lib/WWW/Hetzner/Cloud/Server.pm

filter: Statementstmt 38.9% 30 / 77 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 38.4% 10 / 26 Podpod 100% 17 / 17 totaltotal 39.8% 57 / 143 CC 12 SCAR 15.8
CC
12
Cov
30%
rebuild
12.0
refresh
12.0
image
6.0
CRAP 4.8
« lib/WWW/Hetzner/Robot/Server.pm ↑ Summary lib/WWW/Hetzner/Cloud/Certificate.pm »
1 package WWW::Hetzner::Cloud::Server;
2 # ABSTRACT: Hetzner Cloud Server 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 status => ( is => 'rwp' );
25  
26  
27 25 has locked => ( is => 'ro' );
28  
29  
30 25 has created => ( is => 'ro' );
31  
32  
33 1 ▶has labels => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
34  
35  
36 # Nested data stored as-is
37 0 ▶has public_net => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
38 8 ▶has private_net => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
39 1 ▶has server_type_data => ( is => 'ro', init_arg => 'server_type', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
40 2 ▶has datacenter_data => ( is => 'ro', init_arg => 'datacenter', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
41 2 ▶has image_data => ( is => 'ro', init_arg => 'image', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
42  
43 # Convenience accessors
44  
45 1 ▶sub ipv4 { shift->public_net->{ipv4}{ip} }
Subroutine ipv4: called CC=1 SCAR=0.0
Pod documented
46  
47  
48 0 ▶sub ipv6 { shift->public_net->{ipv6}{ip} }
Subroutine ipv6: not called CC=1 SCAR=6.9
Pod documented
49  
50  
51 0 ▶sub server_type { shift->server_type_data->{name} }
Subroutine server_type: not called CC=1 SCAR=6.9
Pod documented
52  
53  
54 0 ▶sub datacenter { shift->datacenter_data->{name} }
Subroutine datacenter: not called CC=1 SCAR=6.9
Pod documented
55  
56  
57 0 ▶sub location { shift->datacenter_data->{location}{name} }
Subroutine location: not called CC=1 SCAR=6.9
Pod documented
58  
59  
60 0 ▶sub image { my $i = shift->image_data; $i ? $i->{name} : undef }
Subroutine image: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 0 0 0
61  
62  
63 3 ▶sub is_running { shift->status eq 'running' }
Subroutine is_running: called CC=1 SCAR=0.0
Pod documented
64  
65  
66 0 ▶sub is_off { shift->status eq 'off' }
Subroutine is_off: not called CC=1 SCAR=6.9
Pod documented
67  
68  
69 # Actions
70  
71 sub update {
72 0 ▶ my ($self) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ croak "Cannot update server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
74  
75 0 my $result = $self->_client->put("/servers/" . $self->id, {
76 name => $self->name,
77 labels => $self->labels,
78 });
79 0 return $self;
80 }
81  
82  
83 sub delete {
84 0 ▶ my ($self) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
85 0 ▶ croak "Cannot delete server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
86  
87 0 $self->_client->delete("/servers/" . $self->id);
88 0 return 1;
89 }
90  
91  
92 sub power_on {
93 0 ▶ my ($self) = @_;
Subroutine power_on: not called CC=2 SCAR=17.9
Pod documented
94 0 ▶ croak "Cannot power on server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
95  
96 0 $self->_client->post("/servers/" . $self->id . "/actions/poweron", {});
97 0 return $self;
98 }
99  
100  
101 sub power_off {
102 0 ▶ my ($self) = @_;
Subroutine power_off: not called CC=2 SCAR=17.9
Pod documented
103 0 ▶ croak "Cannot power off server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
104  
105 0 $self->_client->post("/servers/" . $self->id . "/actions/poweroff", {});
106 0 return $self;
107 }
108  
109  
110 sub reboot {
111 0 ▶ my ($self) = @_;
Subroutine reboot: not called CC=2 SCAR=17.9
Pod documented
112 0 ▶ croak "Cannot reboot server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
113  
114 0 $self->_client->post("/servers/" . $self->id . "/actions/reboot", {});
115 0 return $self;
116 }
117  
118  
119 sub shutdown {
120 0 ▶ my ($self) = @_;
Subroutine shutdown: not called CC=2 SCAR=17.9
Pod documented
121 0 ▶ croak "Cannot shutdown server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
122  
123 0 $self->_client->post("/servers/" . $self->id . "/actions/shutdown", {});
124 0 return $self;
125 }
126  
127  
128 sub rebuild {
129 0 ▶ my ($self, $image) = @_;
Subroutine rebuild: not called CC=3 SCAR=24.8
Pod documented
130 0 ▶ croak "Cannot rebuild server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
131 0 ▶ croak "Image required" unless $image;
Branch: 1 branch
BranchTrueFalseTotal
unless $image 0 0 0
132  
133 0 $self->_client->post("/servers/" . $self->id . "/actions/rebuild", { image => $image });
134 0 return $self;
135 }
136  
137  
138 sub refresh {
139 0 ▶ my ($self) = @_;
Subroutine refresh: not called CC=3 SCAR=24.8
Pod documented
140 0 ▶ croak "Cannot refresh server without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
141  
142 0 my $result = $self->_client->get("/servers/" . $self->id);
143 0 my $data = $result->{server};
144  
145 0 $self->_set_status($data->{status});
146 0 $self->name($data->{name});
147 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
148  
149 0 return $self;
150 }
151  
152  
153 sub data {
154 0 ▶ my ($self) = @_;
Subroutine data: not called CC=1 SCAR=6.9
Pod documented
155 return {
156 0 id => $self->id,
157 name => $self->name,
158 status => $self->status,
159 locked => $self->locked,
160 created => $self->created,
161 labels => $self->labels,
162 public_net => $self->public_net,
163 private_net => $self->private_net,
164 server_type => $self->server_type_data,
165 datacenter => $self->datacenter_data,
166 image => $self->image_data,
167 };
168 }
169  
170  
171  
172 25 1.
173  
174 __END__
« lib/WWW/Hetzner/Robot/Server.pm ↑ Summary lib/WWW/Hetzner/Cloud/Certificate.pm »