lib/WWW/Hetzner/CLI/Cmd/Volume/Cmd/Create.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 84.3% 43 / 51 CC 4 SCAR 9.5
CC
4
Cov
88%
execute
4.2
BEGIN
1.0
BEGIN
1.0
CRAP 2.6
« lib/WWW/Hetzner/Cloud/Server.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Sshkey/Cmd/Describe.pm »
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
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
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 // "-"
l!l
10
MC/DC0%0/1
$volume->linux_device // "-"
$volume->linux_device
Truth table50%1/2
A
A= $volume->linux_device
Aresult
11
00
81 1 ▶ printf " Server: %s\n", $volume->server // 'not attached';
Condition50%1/2
$volume->server // "not attached"
l!l
01
MC/DC0%0/1
$volume->server // "not attached"
$volume->server
Truth table50%1/2
A
A= $volume->server
Aresult
11
00
82 }
83  
84 1 1;
85  
86 __END__
« lib/WWW/Hetzner/Cloud/Server.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Sshkey/Cmd/Describe.pm »