| 1 | package WWW::Hetzner::CLI::Cmd::Server::Cmd::Rebuild; | ||||||||||
| 2 | # ABSTRACT: Rebuild a server with a new image | ||||||||||
| 3 | |||||||||||
| 4 | 1 | our $VERSION = '0.102'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use MooX::Cmd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use MooX::Options protect_argv => 0, usage_string => 'USAGE: hcloud.pl server rebuild <id> --image <image>'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | with 'WWW::Hetzner::CLI::Role::WaitsForAction'; | |||||||||
| 11 | |||||||||||
| 12 | 1 | option image => ( | |||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | format => 's', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | doc => 'Image to rebuild with (e.g., debian-12, ubuntu-24.04)', | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||
| 20 | 2 | my ($self, $args, $chain) = @_; | |||||||||
| 21 | 2 | ▶ | my $id = $args->[0] or die "Usage: hcloud.pl server rebuild <id> --image <image>\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | my $main = $chain->[0]; | |||||||||
| 24 | 2 | my $cloud = $main->cloud; | |||||||||
| 25 | |||||||||||
| 26 | 2 | print "Rebuilding server $id with image ", $self->image, "...\n"; | |||||||||
| 27 | 2 | my $action = $cloud->servers->rebuild($id, $self->image); | |||||||||
| 28 | 2 | $self->handle_action($action); | |||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | if ($main->output eq 'json') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 1 | print encode_json({ %{ $action->data }, %{ $action->result } }), "\n"; | |||||||||
| 32 | } else { | ||||||||||
| 33 | 1 | ▶ | print $self->no_wait | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | ? "Server rebuild requested. Data on the server will be lost.\n" | ||||||||||
| 35 | : "Server rebuilt. Data on the server has been lost.\n"; | ||||||||||
| 36 | 1 | ▶ | if (defined $action->root_password) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | print "Root password: ", $action->root_password, "\n"; | |||||||||
| 38 | } | ||||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||