| 1 | package WWW::Hetzner::CLI::Cmd::Firewall::Cmd::ApplyTo; | ||
| 2 | # ABSTRACT: Apply a firewall 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 firewall apply-to <firewall-id> --server <server-id>'; | ||
| 9 | |||
| 10 | option server => ( | ||
| 11 | is => 'ro', | ||
| 12 | format => 'i', | ||
| 13 | required => 1, | ||
| 14 | doc => 'Server ID to apply firewall to', | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ($self, $args, $chain) = @_; | ||
| 19 | my $id = $args->[0] or die "Usage: hcloud.pl firewall apply-to <firewall-id> --server <server-id>\n"; | ||
| 20 | |||
| 21 | my $main = $chain->[0]; | ||
| 22 | my $cloud = $main->cloud; | ||
| 23 | |||
| 24 | print "Applying firewall $id to server ", $self->server, "...\n"; | ||
| 25 | $cloud->firewalls->apply_to_resources($id, | ||
| 26 | { type => 'server', server => { id => $self->server } }, | ||
| 27 | ); | ||
| 28 | print "Firewall applied.\n"; | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; | ||
| 32 | |||
| 33 | __END__ |