| 1 | package WWW::Hetzner::Cloud::API::Volumes; | ||||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Volumes API | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 25 | our $VERSION = '0.100'; | |||||||||||||
| 5 | |||||||||||||||
| 6 | 25 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 25 | ▶ | use Carp qw(croak); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 25 | ▶ | use WWW::Hetzner::Cloud::Volume; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 25 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | 25 | has client => ( | |||||||||||||
| 13 | is => 'ro', | ||||||||||||||
| 14 | required => 1, | ||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||
| 16 | ); | ||||||||||||||
| 17 | |||||||||||||||
| 18 | sub _wrap { | ||||||||||||||
| 19 | 5 | ▶ | my ($self, $data) = @_; | ||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 5 | return WWW::Hetzner::Cloud::Volume->new( | |||||||||||||
| 21 | client => $self->client, | ||||||||||||||
| 22 | %$data, | ||||||||||||||
| 23 | ); | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | sub _wrap_list { | ||||||||||||||
| 27 | 1 | ▶ | my ($self, $list) = @_; | ||||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||||
| 28 | 1 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | |||||||||||||||
| 32 | sub list { | ||||||||||||||
| 33 | 1 | ▶ | my ($self, %params) = @_; | ||||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 34 | |||||||||||||||
| 35 | 1 | my $result = $self->client->get('/volumes', params => \%params); | |||||||||||||
| 36 | 1 | ▶ | return $self->_wrap_list($result->{volumes} // []); | ||||||||||||
|
Condition50%1/2
$result->{"volumes"} // []
MC/DC0%0/1
$result->{"volumes"} // []
$result->{"volumes"}
Truth table50%1/2
A
A= $result->{"volumes"}
| |||||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | |||||||||||||||
| 40 | sub get { | ||||||||||||||
| 41 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 42 | 2 | ▶ | croak "Volume ID required" unless $id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | 2 | my $result = $self->client->get("/volumes/$id"); | |||||||||||||
| 45 | 2 | return $self->_wrap($result->{volume}); | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | sub create { | ||||||||||||||
| 50 | 4 | ▶ | my ($self, %params) = @_; | ||||||||||||
|
Subroutine
create: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 4 | ▶ | croak "name required" unless $params{name}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 3 | ▶ | croak "size required" unless $params{size}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 2 | ▶ | croak "location required" unless $params{location}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | |||||||||||||||
| 56 | my $body = { | ||||||||||||||
| 57 | name => $params{name}, | ||||||||||||||
| 58 | size => $params{size}, | ||||||||||||||
| 59 | location => $params{location}, | ||||||||||||||
| 60 | 1 | }; | |||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | ▶ | $body->{format} = $params{format} if $params{format}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 1 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 1 | ▶ | $body->{automount} = $params{automount} if exists $params{automount}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 1 | ▶ | $body->{server} = $params{server} if $params{server}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | my $result = $self->client->post('/volumes', $body); | |||||||||||||
| 68 | 1 | return $self->_wrap($result->{volume}); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | |||||||||||||||
| 72 | sub delete { | ||||||||||||||
| 73 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 74 | 1 | ▶ | croak "Volume ID required" unless $id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | |||||||||||||||
| 76 | 1 | return $self->client->delete("/volumes/$id"); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | |||||||||||||||
| 80 | sub attach { | ||||||||||||||
| 81 | 1 | ▶ | my ($self, $id, $server_id, %opts) = @_; | ||||||||||||
|
Subroutine
attach: called CC=5 SCAR=18.1
Pod
documented
| |||||||||||||||
| 82 | 1 | ▶ | croak "Volume ID required" unless $id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 1 | ▶ | croak "Server ID required" unless $server_id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 1 | my $body = { server => $server_id }; | |||||||||||||
| 86 | 1 | ▶ | $body->{automount} = $opts{automount} ? \1 : \0 if exists $opts{automount}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 87 | |||||||||||||||
| 88 | 1 | return $self->client->post("/volumes/$id/actions/attach", $body); | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | |||||||||||||||
| 92 | sub detach { | ||||||||||||||
| 93 | 1 | ▶ | my ($self, $id) = @_; | ||||||||||||
|
Subroutine
detach: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 94 | 1 | ▶ | croak "Volume ID required" unless $id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | |||||||||||||||
| 96 | 1 | return $self->client->post("/volumes/$id/actions/detach", {}); | |||||||||||||
| 97 | } | ||||||||||||||
| 98 | |||||||||||||||
| 99 | |||||||||||||||
| 100 | sub resize { | ||||||||||||||
| 101 | 1 | ▶ | my ($self, $id, $size) = @_; | ||||||||||||
|
Subroutine
resize: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||
| 102 | 1 | ▶ | croak "Volume ID required" unless $id; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | 1 | ▶ | croak "Size required" unless $size; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 104 | |||||||||||||||
| 105 | 1 | return $self->client->post("/volumes/$id/actions/resize", { size => $size }); | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | |||||||||||||||
| 109 | 25 | 1; | |||||||||||||
| 110 | |||||||||||||||
| 111 | __END__ | ||||||||||||||