MetaAPI/API/Network.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 77.5% 45 / 58 CC 7 SCAR 12.1
CC
7
Cov
83%
create_floating_ip
4.9
add_floating_ip_to_server
4.1
BEGIN
1.0
CRAP 3.3
« MetaAPI/API/Service.pm ↑ Summary MetaAPI/Helpers/DataAsYaml.pm »
1 package OpenStack::MetaAPI::API::Network;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 extends 'OpenStack::MetaAPI::API::Service';
9  
10 # roles
11 3 with 'OpenStack::MetaAPI::Roles::Listable';
12 3 with 'OpenStack::MetaAPI::Roles::GetFromId';
13  
14 3 has '+name' => (default => 'network');
15 3 has '+version_prefix' => (default => 'v2.0');
16 3 has '+version' => (default => 'v2'); # use the v2 specs
17  
18 ## FIXME can be defined from specs
19 sub delete_floatingip {
20 1 ▶ my ($self, $uid) = @_;
Subroutine delete_floatingip: called CC=1 SCAR=0.0
Pod undocumented
21  
22 1 my $uri = $self->root_uri('/floatingips/' . $uid);
23 1 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 sub create_floating_ip {
30 1 ▶ my ($self, $network_id) = @_;
Subroutine create_floating_ip: called CC=4 SCAR=15.9
Pod undocumented
31  
32 1 ▶ die "Missing network_id" unless defined $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $network_id 0 1 1
33  
34 1 my $uri = $self->root_uri('/floatingips');
35 1 my $answer = $self->post(
36 $uri,
37 {floatingip => {floating_network_id => $network_id}});
38  
39 1 ▶ return $answer->{floatingip} if ref $answer && $answer->{floatingip};
Branch: 1 branch
BranchTrueFalseTotal
if ref $answer and $answer->{"floatingip"} 1 0 1
Condition33%1/3
ref $answer and $answer->{"floatingip"}
!ll&&!rl&&r
001
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 sub add_floating_ip_to_server {
44 1 ▶ my ($self, $floatingip_id, $server_id) = @_;
Subroutine add_floating_ip_to_server: called CC=4 SCAR=14.2
Pod undocumented
45  
46 1 ▶ die "floatingip_id is required" unless defined $floatingip_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $floatingip_id 0 1 1
47 1 ▶ die "server_id is required" unless defined $server_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $server_id 0 1 1
48  
49 1 my $uri = $self->root_uri('/ports');
50 1 my $ports = $self->get($uri, device_id => $server_id);
51  
52 # pick the first port for now (maybe need to check the network_id...)
53 1 my $port_id = eval { $ports->{ports}->[0]->{id} };
54 1 ▶ die "Cannot find a port for server $server_id: $@" unless defined $port_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port_id 0 1 1
55  
56 # now link the floating ip to the port
57 1 return $self->put(
58 $self->root_uri('/floatingips/' . $floatingip_id),
59 {floatingip => {port_id => $port_id}});
60 }
61  
62 3 1;
63  
64 __END__
65  
66 =pod
67  
68 =encoding UTF-8
69  
70 =head1 NAME
71  
72 OpenStack::MetaAPI::API::Network
73  
74 =head1 VERSION
75  
76 version 0.002
77  
78 =head1 AUTHOR
79  
80 Nicolas R <atoomic@cpan.org>
81  
82 =head1 COPYRIGHT AND LICENSE
83  
84 This software is copyright (c) 2019 by cPanel, Inc.
85  
86 This is free software; you can redistribute it and/or modify it under
87 the same terms as the Perl 5 programming language system itself.
88  
89 =cut
« MetaAPI/API/Service.pm ↑ Summary MetaAPI/Helpers/DataAsYaml.pm »