| 1 | package WWW::Hetzner::CLI::Cmd::Server::Cmd::Rescue; | ||||||||||
| 2 | # ABSTRACT: Enable or disable rescue mode | ||||||||||
| 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: hcloud.pl server rescue <id> [--disable] [--type linux64|linux32]'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | with 'WWW::Hetzner::CLI::Role::WaitsForAction'; | |||||||||
| 11 | |||||||||||
| 12 | 1 | option disable => ( | |||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | doc => 'Disable rescue mode instead of enabling', | ||||||||||
| 15 | default => 0, | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 1 | option type => ( | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | format => 's', | ||||||||||
| 21 | doc => 'Rescue system type: linux64, linux32 (default: linux64)', | ||||||||||
| 22 | default => 'linux64', | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 1 | option ssh_key => ( | |||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | format => 's@', | ||||||||||
| 28 | doc => 'SSH key name or ID (repeatable)', | ||||||||||
| 29 | autosplit => ',', | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 2 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=7 SCAR=21.4
Pod
undocumented
| |||||||||||
| 33 | 2 | my ($self, $args, $chain) = @_; | |||||||||
| 34 | 2 | ▶ | my $id = $args->[0] or die "Usage: hcloud.pl server rescue <id> [--disable]\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 2 | my $main = $chain->[0]; | |||||||||
| 37 | 2 | my $cloud = $main->cloud; | |||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | if ($self->disable) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | print "Disabling rescue mode for server $id...\n"; | |||||||||
| 41 | 0 | my $action = $cloud->servers->disable_rescue($id); | |||||||||
| 42 | 0 | $self->handle_action($action); | |||||||||
| 43 | 0 | ▶ | print $self->no_wait ? "Rescue-mode-disable requested.\n" : "Rescue mode disabled.\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } else { | ||||||||||
| 45 | 2 | print "Enabling rescue mode for server $id...\n"; | |||||||||
| 46 | 2 | my $action = $cloud->servers->enable_rescue($id, | |||||||||
| 47 | type => $self->type, | ||||||||||
| 48 | ssh_keys => $self->ssh_key, | ||||||||||
| 49 | ); | ||||||||||
| 50 | 2 | $self->handle_action($action); | |||||||||
| 51 | |||||||||||
| 52 | 2 | ▶ | if ($main->output eq 'json') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | print encode_json({ %{ $action->data }, %{ $action->result } }), "\n"; | |||||||||
| 54 | } else { | ||||||||||
| 55 | 1 | ▶ | print $self->no_wait ? "Rescue-mode-enable requested.\n" : "Rescue mode enabled.\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | ▶ | if (defined $action->root_password) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | print "Root password: ", $action->root_password, "\n"; | |||||||||
| 58 | } | ||||||||||
| 59 | 1 | print "Reboot the server to enter rescue mode.\n"; | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||