| 1 | package WWW::Hetzner::CLI::Cmd::PrimaryIp::Cmd::Assign; | ||
| 2 | # ABSTRACT: Assign a primary IP to a server | ||
| 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 primary-ip assign <id> --server <server-id>'; | ||
| 9 | |||
| 10 | option server => ( | ||
| 11 | is => 'ro', | ||
| 12 | format => 'i', | ||
| 13 | required => 1, | ||
| 14 | doc => 'Server ID to assign to', | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ($self, $args, $chain) = @_; | ||
| 19 | my $id = $args->[0] or die "Usage: hcloud.pl primary-ip assign <id> --server <server-id>\n"; | ||
| 20 | |||
| 21 | my $main = $chain->[0]; | ||
| 22 | my $cloud = $main->cloud; | ||
| 23 | |||
| 24 | print "Assigning primary IP $id to server ", $self->server, "...\n"; | ||
| 25 | $cloud->primary_ips->assign($id, $self->server, 'server'); | ||
| 26 | print "Primary IP assigned.\n"; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | __END__ |