MetaAPI/API/Network.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 64.2% 9 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 79.1% 57 / 72 CC 10 SCAR 15.9
CC
10
Cov
85%
add_floating_ip_to_server
7.1
create_floating_ip
4.9
BEGIN
1.0
CRAP 4.9
« MetaAPI/Roles/GetFromId.pm ↑ Summary MetaAPI/API/Compute.pm »
1 package OpenStack::MetaAPI::API::Network;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 extends 'OpenStack::MetaAPI::API::Service';
9  
10 # roles
11 8 with 'OpenStack::MetaAPI::Roles::Listable';
12 8 with 'OpenStack::MetaAPI::Roles::GetFromId';
13  
14 8 has '+name' => (default => 'network');
15 8 has '+version_prefix' => (default => 'v2.0');
16 8 has '+version' => (default => 'v2'); # use the v2 specs
17  
18 ## FIXME can be defined from specs
19 2 ▶sub delete_floatingip {
Subroutine delete_floatingip: called CC=1 SCAR=0.0
Pod undocumented
20 2 my ($self, $uid) = @_;
21  
22 2 my $uri = $self->root_uri('/floatingips/' . $uid);
23 2 return $self->delete($uri);
24 }
25  
26 # REQ: curl -g -i -X POST http://service01a-c2.cpanel.net:9696/v2.0/floatingips
27 # -H "Content-Type: application/json" -H "User-Agent: openstacksdk/0.27.0 keystoneauth1/3.13.1 python-requests/2.21.0 CPython/3.6.6" -H "X-Auth-Token: {SHA256}b0ba0e5595347e63c0b6f56e7f035977abe209f6fa034f41f7dfe491e6e984a1" -d '{"floatingip": {"floating_network_id": "8a10163f-072c-483a-9834-78395cf8a2e7"}}'
28  
29 2 ▶sub create_floating_ip {
Subroutine create_floating_ip: called CC=4 SCAR=15.9
Pod undocumented
30 2 my ($self, $network_id) = @_;
31  
32 2 ▶ die "Missing network_id" unless defined $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $network_id 0 2 2
33  
34 2 my $uri = $self->root_uri('/floatingips');
35 2 my $answer = $self->post(
36 $uri,
37 {floatingip => {floating_network_id => $network_id}});
38  
39 2 ▶ return $answer->{floatingip} if ref $answer && $answer->{floatingip};
Branch: 1 branch
BranchTrueFalseTotal
if ref $answer and $answer->{"floatingip"} 2 0 2
Condition33%1/3
ref $answer and $answer->{"floatingip"}
!ll&&!rl&&r
002
MC/DC0%0/2
ref $answer and $answer->{"floatingip"}
ref $answer $answer->{"floatingip"}
Truth table33%1/3
A and B
A= ref $answerB= $answer->{"floatingip"}
ABresult
0X0
100
111
40 0 return $answer;
41 }
42  
43 5 ▶sub add_floating_ip_to_server {
Subroutine add_floating_ip_to_server: called CC=7 SCAR=19.7
Pod undocumented
44 5 my ($self, $floatingip_id, $server_id, %opts) = @_;
45  
46 5 ▶ die "floatingip_id is required" unless defined $floatingip_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $floatingip_id 0 5 5
47 5 ▶ die "server_id is required" unless defined $server_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $server_id 0 5 5
48  
49 5 my $uri = $self->root_uri('/ports');
50 5 my $ports = $self->get($uri, device_id => $server_id);
51  
52 5 my $port_id;
53 5 ▶ if (my $network_id = $opts{network_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $network_id = $opts{'network_id'}) { } 4 1 5
54 5 my @matching = grep { $_->{network_id} eq $network_id }
55 4 ▶ @{ $ports->{ports} // [] };
Condition50%1/2
$ports->{"ports"} // []
l!l
40
MC/DC0%0/1
$ports->{"ports"} // []
$ports->{"ports"}
Truth table50%1/2
A
A= $ports->{"ports"}
Aresult
11
00
56 4 ▶ die "Cannot find a port on network $network_id for server $server_id"
Branch: 1 branch
BranchTrueFalseTotal
unless @matching 1 3 4
57 unless @matching;
58 3 $port_id = $matching[0]->{id};
59 }
60 else {
61 1 $port_id = eval { $ports->{ports}->[0]->{id} };
62 1 ▶ die "Cannot find a port for server $server_id: $@"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port_id 0 1 1
63 unless defined $port_id;
64 }
65  
66 # now link the floating ip to the port
67 4 return $self->put(
68 $self->root_uri('/floatingips/' . $floatingip_id),
69 {floatingip => {port_id => $port_id}});
70 }
71  
72 8 1;
73  
74 __END__
« MetaAPI/Roles/GetFromId.pm ↑ Summary MetaAPI/API/Compute.pm »