| 1 | package WWW::Hetzner::Cloud::LoadBalancer; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Load Balancer 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 | 0 | ▶ | has public_net => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 25 | |||||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | has private_net => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | has location => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 31 | |||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | has load_balancer_type => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 34 | |||||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | has protection => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 37 | |||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | has labels => ( is => 'rw', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 40 | |||||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | has targets => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 43 | |||||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | has services => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 46 | |||||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | has algorithm => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 49 | |||||||||||||
| 50 | |||||||||||||
| 51 | 25 | has created => ( is => 'ro' ); | |||||||||||
| 52 | |||||||||||||
| 53 | |||||||||||||
| 54 | 25 | has outgoing_traffic => ( is => 'ro' ); | |||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | 25 | has ingoing_traffic => ( is => 'ro' ); | |||||||||||
| 58 | |||||||||||||
| 59 | |||||||||||||
| 60 | 25 | has included_traffic => ( is => 'ro' ); | |||||||||||
| 61 | |||||||||||||
| 62 | |||||||||||||
| 63 | # Convenience | ||||||||||||
| 64 | 1 | ▶ | sub location_name { shift->location->{name} } | ||||||||||
|
Subroutine
location_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | 1 | ▶ | sub type_name { shift->load_balancer_type->{name} } | ||||||||||
|
Subroutine
type_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | 1 | ▶ | sub ipv4 { shift->public_net->{ipv4}{ip} } | ||||||||||
|
Subroutine
ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 71 | |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub ipv6 { shift->public_net->{ipv6}{ip} } | ||||||||||
|
Subroutine
ipv6: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 74 | |||||||||||||
| 75 | |||||||||||||
| 76 | # Actions | ||||||||||||
| 77 | sub update { | ||||||||||||
| 78 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 79 | 0 | ▶ | croak "Cannot update load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | 0 | my $result = $self->_client->put("/load_balancers/" . $self->id, { | |||||||||||
| 82 | name => $self->name, | ||||||||||||
| 83 | labels => $self->labels, | ||||||||||||
| 84 | }); | ||||||||||||
| 85 | 0 | return $self; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | sub delete { | ||||||||||||
| 90 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 91 | 0 | ▶ | croak "Cannot delete load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | |||||||||||||
| 93 | 0 | $self->_client->delete("/load_balancers/" . $self->id); | |||||||||||
| 94 | 0 | return 1; | |||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | |||||||||||||
| 98 | sub add_target { | ||||||||||||
| 99 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
add_target: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 100 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 0 | ▶ | croak "type required" unless $opts{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 102 | |||||||||||||
| 103 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/add_target", \%opts); | |||||||||||
| 104 | 0 | return $self; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | sub remove_target { | ||||||||||||
| 109 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
remove_target: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 110 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | ▶ | croak "type required" unless $opts{type}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | |||||||||||||
| 113 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/remove_target", \%opts); | |||||||||||
| 114 | 0 | return $self; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | |||||||||||||
| 118 | sub add_service { | ||||||||||||
| 119 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||
|
Subroutine
add_service: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 120 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 121 | 0 | ▶ | croak "protocol required" unless $opts{protocol}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | 0 | ▶ | croak "listen_port required" unless $opts{listen_port}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 123 | 0 | ▶ | croak "destination_port required" unless $opts{destination_port}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | |||||||||||||
| 125 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/add_service", \%opts); | |||||||||||
| 126 | 0 | return $self; | |||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | |||||||||||||
| 130 | sub delete_service { | ||||||||||||
| 131 | 0 | ▶ | my ($self, $listen_port) = @_; | ||||||||||
|
Subroutine
delete_service: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 132 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 133 | 0 | ▶ | croak "listen_port required" unless $listen_port; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 134 | |||||||||||||
| 135 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/delete_service", { | |||||||||||
| 136 | listen_port => $listen_port, | ||||||||||||
| 137 | }); | ||||||||||||
| 138 | 0 | return $self; | |||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | |||||||||||||
| 142 | sub attach_to_network { | ||||||||||||
| 143 | 0 | ▶ | my ($self, $network_id, %opts) = @_; | ||||||||||
|
Subroutine
attach_to_network: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 144 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 145 | 0 | ▶ | croak "network required" unless $network_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 146 | |||||||||||||
| 147 | 0 | my $body = { network => $network_id }; | |||||||||||
| 148 | 0 | ▶ | $body->{ip} = $opts{ip} if $opts{ip}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 149 | |||||||||||||
| 150 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/attach_to_network", $body); | |||||||||||
| 151 | 0 | return $self; | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | |||||||||||||
| 155 | sub detach_from_network { | ||||||||||||
| 156 | 0 | ▶ | my ($self, $network_id) = @_; | ||||||||||
|
Subroutine
detach_from_network: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 157 | 0 | ▶ | croak "Cannot modify load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 158 | 0 | ▶ | croak "network required" unless $network_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 159 | |||||||||||||
| 160 | 0 | $self->_client->post("/load_balancers/" . $self->id . "/actions/detach_from_network", { | |||||||||||
| 161 | network => $network_id, | ||||||||||||
| 162 | }); | ||||||||||||
| 163 | 0 | return $self; | |||||||||||
| 164 | } | ||||||||||||
| 165 | |||||||||||||
| 166 | |||||||||||||
| 167 | sub refresh { | ||||||||||||
| 168 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 169 | 0 | ▶ | croak "Cannot refresh load balancer without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 170 | |||||||||||||
| 171 | 0 | my $result = $self->_client->get("/load_balancers/" . $self->id); | |||||||||||
| 172 | 0 | my $data = $result->{load_balancer}; | |||||||||||
| 173 | |||||||||||||
| 174 | 0 | $self->name($data->{name}); | |||||||||||
| 175 | 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"}
| |||||||||||||
| 176 | |||||||||||||
| 177 | 0 | return $self; | |||||||||||
| 178 | } | ||||||||||||
| 179 | |||||||||||||
| 180 | |||||||||||||
| 181 | sub data { | ||||||||||||
| 182 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 183 | return { | ||||||||||||
| 184 | 0 | id => $self->id, | |||||||||||
| 185 | name => $self->name, | ||||||||||||
| 186 | public_net => $self->public_net, | ||||||||||||
| 187 | private_net => $self->private_net, | ||||||||||||
| 188 | location => $self->location, | ||||||||||||
| 189 | load_balancer_type => $self->load_balancer_type, | ||||||||||||
| 190 | protection => $self->protection, | ||||||||||||
| 191 | labels => $self->labels, | ||||||||||||
| 192 | targets => $self->targets, | ||||||||||||
| 193 | services => $self->services, | ||||||||||||
| 194 | algorithm => $self->algorithm, | ||||||||||||
| 195 | created => $self->created, | ||||||||||||
| 196 | }; | ||||||||||||
| 197 | } | ||||||||||||
| 198 | |||||||||||||
| 199 | |||||||||||||
| 200 | |||||||||||||
| 201 | 25 | 1. | |||||||||||
| 202 | |||||||||||||
| 203 | __END__ | ||||||||||||