| 1 | package WWW::Hetzner::Cloud::FloatingIP; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Floating IP object | ||||||||||||
| 3 | |||||||||||||
| 4 | 25 | our $VERSION = '0.100'; | |||||||||||
| 5 | |||||||||||||
| 6 | 25 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 25 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 25 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 25 | has _client => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | required => 1, | ||||||||||||
| 14 | weak_ref => 1, | ||||||||||||
| 15 | init_arg => 'client', | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | 25 | has id => ( is => 'ro' ); | |||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 25 | has name => ( is => 'rw' ); | |||||||||||
| 22 | |||||||||||||
| 23 | |||||||||||||
| 24 | 25 | has description => ( is => 'rw' ); | |||||||||||
| 25 | |||||||||||||
| 26 | |||||||||||||
| 27 | 25 | has ip => ( is => 'ro' ); | |||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | 25 | has type => ( is => 'ro' ); | |||||||||||
| 31 | |||||||||||||
| 32 | |||||||||||||
| 33 | 25 | has server => ( is => 'ro' ); | |||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | has dns_ptr => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 37 | |||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | has home_location => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 25 | has blocked => ( is => 'ro' ); | |||||||||||
| 43 | |||||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | has labels => ( is => 'rw', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 46 | |||||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | has protection => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 25 | has created => ( is => 'ro' ); | |||||||||||
| 52 | |||||||||||||
| 53 | |||||||||||||
| 54 | # Convenience | ||||||||||||
| 55 | 2 | ▶ | sub is_assigned { defined shift->server } | ||||||||||
|
Subroutine
is_assigned: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 56 | |||||||||||||
| 57 | |||||||||||||
| 58 | 1 | ▶ | sub location { shift->home_location->{name} } | ||||||||||
|
Subroutine
location: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | # Actions | ||||||||||||
| 62 | sub update { | ||||||||||||
| 63 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 64 | 0 | ▶ | croak "Cannot update floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | |||||||||||||
| 66 | 0 | my $result = $self->_client->put("/floating_ips/" . $self->id, { | |||||||||||
| 67 | name => $self->name, | ||||||||||||
| 68 | description => $self->description, | ||||||||||||
| 69 | labels => $self->labels, | ||||||||||||
| 70 | }); | ||||||||||||
| 71 | 0 | return $self; | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | |||||||||||||
| 75 | sub delete { | ||||||||||||
| 76 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 77 | 0 | ▶ | croak "Cannot delete floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | |||||||||||||
| 79 | 0 | $self->_client->delete("/floating_ips/" . $self->id); | |||||||||||
| 80 | 0 | return 1; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | sub assign { | ||||||||||||
| 85 | 0 | ▶ | my ($self, $server_id) = @_; | ||||||||||
|
Subroutine
assign: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 86 | 0 | ▶ | croak "Cannot assign floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 0 | ▶ | croak "Server ID required" unless $server_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | |||||||||||||
| 89 | 0 | $self->_client->post("/floating_ips/" . $self->id . "/actions/assign", { | |||||||||||
| 90 | server => $server_id, | ||||||||||||
| 91 | }); | ||||||||||||
| 92 | 0 | return $self; | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | sub unassign { | ||||||||||||
| 97 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
unassign: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 98 | 0 | ▶ | croak "Cannot unassign floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | |||||||||||||
| 100 | 0 | $self->_client->post("/floating_ips/" . $self->id . "/actions/unassign", {}); | |||||||||||
| 101 | 0 | return $self; | |||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | |||||||||||||
| 105 | sub change_dns_ptr { | ||||||||||||
| 106 | 0 | ▶ | my ($self, $ip, $dns_ptr) = @_; | ||||||||||
|
Subroutine
change_dns_ptr: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 107 | 0 | ▶ | croak "Cannot modify floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 0 | ▶ | croak "IP required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | 0 | ▶ | croak "dns_ptr required" unless defined $dns_ptr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | |||||||||||||
| 111 | 0 | $self->_client->post("/floating_ips/" . $self->id . "/actions/change_dns_ptr", { | |||||||||||
| 112 | ip => $ip, | ||||||||||||
| 113 | dns_ptr => $dns_ptr, | ||||||||||||
| 114 | }); | ||||||||||||
| 115 | 0 | return $self; | |||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | |||||||||||||
| 119 | sub refresh { | ||||||||||||
| 120 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 121 | 0 | ▶ | croak "Cannot refresh floating IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | |||||||||||||
| 123 | 0 | my $result = $self->_client->get("/floating_ips/" . $self->id); | |||||||||||
| 124 | 0 | my $data = $result->{floating_ip}; | |||||||||||
| 125 | |||||||||||||
| 126 | 0 | $self->name($data->{name}); | |||||||||||
| 127 | 0 | $self->description($data->{description}); | |||||||||||
| 128 | 0 | ▶ | $self->labels($data->{labels} // {}); | ||||||||||
|
Condition0%0/2
$data->{"labels"} // {}
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
| |||||||||||||
| 129 | |||||||||||||
| 130 | 0 | return $self; | |||||||||||
| 131 | } | ||||||||||||
| 132 | |||||||||||||
| 133 | |||||||||||||
| 134 | sub data { | ||||||||||||
| 135 | 1 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 136 | return { | ||||||||||||
| 137 | 1 | id => $self->id, | |||||||||||
| 138 | name => $self->name, | ||||||||||||
| 139 | description => $self->description, | ||||||||||||
| 140 | ip => $self->ip, | ||||||||||||
| 141 | type => $self->type, | ||||||||||||
| 142 | server => $self->server, | ||||||||||||
| 143 | dns_ptr => $self->dns_ptr, | ||||||||||||
| 144 | home_location => $self->home_location, | ||||||||||||
| 145 | blocked => $self->blocked, | ||||||||||||
| 146 | labels => $self->labels, | ||||||||||||
| 147 | protection => $self->protection, | ||||||||||||
| 148 | created => $self->created, | ||||||||||||
| 149 | }; | ||||||||||||
| 150 | } | ||||||||||||
| 151 | |||||||||||||
| 152 | |||||||||||||
| 153 | |||||||||||||
| 154 | 25 | 1. | |||||||||||
| 155 | |||||||||||||
| 156 | __END__ | ||||||||||||