« lib/WWW/Hetzner/CLI/Cmd/LoadBalancer.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/AddTarget.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::LoadBalancer::Cmd::AddService; | ||
| 2 | # ABSTRACT: Add a service to 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 add-service <id> --protocol <proto> --listen-port <port> --destination-port <port>'; | ||
| 9 | |||
| 10 | option protocol => ( | ||
| 11 | is => 'ro', | ||
| 12 | format => 's', | ||
| 13 | required => 1, | ||
| 14 | doc => 'Protocol: tcp, http, https', | ||
| 15 | ); | ||
| 16 | |||
| 17 | option 'listen_port' => ( | ||
| 18 | is => 'ro', | ||
| 19 | format => 'i', | ||
| 20 | required => 1, | ||
| 21 | long_doc => 'listen-port', | ||
| 22 | doc => 'Listen port', | ||
| 23 | ); | ||
| 24 | |||
| 25 | option 'destination_port' => ( | ||
| 26 | is => 'ro', | ||
| 27 | format => 'i', | ||
| 28 | required => 1, | ||
| 29 | long_doc => 'destination-port', | ||
| 30 | doc => 'Destination port', | ||
| 31 | ); | ||
| 32 | |||
| 33 | sub execute { | ||
| 34 | my ($self, $args, $chain) = @_; | ||
| 35 | my $id = $args->[0] or die "Usage: hcloud.pl load-balancer add-service <id> --protocol <proto> --listen-port <port> --destination-port <port>\n"; | ||
| 36 | |||
| 37 | my $main = $chain->[0]; | ||
| 38 | my $cloud = $main->cloud; | ||
| 39 | |||
| 40 | print "Adding ", $self->protocol, " service to load balancer $id...\n"; | ||
| 41 | $cloud->load_balancers->add_service($id, | ||
| 42 | protocol => $self->protocol, | ||
| 43 | listen_port => $self->listen_port, | ||
| 44 | destination_port => $self->destination_port, | ||
| 45 | ); | ||
| 46 | print "Service added.\n"; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ |