File Coverage

blib/lib/WWW/VastAI/Instance.pm
Criterion Covered Total %
statement 9 37 24.3
branch n/a
condition 1 4 25.0
subroutine 6 21 28.5
pod 20 20 100.0
total 36 82 43.9


line stmt bran cond sub pod time code
1             package WWW::VastAI::Instance;
2             our $VERSION = '0.001';
3             # ABSTRACT: Instance wrapper with convenience lifecycle helpers
4              
5 10     10   70 use Moo;
  10         44  
  10         92  
6             extends 'WWW::VastAI::Object';
7              
8 1     1 1 29 sub label { shift->data->{label} }
9 2     2 1 39 sub actual_status { shift->data->{actual_status} }
10 0     0 1 0 sub intended_status { shift->data->{intended_status} }
11 0     0 1 0 sub ssh_host { shift->data->{ssh_host} }
12 1     1 1 27 sub ssh_port { shift->data->{ssh_port} }
13 0     0 1 0 sub public_ipaddr { shift->data->{public_ipaddr} }
14 0     0 1 0 sub gpu_name { shift->data->{gpu_name} }
15 0     0 1 0 sub num_gpus { shift->data->{num_gpus} }
16              
17 1   50 1 1 4233 sub is_running { (shift->actual_status || '') eq 'running' }
18 0   0 0 1 0 sub is_stopped { (shift->actual_status || '') eq 'stopped' }
19              
20             sub refresh {
21 0     0 1 0 my ($self) = @_;
22 0         0 return $self->_replace_data($self->_client->instances->get($self->id)->raw);
23             }
24              
25             sub update {
26 0     0 1 0 my ($self, %params) = @_;
27 0         0 return $self->_replace_data($self->_client->instances->update($self->id, %params)->raw);
28             }
29              
30             sub start {
31 0     0 1 0 my ($self) = @_;
32 0         0 $self->_client->instances->start($self->id);
33 0         0 return $self;
34             }
35              
36             sub stop {
37 0     0 1 0 my ($self) = @_;
38 0         0 $self->_client->instances->stop($self->id);
39 0         0 return $self;
40             }
41              
42             sub set_label {
43 0     0 1 0 my ($self, $label) = @_;
44 0         0 $self->_client->instances->label($self->id, $label);
45 0         0 $self->data->{label} = $label;
46 0         0 return $self;
47             }
48              
49             sub logs {
50 0     0 1 0 my ($self, %params) = @_;
51 0         0 return $self->_client->instances->logs($self->id, %params);
52             }
53              
54             sub ssh_keys {
55 0     0 1 0 my ($self) = @_;
56 0         0 return $self->_client->instances->ssh_keys($self->id);
57             }
58              
59             sub attach_ssh_key {
60 0     0 1 0 my ($self, $ssh_key) = @_;
61 0         0 return $self->_client->instances->attach_ssh_key($self->id, $ssh_key);
62             }
63              
64             sub detach_ssh_key {
65 0     0 1 0 my ($self, $ssh_key_id) = @_;
66 0         0 return $self->_client->instances->detach_ssh_key($self->id, $ssh_key_id);
67             }
68              
69             sub delete {
70 1     1 1 3 my ($self) = @_;
71 1         30 return $self->_client->instances->delete($self->id);
72             }
73              
74             1;
75              
76             __END__