lib/WWW/Hetzner/Cloud/LoadBalancer.pm

filter: Statementstmt 32.9% 30 / 91 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 23.0% 6 / 26 Podpod 100% 14 / 14 totaltotal 29.4% 50 / 170 CC 20 SCAR 23.1
CC
20
Cov
23%
add_service
30.0
attach_to_network
20.0
add_target
12.0
CRAP 10.1
« lib/WWW/Hetzner/Cloud/Volume.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Sshkey/Cmd/Create.pm »
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
BranchTrueFalseTotal
unless $self->id 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
101 0 ▶ croak "type required" unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
111 0 ▶ croak "type required" unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
121 0 ▶ croak "protocol required" unless $opts{protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"protocol"} 0 0 0
122 0 ▶ croak "listen_port required" unless $opts{listen_port};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"listen_port"} 0 0 0
123 0 ▶ croak "destination_port required" unless $opts{destination_port};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"destination_port"} 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
133 0 ▶ croak "listen_port required" unless $listen_port;
Branch: 1 branch
BranchTrueFalseTotal
unless $listen_port 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
145 0 ▶ croak "network required" unless $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $network_id 0 0 0
146  
147 0 my $body = { network => $network_id };
148 0 ▶ $body->{ip} = $opts{ip} if $opts{ip};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"ip"} 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
158 0 ▶ croak "network required" unless $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $network_id 0 0 0
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
BranchTrueFalseTotal
unless $self->id 0 0 0
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"} // {}
l!l
00
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
Aresult
11
00
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__
« lib/WWW/Hetzner/Cloud/Volume.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Sshkey/Cmd/Create.pm »