lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/Rescue.pm

filter: Statementstmt 89.4% 34 / 38 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 80.3% 45 / 56 CC 7 SCAR 17.5
CC
7
Cov
80%
execute
8.5
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« lib/WWW/Hetzner/CLI/Cmd/Record/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/Firewall.pm »
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
BranchTrueFalseTotal
my $id = $args->[0] or die "Usage: hcloud.pl server rescue <id> [--disable]\n" 2 0 2
35  
36 2 my $main = $chain->[0];
37 2 my $cloud = $main->cloud;
38  
39 2 ▶ if ($self->disable) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->disable) { } 0 2 2
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
BranchTrueFalseTotal
$self->no_wait ? : 0 0 0
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
BranchTrueFalseTotal
if ($main->output eq 'json') { } 1 1 2
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
BranchTrueFalseTotal
$self->no_wait ? : 1 0 1
56 1 ▶ if (defined $action->root_password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $action->root_password) 1 0 1
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__
« lib/WWW/Hetzner/CLI/Cmd/Record/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/Firewall.pm »