| 1 | package WWW::Hetzner::CLI::Cmd::Volume::Cmd::Create; | ||||||||||||
| 2 | # ABSTRACT: Create a volume | ||||||||||||
| 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 usage_string => 'USAGE: hcloud.pl volume create --name <name> --size <gb> --location <loc>'; | ||||||||||
|
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 name => ( | |||||||||||
| 13 | is => 'ro', | ||||||||||||
| 14 | format => 's', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | doc => 'Volume name', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 1 | option size => ( | |||||||||||
| 20 | is => 'ro', | ||||||||||||
| 21 | format => 'i', | ||||||||||||
| 22 | required => 1, | ||||||||||||
| 23 | doc => 'Volume size in GB (min 10)', | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 1 | option location => ( | |||||||||||
| 27 | is => 'ro', | ||||||||||||
| 28 | format => 's', | ||||||||||||
| 29 | required => 1, | ||||||||||||
| 30 | doc => 'Location (e.g., fsn1, nbg1, hel1)', | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 1 | option format => ( | |||||||||||
| 34 | is => 'ro', | ||||||||||||
| 35 | format => 's', | ||||||||||||
| 36 | doc => 'Filesystem format: ext4, xfs (default: ext4)', | ||||||||||||
| 37 | default => 'ext4', | ||||||||||||
| 38 | ); | ||||||||||||
| 39 | |||||||||||||
| 40 | 1 | option server => ( | |||||||||||
| 41 | is => 'ro', | ||||||||||||
| 42 | format => 'i', | ||||||||||||
| 43 | doc => 'Server ID to attach to', | ||||||||||||
| 44 | ); | ||||||||||||
| 45 | |||||||||||||
| 46 | 1 | option automount => ( | |||||||||||
| 47 | is => 'ro', | ||||||||||||
| 48 | doc => 'Automount volume after attach', | ||||||||||||
| 49 | default => 0, | ||||||||||||
| 50 | ); | ||||||||||||
| 51 | |||||||||||||
| 52 | 1 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||
| 53 | 1 | my ($self, $args, $chain) = @_; | |||||||||||
| 54 | |||||||||||||
| 55 | 1 | my $main = $chain->[0]; | |||||||||||
| 56 | 1 | my $cloud = $main->cloud; | |||||||||||
| 57 | |||||||||||||
| 58 | 1 | print "Creating volume '", $self->name, "'...\n"; | |||||||||||
| 59 | |||||||||||||
| 60 | 1 | my $volume = $cloud->volumes->create( | |||||||||||
| 61 | name => $self->name, | ||||||||||||
| 62 | size => $self->size, | ||||||||||||
| 63 | location => $self->location, | ||||||||||||
| 64 | format => $self->format, | ||||||||||||
| 65 | server => $self->server, | ||||||||||||
| 66 | automount => $self->automount, | ||||||||||||
| 67 | ); | ||||||||||||
| 68 | 1 | $self->handle_action($volume->action); | |||||||||||
| 69 | |||||||||||||
| 70 | 1 | ▶ | if ($main->output eq 'json') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | 0 | print encode_json($volume->data), "\n"; | |||||||||||
| 72 | 0 | return; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 1 | print "Volume created:\n"; | |||||||||||
| 76 | 1 | printf " ID: %s\n", $volume->id; | |||||||||||
| 77 | 1 | printf " Name: %s\n", $volume->name; | |||||||||||
| 78 | 1 | printf " Size: %s GB\n", $volume->size; | |||||||||||
| 79 | 1 | printf " Location: %s\n", $volume->location; | |||||||||||
| 80 | 1 | ▶ | printf " Device: %s\n", $volume->linux_device // '-'; | ||||||||||
|
Condition50%1/2
$volume->linux_device // "-"
MC/DC0%0/1
$volume->linux_device // "-"
$volume->linux_device
Truth table50%1/2
A
A= $volume->linux_device
| |||||||||||||
| 81 | 1 | ▶ | printf " Server: %s\n", $volume->server // 'not attached'; | ||||||||||
|
Condition50%1/2
$volume->server // "not attached"
MC/DC0%0/1
$volume->server // "not attached"
$volume->server
Truth table50%1/2
A
A= $volume->server
| |||||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 1 | 1; | |||||||||||
| 85 | |||||||||||||
| 86 | __END__ | ||||||||||||