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