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