| 1 | package WWW::Hetzner::Cloud::API::PrimaryIPs; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Primary 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::PrimaryIP; | ||||||||||
|
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 | 42 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 42 | my ($self, $data, %extra) = @_; | |||||||||||
| 23 | 42 | return WWW::Hetzner::Cloud::PrimaryIP->new( | |||||||||||
| 24 | client => $self->client, | ||||||||||||
| 25 | %$data, | ||||||||||||
| 26 | %extra, | ||||||||||||
| 27 | ); | ||||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 17 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 17 | my ($self, $list) = @_; | |||||||||||
| 32 | 17 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 17 | ▶ | sub _list_page { | ||||||||||
|
Subroutine
_list_page: called CC=2 SCAR=7.1
| |||||||||||||
| 37 | 17 | my ($self, %params) = @_; | |||||||||||
| 38 | |||||||||||||
| 39 | 17 | my $result = $self->client->get('/primary_ips', params => \%params); | |||||||||||
| 40 | 17 | ▶ | return ($self->_wrap_list($result->{primary_ips} // []), $result->{meta}); | ||||||||||
|
Condition50%1/2
$result->{"primary_ips"} // []
MC/DC0%0/1
$result->{"primary_ips"} // []
$result->{"primary_ips"}
Truth table50%1/2
A
A= $result->{"primary_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 "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 55 | |||||||||||||
| 56 | 3 | my $result = $self->client->get("/primary_ips/$id"); | |||||||||||
| 57 | 3 | return $self->_wrap($result->{primary_ip}); | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 6 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||
| 62 | 6 | my ($self, %params) = @_; | |||||||||||
| 63 | |||||||||||||
| 64 | 6 | ▶ | croak "name required" unless $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 5 | ▶ | croak "type required (ipv4 or ipv6)" unless $params{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 4 | ▶ | croak "assignee_type required" unless $params{assignee_type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 3 | ▶ | croak "datacenter required" unless $params{datacenter}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | my $body = { | ||||||||||||
| 70 | name => $params{name}, | ||||||||||||
| 71 | type => $params{type}, | ||||||||||||
| 72 | assignee_type => $params{assignee_type}, | ||||||||||||
| 73 | datacenter => $params{datacenter}, | ||||||||||||
| 74 | 2 | }; | |||||||||||
| 75 | |||||||||||||
| 76 | 2 | ▶ | $body->{assignee_id} = $params{assignee_id} if $params{assignee_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 2 | ▶ | $body->{auto_delete} = $params{auto_delete} if exists $params{auto_delete}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 2 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | 2 | my $result = $self->client->post('/primary_ips', $body); | |||||||||||
| 81 | return $self->_wrap( | ||||||||||||
| 82 | $result->{primary_ip}, | ||||||||||||
| 83 | action => $self->_wrap_action($result->{action}), | ||||||||||||
| 84 | 2 | next_actions => $self->_wrap_actions($result->{next_actions}), | |||||||||||
| 85 | ); | ||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 90 | 0 | my ($self, $id, %params) = @_; | |||||||||||
| 91 | 0 | ▶ | croak "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | |||||||||||||
| 93 | 0 | my $body = {}; | |||||||||||
| 94 | 0 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | ▶ | $body->{auto_delete} = $params{auto_delete} if exists $params{auto_delete}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 0 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 97 | |||||||||||||
| 98 | 0 | my $result = $self->client->put("/primary_ips/$id", $body); | |||||||||||
| 99 | 0 | return $self->_wrap($result->{primary_ip}); | |||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | |||||||||||||
| 103 | 2 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 104 | 2 | my ($self, $id) = @_; | |||||||||||
| 105 | 2 | ▶ | croak "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | |||||||||||||
| 107 | 2 | return $self->client->delete("/primary_ips/$id"); | |||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | |||||||||||||
| 111 | 3 | ▶ | sub assign { | ||||||||||
|
Subroutine
assign: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 112 | 3 | my ($self, $id, $assignee_id, $assignee_type) = @_; | |||||||||||
| 113 | 3 | ▶ | croak "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 3 | ▶ | croak "Assignee ID required" unless $assignee_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 115 | 3 | ▶ | $assignee_type //= 'server'; | ||||||||||
|
Condition50%1/2
$assignee_type //= "server"
MC/DC0%0/1
$assignee_type //= "server"
$assignee_type
Truth table50%1/2
A
A= $assignee_type
| |||||||||||||
| 116 | |||||||||||||
| 117 | return $self->_wrap_action( | ||||||||||||
| 118 | $self->client->post("/primary_ips/$id/actions/assign", { | ||||||||||||
| 119 | assignee_id => $assignee_id, | ||||||||||||
| 120 | assignee_type => $assignee_type, | ||||||||||||
| 121 | })->{action} | ||||||||||||
| 122 | 3 | ); | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | |||||||||||||
| 126 | 3 | ▶ | sub unassign { | ||||||||||
|
Subroutine
unassign: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 127 | 3 | my ($self, $id) = @_; | |||||||||||
| 128 | 3 | ▶ | croak "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 129 | |||||||||||||
| 130 | return $self->_wrap_action( | ||||||||||||
| 131 | $self->client->post("/primary_ips/$id/actions/unassign", {})->{action} | ||||||||||||
| 132 | 3 | ); | |||||||||||
| 133 | } | ||||||||||||
| 134 | |||||||||||||
| 135 | |||||||||||||
| 136 | 1 | ▶ | sub change_dns_ptr { | ||||||||||
|
Subroutine
change_dns_ptr: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 137 | 1 | my ($self, $id, $ip, $dns_ptr) = @_; | |||||||||||
| 138 | 1 | ▶ | croak "Primary IP ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 139 | 1 | ▶ | croak "IP required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | 1 | ▶ | croak "dns_ptr required" unless defined $dns_ptr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 141 | |||||||||||||
| 142 | return $self->_wrap_action( | ||||||||||||
| 143 | $self->client->post("/primary_ips/$id/actions/change_dns_ptr", { | ||||||||||||
| 144 | ip => $ip, | ||||||||||||
| 145 | dns_ptr => $dns_ptr, | ||||||||||||
| 146 | })->{action} | ||||||||||||
| 147 | 1 | ); | |||||||||||
| 148 | } | ||||||||||||
| 149 | |||||||||||||
| 150 | |||||||||||||
| 151 | 60 | 1; | |||||||||||
| 152 | |||||||||||||
| 153 | __END__ | ||||||||||||