« lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/Reboot.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/Reset.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::Server::Cmd::Rebuild; | ||
| 2 | # ABSTRACT: Rebuild a server with a new image | ||
| 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 server rebuild <id> --image <image>'; | ||
| 9 | |||
| 10 | option image => ( | ||
| 11 | is => 'ro', | ||
| 12 | format => 's', | ||
| 13 | required => 1, | ||
| 14 | doc => 'Image to rebuild with (e.g., debian-12, ubuntu-24.04)', | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ($self, $args, $chain) = @_; | ||
| 19 | my $id = $args->[0] or die "Usage: hcloud.pl server rebuild <id> --image <image>\n"; | ||
| 20 | |||
| 21 | my $main = $chain->[0]; | ||
| 22 | my $cloud = $main->cloud; | ||
| 23 | |||
| 24 | print "Rebuilding server $id with image ", $self->image, "...\n"; | ||
| 25 | $cloud->servers->rebuild($id, $self->image); | ||
| 26 | print "Server rebuild initiated. Data on the server will be lost.\n"; | ||
| 27 | } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | |||
| 31 | __END__ |