« lib/WWW/Hetzner/Robot/CLI/Cmd/Traffic.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/Network/Cmd/Describe.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::LoadBalancer::Cmd::Describe; | ||
| 2 | # ABSTRACT: Describe a load balancer | ||
| 3 | |||
| 4 | our $VERSION = '0.100'; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use MooX::Cmd; | ||
| 8 | use MooX::Options protect_argv => 0, usage_string => 'USAGE: hcloud.pl load-balancer describe <id>'; | ||
| 9 | use JSON::MaybeXS qw(encode_json); | ||
| 10 | |||
| 11 | sub execute { | ||
| 12 | my ($self, $args, $chain) = @_; | ||
| 13 | my $id = $args->[0] or die "Usage: hcloud.pl load-balancer describe <id>\n"; | ||
| 14 | |||
| 15 | my $main = $chain->[0]; | ||
| 16 | my $cloud = $main->cloud; | ||
| 17 | |||
| 18 | my $lb = $cloud->load_balancers->get($id); | ||
| 19 | |||
| 20 | if ($main->output eq 'json') { | ||
| 21 | print encode_json($lb->data), "\n"; | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | |||
| 25 | printf "ID: %s\n", $lb->id; | ||
| 26 | printf "Name: %s\n", $lb->name; | ||
| 27 | printf "Type: %s\n", $lb->type_name // '-'; | ||
| 28 | printf "IPv4: %s\n", $lb->ipv4 // '-'; | ||
| 29 | printf "IPv6: %s\n", $lb->ipv6 // '-'; | ||
| 30 | printf "Location: %s\n", $lb->location_name // '-'; | ||
| 31 | printf "Algorithm: %s\n", $lb->algorithm->{type} // '-'; | ||
| 32 | printf "Created: %s\n", $lb->created // '-'; | ||
| 33 | |||
| 34 | my $targets = $lb->targets; | ||
| 35 | if ($targets && @$targets) { | ||
| 36 | print "\nTargets:\n"; | ||
| 37 | for my $t (@$targets) { | ||
| 38 | if ($t->{type} eq 'server' && $t->{server}) { | ||
| 39 | printf " - Server %d\n", $t->{server}{id}; | ||
| 40 | } elsif ($t->{type} eq 'label_selector') { | ||
| 41 | printf " - Label: %s\n", $t->{label_selector}{selector}; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | my $services = $lb->services; | ||
| 47 | if ($services && @$services) { | ||
| 48 | print "\nServices:\n"; | ||
| 49 | for my $s (@$services) { | ||
| 50 | printf " - %s :%d -> :%d\n", | ||
| 51 | $s->{protocol}, | ||
| 52 | $s->{listen_port}, | ||
| 53 | $s->{destination_port}; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | |||
| 60 | __END__ |