MetaAPI/API/Compute.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 67.8% 19 / 28 Conditioncond 53.5% 15 / 28 MC/DCmcdc 27.7% 5 / 18 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 10 totaltotal 70.9% 115 / 162 CC 27 SCAR 15.1
CC
27
Cov
80%
delete_server
9.0
flavors_detail
5.2
detach_volume
4.1
CRAP 4.5
« MetaAPI/API/Network.pm ↑ Summary MetaAPI/API/Images.pm »
1 package OpenStack::MetaAPI::API::Compute;
2  
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # use Client::Lite::API role
9 #with 'OpenStack::MetaAPI::API'; ...
10  
11 13 extends 'OpenStack::MetaAPI::API::Service';
12  
13 # roles
14 #with 'OpenStack::MetaAPI::Roles::DataAsYaml';
15 13 with 'OpenStack::MetaAPI::Roles::Listable';
16 13 with 'OpenStack::MetaAPI::Roles::GetFromId';
17  
18 13 has '+name' => (default => 'compute');
19  
20 3 ▶sub delete_server {
Subroutine delete_server: called CC=8 SCAR=22.0
Pod undocumented
21 3 my ($self, $uid) = @_;
22  
23 # first check that the server exists
24 3 my $server = $self->api->server_from_uid($uid);
25 3 ▶ return unless ref $server && $server->{id} eq $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $server and $server->{"id"} eq $uid 0 3 3
Condition33%1/3
ref $server and $server->{"id"} eq $uid
!ll&&!rl&&r
003
MC/DC0%0/2
ref $server and $server->{"id"} eq $uid
ref $server $server->{"id"} eq $uid
Truth table33%1/3
A and B
A= ref $serverB= $server->{"id"} eq $uid
ABresult
0X0
100
111
26  
27 3 my $api = $self->api;
28 {
29 # delete floating ips for all ports on this device (supports multi-homed VMs)
30 3 my @ports_for_device = $api->ports(device_id => $uid);
31 3 for my $port (@ports_for_device) {
32 3 ▶ next unless ref $port && $port->{id};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $port and $port->{"id"} 1 2 3
Condition66%2/3
ref $port and $port->{"id"}
!ll&&!rl&&r
102
MC/DC50%1/2
ref $port and $port->{"id"}
ref $port $port->{"id"}
Truth table66%2/3
A and B
A= ref $portB= $port->{"id"}
ABresult
0X0
100
111
33  
34 2 my $floatingip = $api->floatingips(port_id => $port->{id});
35 2 ▶ if ($floatingip && $floatingip->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($floatingip and $floatingip->{"id"}) 2 0 2
Condition33%1/3
$floatingip and $floatingip->{"id"}
!ll&&!rl&&r
002
MC/DC0%0/2
$floatingip and $floatingip->{"id"}
$floatingip $floatingip->{"id"}
Truth table33%1/3
A and B
A= $floatingipB= $floatingip->{"id"}
ABresult
0X0
100
111
36 2 $api->delete_floatingip($floatingip->{id});
37 }
38 }
39 }
40  
41 # maybe need to wait?
42 3 my $uri = $self->root_uri('/servers/' . $uid);
43 3 return $self->delete($uri);
44 }
45  
46 # FIXME should be generated from specs
47 9 ▶sub create_server {
Subroutine create_server: called CC=2 SCAR=7.4
Pod undocumented
48 9 my ($self, %opts) = @_;
49  
50 9 my $uri = $self->root_uri('/servers/');
51 9 my $output = $self->post($uri, {server => {%opts}});
52 9 ▶ return $output->{server} if ref $output;
Branch: 1 branch
BranchTrueFalseTotal
if ref $output 9 0 9
53 0 return $output;
54 }
55  
56 ### helpers
57  
58 # What this project may have, and what it is already using.
59 #
60 # Both halves arrive in one response, which is what makes this the right thing
61 # to ask when deciding whether another guest fits. /os-quota-sets gives only
62 # the allowance, leaving you to add the usage up yourself from the server list.
63 1 ▶sub limits {
Subroutine limits: called CC=2 SCAR=7.1
Pod undocumented
64 1 my ($self) = @_;
65  
66 1 my $out = $self->get($self->root_uri('/limits'));
67  
68 1 ▶ return ref $out ? $out->{limits} : $out;
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 1 0 1
69 }
70  
71 # Everything Nova models as an action on an existing server: snapshots, power
72 # state, rebuild. They are all one POST to the same place with a different
73 # single-key body, so they are all this.
74 5 ▶sub server_action {
Subroutine server_action: called CC=4 SCAR=13.9
Pod undocumented
75 5 my ($self, $uid, $action) = @_;
76  
77 5 ▶ die "server id is required by server_action" unless defined $uid && length $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uid and length $uid 1 4 5
Condition66%2/3
defined $uid and length $uid
!ll&&!rl&&r
014
MC/DC50%1/2
defined $uid and length $uid
defined $uid length $uid
Truth table66%2/3
A and B
A= defined $uidB= length $uid
ABresult
0X0
100
111
78 4 ▶ die "action must be a hash reference" unless ref $action eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $action eq "HASH" 1 3 4
79  
80 3 return $self->post($self->root_uri("/servers/$uid/action"), $action);
81 }
82  
83 # Snapshot a server into a Glance image.
84 #
85 # Nova returns the new image's id in the Location header, and only puts it in
86 # the body from microversion 2.45 on -- so neither is worth relying on. Ask
87 # Glance for the name afterwards instead.
88 2 ▶sub create_image {
Subroutine create_image: called CC=3 SCAR=11.0
Pod undocumented
89 2 my ($self, $uid, %opts) = @_;
90  
91 2 my $name = delete $opts{name};
92 2 ▶ die "'name' is required by create_image" unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 1 1 2
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
101
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
93  
94 1 return $self->server_action($uid, {createImage => {name => $name, %opts}});
95 }
96  
97 # The flavor list is names and ids; this is the one that knows how many CPUs.
98 2 ▶sub flavors_detail {
Subroutine flavors_detail: called CC=5 SCAR=16.5
Pod undocumented
99 2 my ($self, %filter) = @_;
100  
101 2 my $out = $self->get($self->root_uri('/flavors/detail'));
102 2 ▶ my @all = ref $out ? @{$out->{flavors} // []} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 2 0 2
Condition50%1/2
$out->{"flavors"} // []
l!l
20
MC/DC0%0/1
$out->{"flavors"} // []
$out->{"flavors"}
Truth table50%1/2
A
A= $out->{"flavors"}
Aresult
11
00
103  
104 2 foreach my $key (sort keys %filter) {
105 1 ▶ @all = grep { defined $_->{$key} && $_->{$key} eq $filter{$key} } @all;
Condition66%2/3
defined $_->{$key} && $_->{$key} eq $filter{$key}
!ll&&!rl&&r
011
MC/DC50%1/2
defined $_->{$key} && $_->{$key} eq $filter{$key}
defined $_->{$key} $_->{$key} eq $filter{$key}
Truth table66%2/3
A && B
A= defined $_->{$key}B= $_->{$key} eq $filter{$key}
ABresult
0X0
100
111
106 }
107  
108 2 return @all;
109 }
110  
111 # What the guest wrote to its serial console. When a guest never comes up this
112 # is usually the only thing that says why.
113 1 ▶sub console_output {
Subroutine console_output: called CC=2 SCAR=7.1
Pod undocumented
114 1 my ($self, $uid, $length) = @_;
115  
116 1 my $out = $self->server_action($uid, {'os-getConsoleOutput' => {length => $length}});
117  
118 1 ▶ return ref $out ? $out->{output} : $out;
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 1 0 1
119 }
120  
121 # Volumes are Cinder's, but attaching one to a server is Nova's.
122 1 ▶sub server_volumes {
Subroutine server_volumes: called CC=3 SCAR=11.4
Pod undocumented
123 1 my ($self, $uid) = @_;
124  
125 1 my $out = $self->get($self->root_uri("/servers/$uid/os-volume_attachments"));
126  
127 1 ▶ return ref $out ? @{$out->{volumeAttachments} // []} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 1 0 1
Condition50%1/2
$out->{"volumeAttachments"} // []
l!l
10
MC/DC0%0/1
$out->{"volumeAttachments"} // []
$out->{"volumeAttachments"}
Truth table50%1/2
A
A= $out->{"volumeAttachments"}
Aresult
11
00
128 }
129  
130 2 ▶sub attach_volume {
Subroutine attach_volume: called CC=4 SCAR=14.1
Pod undocumented
131 2 my ($self, $uid, $volume_id, %opts) = @_;
132  
133 2 ▶ die "volume id is required by attach_volume" unless defined $volume_id && length $volume_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $volume_id and length $volume_id 1 1 2
Condition66%2/3
defined $volume_id and length $volume_id
!ll&&!rl&&r
011
MC/DC50%1/2
defined $volume_id and length $volume_id
defined $volume_id length $volume_id
Truth table66%2/3
A and B
A= defined $volume_idB= length $volume_id
ABresult
0X0
100
111
134  
135 1 my $out = $self->post(
136 $self->root_uri("/servers/$uid/os-volume_attachments"),
137 {volumeAttachment => {volumeId => $volume_id, %opts}});
138  
139 1 ▶ return ref $out ? $out->{volumeAttachment} : $out;
Branch: 1 branch
BranchTrueFalseTotal
ref $out ? : 1 0 1
140 }
141  
142 1 ▶sub detach_volume {
Subroutine detach_volume: called CC=3 SCAR=14.2
Pod undocumented
143 1 my ($self, $uid, $volume_id) = @_;
144  
145 1 ▶ die "volume id is required by detach_volume" unless defined $volume_id && length $volume_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $volume_id and length $volume_id 1 0 1
Condition33%1/3
defined $volume_id and length $volume_id
!ll&&!rl&&r
010
MC/DC0%0/2
defined $volume_id and length $volume_id
defined $volume_id length $volume_id
Truth table33%1/3
A and B
A= defined $volume_idB= length $volume_id
ABresult
0X0
100
111
146  
147 0 return $self->delete($self->root_uri("/servers/$uid/os-volume_attachments/$volume_id"));
148 }
149  
150 13 1;
151  
152 __END__
« MetaAPI/API/Network.pm ↑ Summary MetaAPI/API/Images.pm »