File Coverage

blib/lib/OpenStack/MetaAPI/API/Compute.pm
Criterion Covered Total %
statement 26 27 96.3
branch 4 8 50.0
condition 4 9 44.4
subroutine 5 5 100.0
pod 0 2 0.0
total 39 51 76.4


line stmt bran cond sub pod time code
1             package OpenStack::MetaAPI::API::Compute;
2              
3 3     3   21 use strict;
  3         5  
  3         90  
4 3     3   13 use warnings;
  3         6  
  3         69  
5              
6 3     3   13 use Moo;
  3         5  
  3         16  
7              
8             # use Client::Lite::API role
9             #with 'OpenStack::MetaAPI::API'; ...
10              
11             extends 'OpenStack::MetaAPI::API::Service';
12              
13             # roles
14             #with 'OpenStack::MetaAPI::Roles::DataAsYaml';
15             with 'OpenStack::MetaAPI::Roles::Listable';
16             with 'OpenStack::MetaAPI::Roles::GetFromId';
17              
18             has '+name' => (default => 'compute');
19              
20             sub delete_server {
21 2     2 0 6 my ($self, $uid) = @_;
22              
23             # first check that the server exists
24 2         38 my $server = $self->api->server_from_uid($uid);
25 2 50 33     10 return unless ref $server && $server->{id} eq $uid;
26              
27 2         7 my $api = $self->api;
28             {
29             # delete floating ip for device [maybe provide its own helper at the main level of API]
30 2         3 my $port_for_device = $api->ports(device_id => $uid);
  2         53  
31 2 50 66     10 if ($port_for_device && $port_for_device->{id}) {
32              
33 1         3 my $port_id = $port_for_device->{id};
34 1         24 my $floatingip = $api->floatingips(port_id => $port_id);
35              
36 1 50 33     8 if ($floatingip && $floatingip->{id}) {
37 1         24 $api->delete_floatingip($floatingip->{id});
38             }
39             }
40             }
41              
42             # maybe need to wait?
43 2         1794 my $uri = $self->root_uri('/servers/' . $uid);
44 2         37 return $self->delete($uri);
45             }
46              
47             # FIXME should be generated from specs
48             sub create_server {
49 2     2 0 12 my ($self, %opts) = @_;
50              
51 2         6 my $uri = $self->root_uri('/servers/');
52 2         48 my $output = $self->post($uri, {server => {%opts}});
53 2 50       3546 return $output->{server} if ref $output;
54 0           return $output;
55             }
56              
57             ### helpers
58              
59             1;
60              
61             __END__