« lib/WWW/Hetzner/Robot/CLI/Cmd/Boot.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/List.pm »
| 1 | package WWW::Hetzner::Robot::CLI::Cmd::Boot::Cmd::Rescue; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Rescue system boot configuration | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.102'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Options protect_argv => 0, usage_string => 'USAGE: hrobot.pl boot rescue <server-number> [--enable --os <os> | --disable]'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | option enable => ( | |||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | short => 'e', | ||||||||||||||||||||||||||||
| 14 | doc => 'Activate the rescue system', | ||||||||||||||||||||||||||||
| 15 | default => 0, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | option disable => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | short => 'd', | ||||||||||||||||||||||||||||
| 21 | doc => 'Deactivate the rescue system', | ||||||||||||||||||||||||||||
| 22 | default => 0, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | option os => ( | |||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | format => 's', | ||||||||||||||||||||||||||||
| 28 | doc => 'Rescue system to boot (linux, vkvm) - required with --enable', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | option key => ( | |||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | format => 's@', | ||||||||||||||||||||||||||||
| 34 | doc => 'Authorized SSH key fingerprint (repeatable)', | ||||||||||||||||||||||||||||
| 35 | autosplit => ',', | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | option keyboard => ( | |||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||
| 40 | format => 's', | ||||||||||||||||||||||||||||
| 41 | doc => 'Keyboard layout (default: us)', | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 5 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=11 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 5 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||
| 46 | 5 | my $root = $chain->[0]; | |||||||||||||||||||||||||||
| 47 | 5 | my $robot = $root->robot; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 5 | ▶ | my $server_number = $args->[0] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | or die "Usage: hrobot.pl boot rescue <server-number> [--enable --os <os> | --disable]\n"; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | ▶ | die "--enable and --disable are mutually exclusive\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->enable and $self->disable
MC/DC100%2/2
$self->enable and $self->disable
$self->enable
$self->disable
Truth table100%3/3
A and B
A= $self->enableB= $self->disable
| |||||||||||||||||||||||||||||
| 53 | if $self->enable && $self->disable; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 4 | my $rescue; | |||||||||||||||||||||||||||
| 56 | 4 | ▶ | if ($self->enable) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | die "--os is required with --enable\n" unless $self->os; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | $rescue = $robot->boot->enable_rescue( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 59 | $server_number, | ||||||||||||||||||||||||||||
| 60 | os => $self->os, | ||||||||||||||||||||||||||||
| 61 | ($self->key ? (authorized_key => $self->key) : ()), | ||||||||||||||||||||||||||||
| 62 | ($self->keyboard ? (keyboard => $self->keyboard) : ()), | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | } elsif ($self->disable) { | ||||||||||||||||||||||||||||
| 65 | 1 | $rescue = $robot->boot->disable_rescue($server_number); | |||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||
| 67 | 1 | $rescue = $robot->boot->rescue($server_number); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | if ($root->output eq 'json') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | require JSON::MaybeXS; | |||||||||||||||||||||||||||
| 72 | 0 | print JSON::MaybeXS::encode_json($rescue); | |||||||||||||||||||||||||||
| 73 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 3 | _print_rescue($rescue); | |||||||||||||||||||||||||||
| 76 | 3 | ▶ | print "\nReset the server to boot into the rescue system.\n" if $self->enable; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub _print_rescue { | ||||||||||||||||||||||||||
|
Subroutine
_print_rescue: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 81 | 3 | my ($r) = @_; | |||||||||||||||||||||||||||
| 82 | 3 | my $os = $r->{os}; | |||||||||||||||||||||||||||
| 83 | 3 | ▶ | $os = join(', ', @$os) if ref $os eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | print "Server Number: ", $r->{server_number} // '', "\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"server_number"} // ""
MC/DC0%0/1
$r->{"server_number"} // ""
$r->{"server_number"}
Truth table50%1/2
A
A= $r->{"server_number"}
| |||||||||||||||||||||||||||||
| 85 | 3 | ▶ | print "Server IP: ", $r->{server_ip} // '', "\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"server_ip"} // ""
MC/DC0%0/1
$r->{"server_ip"} // ""
$r->{"server_ip"}
Truth table50%1/2
A
A= $r->{"server_ip"}
| |||||||||||||||||||||||||||||
| 86 | 3 | ▶ | print "Active: ", $r->{active} ? 'yes' : 'no', "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | print "OS: ", $os // '', "\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$os // ""
MC/DC0%0/1
$os // ""
$os
Truth table50%1/2
A
A= $os
| |||||||||||||||||||||||||||||
| 88 | 3 | ▶ | print "Password: ", $r->{password}, "\n" if defined $r->{password}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | 1. | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||