| 1 | package WWW::Hetzner::Cloud::API::FloatingIPs; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Floating IPs API | ||||||||||||
| 3 | |||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 60 | with 'WWW::Hetzner::Role::Pagination'; | |||||||||||
| 8 | 60 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 60 | ▶ | use WWW::Hetzner::Cloud::FloatingIP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 60 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 60 | has client => ( | |||||||||||
| 14 | is => 'ro', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | weak_ref => 1, | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 60 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||
| 20 | |||||||||||||
| 21 | 17 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 17 | my ($self, $data, %extra) = @_; | |||||||||||
| 23 | 17 | return WWW::Hetzner::Cloud::FloatingIP->new( | |||||||||||
| 24 | client => $self->client, | ||||||||||||
| 25 | %$data, | ||||||||||||
| 26 | %extra, | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 14 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 14 | my ($self, $list) = @_; | |||||||||||
| 32 | 14 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 14 | ▶ | sub _list_page { | ||||||||||
|
Subroutine
_list_page: called CC=2 SCAR=7.1
| |||||||||||||
| 37 | 14 | my ($self, %params) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 14 | my $result = $self->client->get('/floating_ips', params => \%params); | |||||||||||
| 40 | 14 | ▶ | return ($self->_wrap_list($result->{floating_ips} // []), $result->{meta}); | ||||||||||
|
Condition50%1/2
$result->{"floating_ips"} // []
MC/DC0%0/1
$result->{"floating_ips"} // []
$result->{"floating_ips"}
Truth table50%1/2
A
A= $result->{"floating_ips"}
| |||||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 1 | ▶ | sub list { | ||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 44 | 1 | my ($self, %params) = @_; | |||||||||||
| 45 | |||||||||||||
| 46 | 1 | my ($entities) = $self->_list_page(%params); | |||||||||||
| 47 | 1 | return $entities; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 3 | ▶ | sub get { | ||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 53 | 3 | my ($self, $id) = @_; | |||||||||||
| 54 | 3 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 3 | my $result = $self->client->get("/floating_ips/$id"); | |||||||||||
| 57 | 3 | return $self->_wrap($result->{floating_ip}); | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 4 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||
| 62 | 4 | my ($self, %params) = @_; | |||||||||||
| 63 | |||||||||||||
| 64 | 4 | ▶ | croak "type required (ipv4 or ipv6)" unless $params{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 3 | ▶ | croak "home_location required" unless $params{home_location}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | my $body = { | ||||||||||||
| 68 | type => $params{type}, | ||||||||||||
| 69 | home_location => $params{home_location}, | ||||||||||||
| 70 | 2 | }; | |||||||||||
| 71 | |||||||||||||
| 72 | 2 | ▶ | $body->{name} = $params{name} if $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 2 | ▶ | $body->{description} = $params{description} if $params{description}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 2 | ▶ | $body->{server} = $params{server} if $params{server}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | 2 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | |||||||||||||
| 77 | 2 | my $result = $self->client->post('/floating_ips', $body); | |||||||||||
| 78 | return $self->_wrap( | ||||||||||||
| 79 | $result->{floating_ip}, | ||||||||||||
| 80 | action => $self->_wrap_action($result->{action}), | ||||||||||||
| 81 | 2 | next_actions => $self->_wrap_actions($result->{next_actions}), | |||||||||||
| 82 | ); | ||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 87 | 0 | my ($self, $id, %params) = @_; | |||||||||||
| 88 | 0 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 89 | |||||||||||||
| 90 | 0 | my $body = {}; | |||||||||||
| 91 | 0 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 0 | ▶ | $body->{description} = $params{description} if exists $params{description}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | 0 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | |||||||||||||
| 95 | 0 | my $result = $self->client->put("/floating_ips/$id", $body); | |||||||||||
| 96 | 0 | return $self->_wrap($result->{floating_ip}); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | |||||||||||||
| 100 | 2 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 101 | 2 | my ($self, $id) = @_; | |||||||||||
| 102 | 2 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | |||||||||||||
| 104 | 2 | return $self->client->delete("/floating_ips/$id"); | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | 3 | ▶ | sub assign { | ||||||||||
|
Subroutine
assign: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 109 | 3 | my ($self, $id, $server_id) = @_; | |||||||||||
| 110 | 3 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 3 | ▶ | croak "Server ID required" unless $server_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | |||||||||||||
| 113 | return $self->_wrap_action( | ||||||||||||
| 114 | $self->client->post("/floating_ips/$id/actions/assign", { | ||||||||||||
| 115 | server => $server_id, | ||||||||||||
| 116 | })->{action} | ||||||||||||
| 117 | 3 | ); | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | |||||||||||||
| 121 | 3 | ▶ | sub unassign { | ||||||||||
|
Subroutine
unassign: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 122 | 3 | my ($self, $id) = @_; | |||||||||||
| 123 | 3 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | |||||||||||||
| 125 | return $self->_wrap_action( | ||||||||||||
| 126 | $self->client->post("/floating_ips/$id/actions/unassign", {})->{action} | ||||||||||||
| 127 | 3 | ); | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | |||||||||||||
| 131 | 2 | ▶ | sub change_dns_ptr { | ||||||||||
|
Subroutine
change_dns_ptr: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 132 | 2 | my ($self, $id, $ip, $dns_ptr) = @_; | |||||||||||
| 133 | 2 | ▶ | croak "Floating IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 134 | 2 | ▶ | croak "IP required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | 2 | ▶ | croak "dns_ptr required" unless defined $dns_ptr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 136 | |||||||||||||
| 137 | return $self->_wrap_action( | ||||||||||||
| 138 | $self->client->post("/floating_ips/$id/actions/change_dns_ptr", { | ||||||||||||
| 139 | ip => $ip, | ||||||||||||
| 140 | dns_ptr => $dns_ptr, | ||||||||||||
| 141 | })->{action} | ||||||||||||
| 142 | 2 | ); | |||||||||||
| 143 | } | ||||||||||||
| 144 | |||||||||||||
| 145 | |||||||||||||
| 146 | 60 | 1; | |||||||||||
| 147 | |||||||||||||
| 148 | __END__ | ||||||||||||