| 1 | package WWW::Hetzner::CLI::Cmd::Network::Cmd::AddRoute; | ||
| 2 | # ABSTRACT: Add a route to a network | ||
| 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 network add-route <id> --destination <cidr> --gateway <ip>'; | ||
| 9 | |||
| 10 | option destination => ( | ||
| 11 | is => 'ro', | ||
| 12 | format => 's', | ||
| 13 | required => 1, | ||
| 14 | doc => 'Route destination (e.g. 10.100.0.0/16)', | ||
| 15 | ); | ||
| 16 | |||
| 17 | option gateway => ( | ||
| 18 | is => 'ro', | ||
| 19 | format => 's', | ||
| 20 | required => 1, | ||
| 21 | doc => 'Gateway IP address', | ||
| 22 | ); | ||
| 23 | |||
| 24 | sub execute { | ||
| 25 | my ($self, $args, $chain) = @_; | ||
| 26 | my $id = $args->[0] or die "Usage: hcloud.pl network add-route <id> --destination <cidr> --gateway <ip>\n"; | ||
| 27 | |||
| 28 | my $main = $chain->[0]; | ||
| 29 | my $cloud = $main->cloud; | ||
| 30 | |||
| 31 | print "Adding route ", $self->destination, " via ", $self->gateway, " to network $id...\n"; | ||
| 32 | $cloud->networks->add_route($id, | ||
| 33 | destination => $self->destination, | ||
| 34 | gateway => $self->gateway, | ||
| 35 | ); | ||
| 36 | print "Route added.\n"; | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | __END__ |