| 1 | package WWW::Hetzner::Cloud::API::Servers; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Servers API | ||||||||||||||||||||||||||||||||||||||||||
| 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 WWW::Hetzner::Cloud::Server; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 25 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 25 | has client => ( | |||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | sub _wrap { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | my ($self, $data) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | return WWW::Hetzner::Cloud::Server->new( | |||||||||||||||||||||||||||||||||||||||||
| 21 | client => $self->client, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | %$data, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | sub _wrap_list { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | my ($self, $list) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | sub list { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | my $result = $self->client->get('/servers', params => \%params); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | return $self->_wrap_list($result->{servers} // []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result->{"servers"} // []
MC/DC0%0/1
$result->{"servers"} // []
$result->{"servers"}
Truth table50%1/2
A
A= $result->{"servers"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub list_by_label { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | my ($self, $label_selector) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_by_label: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | return $self->list(label_selector => $label_selector); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | sub get { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | my $result = $self->client->get("/servers/$id"); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | return $self->_wrap($result->{server}); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | sub create { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=23 SCAR=42.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | croak "name required" unless $params{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | croak "server_type required" unless $params{server_type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | croak "image required" unless $params{image}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | my $body = { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | name => $params{name}, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | server_type => $params{server_type}, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | image => $params{image}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Location/Datacenter (mutually exclusive) | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | $body->{location} = $params{location} if $params{location}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | $body->{datacenter} = $params{datacenter} if $params{datacenter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # SSH Keys (array of names or IDs) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | $body->{ssh_keys} = $params{ssh_keys} if $params{ssh_keys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Labels (hash) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # Cloud-init user data | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | $body->{user_data} = $params{user_data} if $params{user_data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Start server after create (default: true) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | $body->{start_after_create} = $params{start_after_create} // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params{"start_after_create"} // 1
MC/DC0%0/1
$params{"start_after_create"} // 1
$params{"start_after_create"}
Truth table50%1/2
A
A= $params{"start_after_create"}
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | # Placement group (ID or name) | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | $body->{placement_group} = $params{placement_group} if $params{placement_group}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Networks (array of network IDs) | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | $body->{networks} = $params{networks} if $params{networks}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # Volumes (array of volume IDs) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | $body->{volumes} = $params{volumes} if $params{volumes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Automount volumes | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | $body->{automount} = $params{automount} if exists $params{automount}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # Firewalls (array of firewall IDs) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | if ($params{firewalls}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | $body->{firewalls} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | map { { firewall => $_ } } @{$params{firewalls}} | |||||||||||||||||||||||||||||||||||||||||
| 100 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # Public network configuration | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | if ($params{public_net} || exists $params{enable_ipv4} || exists $params{enable_ipv6}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$params{"public_net"} or exists $params{"enable_ipv4"} or exists $params{"enable_ipv6"}
$params{"public_net"} or exists $params{"enable_ipv4"}
MC/DC0%0/3
$params{"public_net"} or exists $params{"enable_ipv4"} or exists $params{"enable_ipv6"}
$params{"public_net"}
exists $params{"enable_ipv4"}
exists $params{"enable_ipv6"}
Truth table25%1/4
A or B or C
A= $params{"public_net"}B= exists $params{"enable_ipv4"}C= exists $params{"enable_ipv6"}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $body->{public_net} = $params{public_net} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params{"public_net"} // {}
MC/DC0%0/1
$params{"public_net"} // {}
$params{"public_net"}
Truth table0%0/2
A
A= $params{"public_net"}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $body->{public_net}{enable_ipv4} = $params{enable_ipv4} if exists $params{enable_ipv4}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | $body->{public_net}{enable_ipv6} = $params{enable_ipv6} if exists $params{enable_ipv6}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $body->{public_net}{ipv4} = $params{ipv4} if $params{ipv4}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $body->{public_net}{ipv6} = $params{ipv6} if $params{ipv6}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | my $result = $self->client->post('/servers', $body); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | return $self->_wrap($result->{server}); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | sub delete { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | return $self->client->delete("/servers/$id"); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | sub power_on { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
power_on: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return $self->client->post("/servers/$id/actions/poweron", {}); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub power_off { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
power_off: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | return $self->client->post("/servers/$id/actions/poweroff", {}); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | sub reboot { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reboot: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return $self->client->post("/servers/$id/actions/reboot", {}); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub shutdown { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | return $self->client->post("/servers/$id/actions/shutdown", {}); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub rebuild { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | my ($self, $id, $image) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rebuild: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | croak "Image required" unless $image; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | return $self->client->post("/servers/$id/actions/rebuild", { image => $image }); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | sub change_type { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | my ($self, $id, $server_type, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
change_type: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | croak "Server type required" unless $server_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | return $self->client->post("/servers/$id/actions/change_type", { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | server_type => $server_type, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | upgrade_disk => $opts{upgrade_disk} // 1, | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"upgrade_disk"} // 1
MC/DC0%0/1
$opts{"upgrade_disk"} // 1
$opts{"upgrade_disk"}
Truth table50%1/2
A
A= $opts{"upgrade_disk"}
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return $self->client->post("/servers/$id/actions/reset", {}); | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | sub enable_rescue { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($self, $id, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_rescue: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $body = { type => $opts{type} // 'linux64' }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"type"} // "linux64"
MC/DC0%0/1
$opts{"type"} // "linux64"
$opts{"type"}
Truth table0%0/2
A
A= $opts{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | $body->{ssh_keys} = $opts{ssh_keys} if $opts{ssh_keys}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return $self->client->post("/servers/$id/actions/enable_rescue", $body); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | sub disable_rescue { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_rescue: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return $self->client->post("/servers/$id/actions/disable_rescue", {}); | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | sub request_console { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_console: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $self->client->post("/servers/$id/actions/request_console", {}); | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub reset_password { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_password: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return $self->client->post("/servers/$id/actions/reset_password", {}); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | sub attach_iso { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my ($self, $id, $iso) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach_iso: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | croak "ISO required" unless $iso; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | return $self->client->post("/servers/$id/actions/attach_iso", { iso => $iso }); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | sub detach_iso { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detach_iso: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $self->client->post("/servers/$id/actions/detach_iso", {}); | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | sub enable_backup { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_backup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return $self->client->post("/servers/$id/actions/enable_backup", {}); | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub disable_backup { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_backup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return $self->client->post("/servers/$id/actions/disable_backup", {}); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | sub update { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | my ($self, $id, %params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | croak "Server ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | my $body = {}; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | my $result = $self->client->put("/servers/$id", $body); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | return $self->_wrap($result->{server}); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | sub wait_for_status { | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | my ($self, $id, $status, $timeout) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait_for_status: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | ▶ | $timeout //= 120; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$timeout //= 120
MC/DC0%0/1
$timeout //= 120
$timeout
Truth table50%1/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | while (time - $start < $timeout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | my $server = $self->get($id); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | return $server if $server->status eq $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | sleep 2; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | croak "Timeout waiting for server $id to reach status '$status'"; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 25 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | __END__ | ||||||||||||||||||||||||||||||||||||||||||