« lib/WWW/Hetzner/CLI/Cmd/Firewall/Cmd/Describe.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/Describe.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::Create; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Create a Storage Box | ||||||||||||||||||||||||||||||||||||||||||
| 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 storage-box create --name <name> --type <type> --location <location> --password <password> [options]'; | ||||||||||||||||||||||||||||||||||||||||
|
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 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | option name => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box name' ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | option type => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box type ID or name' ); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | option location => ( is => 'ro', format => 's', required => 1, doc => 'Location ID or name' ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | option password => ( is => 'ro', format => 's', required => 1, doc => 'Storage Box password' ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | option label => ( is => 'ro', format => 's@', autosplit => ',', doc => 'Label key=value (repeatable)' ); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | option ssh_key => ( is => 'ro', format => 's@', autosplit => ',', doc => 'OpenSSH public key (repeatable)' ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | option reachable_externally => ( is => 'ro', doc => 'Allow access outside Hetzner networks' ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | option enable_samba => ( is => 'ro', doc => 'Enable Samba' ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | option enable_ssh => ( is => 'ro', doc => 'Enable SSH' ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | option enable_webdav => ( is => 'ro', doc => 'Enable WebDAV' ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | option enable_zfs => ( is => 'ro', doc => 'Show the ZFS Snapshot folder' ); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=16 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $main = $chain->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my %params = ( | |||||||||||||||||||||||||||||||||||||||||
| 29 | name => $self->name, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | storage_box_type => $self->type, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | location => $self->location, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | password => $self->password, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | if ($self->label) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my %labels; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | for my $label (@{$self->label}) { | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($key, $value) = split /=/, $label, 2; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | die "Label must be key=value\n" unless defined $key && length $key && defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $key and length $key and defined $value
defined $key and length $key
MC/DC0%0/3
defined $key and length $key and defined $value
defined $key
length $key
defined $value
Truth table0%0/4
A and B and C
A= defined $keyB= length $keyC= defined $value
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $labels{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $params{labels} = \%labels; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | $params{ssh_keys} = $self->ssh_key if $self->ssh_key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my %access; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | $access{reachable_externally} = $self->reachable_externally if defined $self->reachable_externally; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | $access{samba_enabled} = $self->enable_samba if defined $self->enable_samba; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $access{ssh_enabled} = $self->enable_ssh if defined $self->enable_ssh; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | $access{webdav_enabled} = $self->enable_webdav if defined $self->enable_webdav; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $access{zfs_enabled} = $self->enable_zfs if defined $self->enable_zfs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $params{access_settings} = \%access if %access; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | print "Creating Storage Box '", $self->name, "'...\n"; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $box = $main->storage->storage_boxes->create(%params); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $self->handle_action($box->action); | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ($main->output eq 'json') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | print encode_json($box->data), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | print "Storage Box created:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | printf " ID: %s\n", $box->id; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | printf " Name: %s\n", $box->name; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | printf " Status: %s\n", $box->status // '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$box->status // "-"
MC/DC0%0/1
$box->status // "-"
$box->status
Truth table50%1/2
A
A= $box->status
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | printf " Username: %s\n", $box->username // '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$box->username // "-"
MC/DC0%0/1
$box->username // "-"
$box->username
Truth table50%1/2
A
A= $box->username
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||||||