| 1 | package WWW::Hetzner::Cloud::Server; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Server object | ||||||||||||
| 3 | |||||||||||||
| 4 | 56 | our $VERSION = '0.101'; | |||||||||||
| 5 | |||||||||||||
| 6 | 56 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 56 | with 'WWW::Hetzner::Role::HasAction'; | |||||||||||
| 8 | 56 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 56 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | 56 | has _client => ( | |||||||||||
| 13 | is => 'ro', | ||||||||||||
| 14 | required => 1, | ||||||||||||
| 15 | weak_ref => 1, | ||||||||||||
| 16 | init_arg => 'client', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 56 | has id => ( is => 'ro' ); | |||||||||||
| 20 | |||||||||||||
| 21 | |||||||||||||
| 22 | 56 | has name => ( is => 'rw' ); | |||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | 56 | has status => ( is => 'rwp' ); | |||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | 56 | has locked => ( is => 'ro' ); | |||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | 56 | has created => ( is => 'ro' ); | |||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 1 | ▶ | has labels => ( is => 'rw', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | # Nested data stored as-is | ||||||||||||
| 38 | 0 | ▶ | has public_net => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 39 | 21 | ▶ | has private_net => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 40 | 1 | ▶ | has server_type_data => ( is => 'ro', init_arg => 'server_type', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 41 | 2 | ▶ | has datacenter_data => ( is => 'ro', init_arg => 'datacenter', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 42 | 2 | ▶ | has image_data => ( is => 'ro', init_arg => 'image', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | |||||||||||||
| 44 | # Convenience accessors | ||||||||||||
| 45 | |||||||||||||
| 46 | 5 | ▶ | sub ipv4 { shift->public_net->{ipv4}{ip} } | ||||||||||
|
Subroutine
ipv4: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | 2 | ▶ | sub ipv6 { shift->public_net->{ipv6}{ip} } | ||||||||||
|
Subroutine
ipv6: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 3 | ▶ | sub server_type { shift->server_type_data->{name} } | ||||||||||
|
Subroutine
server_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 53 | |||||||||||||
| 54 | |||||||||||||
| 55 | 4 | ▶ | sub datacenter { shift->datacenter_data->{name} } | ||||||||||
|
Subroutine
datacenter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 56 | |||||||||||||
| 57 | |||||||||||||
| 58 | 0 | ▶ | sub location { shift->datacenter_data->{location}{name} } | ||||||||||
|
Subroutine
location: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 59 | |||||||||||||
| 60 | |||||||||||||
| 61 | 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
| |||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | 3 | ▶ | sub is_running { shift->status eq 'running' } | ||||||||||
|
Subroutine
is_running: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | sub is_off { shift->status eq 'off' } | ||||||||||
|
Subroutine
is_off: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 68 | |||||||||||||
| 69 | |||||||||||||
| 70 | # Actions | ||||||||||||
| 71 | |||||||||||||
| 72 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 73 | 0 | my ($self) = @_; | |||||||||||
| 74 | 0 | ▶ | croak "Cannot update server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | |||||||||||||
| 76 | 0 | my $result = $self->_client->put("/servers/" . $self->id, { | |||||||||||
| 77 | name => $self->name, | ||||||||||||
| 78 | labels => $self->labels, | ||||||||||||
| 79 | }); | ||||||||||||
| 80 | 0 | return $self; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | |||||||||||||
| 84 | 1 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 85 | 1 | my ($self) = @_; | |||||||||||
| 86 | 1 | ▶ | croak "Cannot delete server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | |||||||||||||
| 88 | 1 | return $self->_client->servers->delete($self->id); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | 1 | ▶ | sub power_on { | ||||||||||
|
Subroutine
power_on: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 93 | 1 | my ($self) = @_; | |||||||||||
| 94 | 1 | ▶ | croak "Cannot power on server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | |||||||||||||
| 96 | 1 | return $self->_client->servers->power_on($self->id); | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | |||||||||||||
| 100 | 1 | ▶ | sub power_off { | ||||||||||
|
Subroutine
power_off: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 101 | 1 | my ($self) = @_; | |||||||||||
| 102 | 1 | ▶ | croak "Cannot power off server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | |||||||||||||
| 104 | 1 | return $self->_client->servers->power_off($self->id); | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | |||||||||||||
| 108 | 1 | ▶ | sub reboot { | ||||||||||
|
Subroutine
reboot: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 109 | 1 | my ($self) = @_; | |||||||||||
| 110 | 1 | ▶ | croak "Cannot reboot server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | |||||||||||||
| 112 | 1 | return $self->_client->servers->reboot($self->id); | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | |||||||||||||
| 116 | 1 | ▶ | sub shutdown { | ||||||||||
|
Subroutine
shutdown: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 117 | 1 | my ($self) = @_; | |||||||||||
| 118 | 1 | ▶ | croak "Cannot shutdown server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 119 | |||||||||||||
| 120 | 1 | return $self->_client->servers->shutdown($self->id); | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | |||||||||||||
| 124 | 1 | ▶ | sub rebuild { | ||||||||||
|
Subroutine
rebuild: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 125 | 1 | my ($self, $image) = @_; | |||||||||||
| 126 | 1 | ▶ | croak "Cannot rebuild server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | 1 | ▶ | croak "Image required" unless $image; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 128 | |||||||||||||
| 129 | 1 | return $self->_client->servers->rebuild($self->id, $image); | |||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | |||||||||||||
| 133 | 0 | ▶ | sub refresh { | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 134 | 0 | my ($self) = @_; | |||||||||||
| 135 | 0 | ▶ | croak "Cannot refresh server without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 136 | |||||||||||||
| 137 | 0 | my $result = $self->_client->get("/servers/" . $self->id); | |||||||||||
| 138 | 0 | my $data = $result->{server}; | |||||||||||
| 139 | |||||||||||||
| 140 | 0 | $self->_set_status($data->{status}); | |||||||||||
| 141 | 0 | $self->name($data->{name}); | |||||||||||
| 142 | 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"}
| |||||||||||||
| 143 | |||||||||||||
| 144 | 0 | return $self; | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | |||||||||||||
| 148 | 1 | ▶ | sub data { | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 149 | 1 | my ($self) = @_; | |||||||||||
| 150 | return { | ||||||||||||
| 151 | 1 | id => $self->id, | |||||||||||
| 152 | name => $self->name, | ||||||||||||
| 153 | status => $self->status, | ||||||||||||
| 154 | locked => $self->locked, | ||||||||||||
| 155 | created => $self->created, | ||||||||||||
| 156 | labels => $self->labels, | ||||||||||||
| 157 | public_net => $self->public_net, | ||||||||||||
| 158 | private_net => $self->private_net, | ||||||||||||
| 159 | server_type => $self->server_type_data, | ||||||||||||
| 160 | datacenter => $self->datacenter_data, | ||||||||||||
| 161 | image => $self->image_data, | ||||||||||||
| 162 | }; | ||||||||||||
| 163 | } | ||||||||||||
| 164 | |||||||||||||
| 165 | |||||||||||||
| 166 | |||||||||||||
| 167 | 56 | 1. | |||||||||||
| 168 | |||||||||||||
| 169 | __END__ | ||||||||||||