« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/UpdateAccessSettings.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/Network/Cmd/List.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::Server; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Server commands | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.102'; | |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooX::Options usage_string => 'USAGE: hcloud.pl server <command> [options]'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 13 | 2 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | # Default to list | ||||||||||||||||||||||||||||||||
| 16 | 2 | $self->_list($chain); | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 2 | option selector => ( | |||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 21 | format => 's', | ||||||||||||||||||||||||||||||||
| 22 | short => 'l', | ||||||||||||||||||||||||||||||||
| 23 | doc => 'Label selector (e.g., env=prod)', | ||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 2 | option name => ( | |||||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 28 | format => 's', | ||||||||||||||||||||||||||||||||
| 29 | short => 'n', | ||||||||||||||||||||||||||||||||
| 30 | doc => 'Filter by name', | ||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | sub _list { | ||||||||||||||||||||||||||||||
|
Subroutine
_list: called CC=9 SCAR=23.3
| |||||||||||||||||||||||||||||||||
| 34 | 2 | my ($self, $chain) = @_; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 2 | my $main = $chain->[0]; | |||||||||||||||||||||||||||||||
| 37 | 2 | my $cloud = $main->cloud; | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 2 | my %params; | |||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | $params{label_selector} = $self->selector if $self->selector; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | $params{name} = $self->name if $self->name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 2 | my $servers = $cloud->servers->list_all(%params); | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | if ($main->output eq 'json') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 1 | print encode_json([ map { $_->data } @$servers ]), "\n"; | |||||||||||||||||||||||||||||||
| 47 | 1 | return; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | # Table output | ||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | if (!@$servers) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 0 | print "No servers found.\n"; | |||||||||||||||||||||||||||||||
| 53 | 0 | return; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 1 | printf "%-10s %-25s %-12s %-16s %-10s %s\n", | |||||||||||||||||||||||||||||||
| 57 | 'ID', 'NAME', 'STATUS', 'IPV4', 'TYPE', 'LOCATION'; | ||||||||||||||||||||||||||||||||
| 58 | 1 | print "-" x 90, "\n"; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 1 | for my $s (@$servers) { | |||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | printf "%-10s %-25s %-12s %-16s %-10s %s\n", | ||||||||||||||||||||||||||||||
|
Condition50%3/6
$s->ipv4 // "-"
$s->server_type // "-"
$s->location // "-"
MC/DC0%0/1
$s->ipv4 // "-"
$s->ipv4
MC/DC0%0/1
$s->server_type // "-"
$s->server_type
MC/DC0%0/1
$s->location // "-"
$s->location
Truth table50%1/2
A
A= $s->ipv4
Truth table50%1/2
A
A= $s->server_type
Truth table50%1/2
A
A= $s->location
| |||||||||||||||||||||||||||||||||
| 62 | $s->id, | ||||||||||||||||||||||||||||||||
| 63 | $s->name, | ||||||||||||||||||||||||||||||||
| 64 | $s->status, | ||||||||||||||||||||||||||||||||
| 65 | $s->ipv4 // '-', | ||||||||||||||||||||||||||||||||
| 66 | $s->server_type // '-', | ||||||||||||||||||||||||||||||||
| 67 | $s->location // '-'; | ||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 2 | 1. | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||