File Coverage

blib/lib/DigitalOcean/Droplet.pm
Criterion Covered Total %
statement 12 81 14.8
branch n/a
condition n/a
subroutine 4 33 12.1
pod 28 28 100.0
total 44 142 30.9


line stmt bran cond sub pod time code
1 1     1   3 use strict;
  1         1  
  1         27  
2             package DigitalOcean::Droplet;
3 1     1   2 use Mouse;
  1         1  
  1         3  
4 1     1   477 use DigitalOcean::Types;
  1         1  
  1         24  
5 1     1   288 use DigitalOcean::Snapshot;
  1         1  
  1         859  
6              
7             #ABSTRACT: Represents a Droplet object in the DigitalOcean API
8              
9             has DigitalOcean => (
10             is => 'rw',
11             isa => 'DigitalOcean',
12             );
13              
14             has id => (
15             is => 'ro',
16             isa => 'Num',
17             );
18              
19             has name => (
20             is => 'rw',
21             isa => 'Str',
22             );
23              
24             has memory => (
25             is => 'rw',
26             isa => 'Num',
27             );
28              
29             has vcpus => (
30             is => 'rw',
31             isa => 'Num',
32             );
33              
34             has disk => (
35             is => 'rw',
36             isa => 'Num',
37             );
38              
39             has locked => (
40             is => 'rw',
41             isa => 'Bool',
42             );
43              
44             has created_at => (
45             is => 'rw',
46             isa => 'Str',
47             );
48              
49             has status => (
50             is => 'rw',
51             isa => 'Str',
52             );
53              
54             has backup_ids => (
55             is => 'rw',
56             isa => 'ArrayRef',
57             default => sub { [] },
58             );
59              
60             has snapshot_ids => (
61             is => 'rw',
62             isa => 'ArrayRef',
63             default => sub { [] },
64             );
65              
66             has features => (
67             is => 'rw',
68             isa => 'ArrayRef',
69             default => sub { [] },
70             );
71              
72             has region => (
73             is => 'rw',
74             isa => 'Coerced::DigitalOcean::Region',
75             coerce => 1,
76             );
77              
78             has image => (
79             is => 'rw',
80             isa => 'Coerced::DigitalOcean::Image',
81             coerce => 1,
82             );
83              
84             has size => (
85             is => 'rw',
86             isa => 'Coerced::DigitalOcean::Size',
87             coerce => 1,
88             );
89              
90             has size_slug => (
91             is => 'rw',
92             isa => 'Str',
93             );
94              
95             has networks => (
96             is => 'rw',
97             isa => 'Coerced::DigitalOcean::Networks',
98             coerce => 1,
99             );
100              
101             has kernel => (
102             is => 'rw',
103             isa => 'Undef|Coerced::DigitalOcean::Kernel',
104             coerce => 1,
105             );
106              
107             has next_backup_window => (
108             is => 'rw',
109             isa => 'Undef|Coerced::DigitalOcean::NextBackupWindow',
110             coerce => 1,
111             );
112              
113             sub _action {
114 0     0     my $self = shift;
115 0           my (%req_body_hash) = @_;
116              
117 0           my %new_args;
118 0           $new_args{path} = $self->path . 'actions';
119 0           $new_args{req_body_hash} = \%req_body_hash;
120              
121 0           $self->DigitalOcean->_action(%new_args);
122             }
123              
124              
125             sub path {
126 0     0 1   'droplets/' . shift->id . '/';
127             }
128              
129              
130             sub kernels {
131 0     0 1   my ($self, $per_page) = @_;
132 0           return $self->DigitalOcean->_get_collection($self->path . 'kernels', 'DigitalOcean::Kernel', 'kernels', {per_page => $per_page});
133             }
134              
135              
136             sub snapshots {
137 0     0 1   my ($self, $per_page) = @_;
138 0           return $self->DigitalOcean->_get_collection($self->path . 'snapshots', 'DigitalOcean::Snapshot', 'snapshots', {per_page => $per_page});
139             }
140              
141              
142             sub backups {
143 0     0 1   my ($self, $per_page) = @_;
144 0           return $self->DigitalOcean->_get_collection($self->path . 'backups', 'DigitalOcean::Backup', 'backups', {per_page => $per_page});
145             }
146              
147              
148             sub actions {
149 0     0 1   my ($self, $per_page) = @_;
150 0           my $init_arr = [['DigitalOcean', $self]];
151 0           return $self->DigitalOcean->_get_collection($self->path . 'actions', 'DigitalOcean::Action', 'actions', {per_page => $per_page}, $init_arr);
152             }
153              
154              
155             sub delete {
156 0     0 1   my ($self) = @_;
157 0           return $self->DigitalOcean->_delete(path => $self->path);
158             }
159              
160              
161             sub neighbors {
162 0     0 1   my ($self) = @_;
163              
164 0           return $self->DigitalOcean->_get_array($self->path . 'neighbors', 'DigitalOcean::Droplet', 'droplets');
165              
166             }
167              
168              
169             sub action {
170 0     0 1   my ($self, $id) = @_;
171              
172 0           return $self->DigitalOcean->_get_object($self->path . "actions/$id", 'DigitalOcean::Action', 'action');
173             }
174              
175              
176 0     0 1   sub disable_backups { shift->_action(@_, type => 'disable_backups') }
177              
178              
179 0     0 1   sub reboot { shift->_action(@_, type => 'reboot') }
180              
181              
182 0     0 1   sub power_cycle { shift->_action(@_, type => 'power_cycle') }
183              
184              
185 0     0 1   sub shutdown { shift->_action(@_, type => 'shutdown') }
186              
187              
188 0     0 1   sub power_off { shift->_action(@_, type => 'power_off') }
189              
190              
191 0     0 1   sub power_on { shift->_action(@_, type => 'power_on') }
192              
193              
194 0     0 1   sub restore { shift->_action(@_, type => 'restore') }
195              
196              
197 0     0 1   sub password_reset { shift->_action(@_, type => 'password_reset') }
198              
199              
200 0     0 1   sub resize { shift->_action(@_, type => 'resize') }
201              
202            
203             sub resize_reboot {
204 0     0 1   my $self = shift;
205 0           my @arr;
206              
207 0           push(@arr, $self->power_off(wait_on_action => 1));
208 0           push(@arr, $self->resize(@_, wait_on_action => 1));
209 0           push(@arr, $self->power_on(wait_on_action => 1));
210              
211 0           return \@arr;
212             }
213              
214              
215 0     0 1   sub rebuild { shift->_action(@_, type => 'rebuild') }
216              
217              
218             sub rename {
219 0     0 1   my $self = shift;
220 0           my (%params) = @_;
221              
222 0           my $action = $self->_action(@_, type => 'rename');
223 0           $self->name($params{name});
224 0           return $action;
225             }
226              
227              
228 0     0 1   sub change_kernel { shift->_action(@_, type => 'change_kernel') }
229              
230              
231             sub change_kernel_reboot {
232 0     0 1   my $self = shift;
233 0           my @arr;
234              
235 0           push(@arr, $self->change_kernel(@_, wait_on_action => 1));
236 0           push(@arr, $self->power_off(wait_on_action => 1));
237 0           push(@arr, $self->power_on(wait_on_action => 1));
238              
239 0           return \@arr;
240             }
241              
242              
243 0     0 1   sub enable_ipv6 { shift->_action(@_, type => 'enable_ipv6') }
244              
245              
246 0     0 1   sub enable_private_networking { shift->_action(@_, type => 'enable_private_networking') }
247              
248            
249             sub enable_private_networking_reboot {
250 0     0 1   my $self = shift;
251 0           my @arr;
252              
253 0           push(@arr, $self->power_off(wait_on_action => 1));
254 0           push(@arr, $self->enable_private_networking(@_, wait_on_action => 1));
255 0           push(@arr, $self->power_on(wait_on_action => 1));
256              
257 0           return \@arr;
258             }
259              
260              
261             sub snapshot {
262 0     0 1   my $self = shift;
263              
264 0           my $action = $self->_action(@_, type => 'snapshot');
265 0           my $temp_droplet = $self->DigitalOcean->droplet($self->id);
266 0           $self->snapshot_ids($temp_droplet->snapshot_ids);
267              
268 0           return $action;
269             }
270              
271            
272             sub snapshot_reboot {
273 0     0 1   my $self = shift;
274              
275 0           my @arr;
276              
277 0           push(@arr, $self->power_off(wait_on_action => 1));
278 0           push(@arr, $self->snapshot(@_, wait_on_action => 1));
279              
280 0           return \@arr;
281             }
282              
283              
284 0     0 1   sub upgrade { shift->_action(@_, type => 'upgrade') }
285              
286              
287             __PACKAGE__->meta->make_immutable();
288              
289             1;
290              
291             __END__