MetaAPI/API/Images.pm

filter: Statementstmt 87.1% 27 / 31 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 3 totaltotal 69.0% 38 / 55 CC 7 SCAR 15.3
CC
7
Cov
75%
image_from_name
7.7
image_from_uid
2.0
images
2.0
CRAP 4.6
« MetaAPI/API/Compute.pm ↑ Summary MetaAPI/API/Service.pm »
1 package OpenStack::MetaAPI::API::Images;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 extends 'OpenStack::MetaAPI::API::Service';
9  
10 # roles
11 2 with 'OpenStack::MetaAPI::Roles::Listable';
12  
13 2 has '+name' => (default => 'image');
14 2 has '+version_prefix' => (default => 'v2');
15  
16  
17 sub images {
18 0 ▶ my ($self, @args) = @_;
Subroutine images: not called CC=1 SCAR=6.9
Pod undocumented
19  
20 0 die "Please use image_from_uid image_from_name";
21 }
22  
23 # API doc
24 # https://developer.openstack.org/api-ref/image/v2/?expanded=list-images-detail
25  
26 # FIXME: should be added to specs
27 sub image_from_uid {
28 3 ▶ my ($self, $uid) = @_;
Subroutine image_from_uid: called CC=2 SCAR=7.0
Pod undocumented
29  
30 3 ▶ die unless defined $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uid 0 3 3
31  
32 3 my $uri = $self->root_uri('/images/' . $uid);
33  
34 3 return $self->get($uri);
35 }
36  
37 sub image_from_name {
38 1 ▶ my ($self, $name) = @_;
Subroutine image_from_name: called CC=6 SCAR=20.5
Pod undocumented
39  
40 # v2/images?name=in:"glass,%20darkly"
41  
42 1 ▶ die unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
43  
44 1 my $uri = $self->root_uri('/images');
45  
46 1 my $reply = $self->get($uri, name => qq{in:"$name"});
47  
48 1 ▶ return unless ref $reply && $reply->{images};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reply and $reply->{"images"} 0 1 1
Condition33%1/3
ref $reply and $reply->{"images"}
!ll&&!rl&&r
001
MC/DC0%0/2
ref $reply and $reply->{"images"}
ref $reply $reply->{"images"}
Truth table33%1/3
A and B
A= ref $replyB= $reply->{"images"}
ABresult
0X0
100
111
49  
50 1 my $images = $reply->{images};
51  
52 1 ▶ return unless ref $images;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $images 0 1 1
53  
54 1 ▶ if (scalar @$images > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$images > 1) 0 1 1
55 0 warn
56 "image_from_name: more than one image sharing the same name '$name'";
57 0 return $images;
58 }
59  
60 1 return $images->[0];
61 }
62  
63 ### helpers
64  
65 2 1;
66  
67 =pod
68  
69 =encoding UTF-8
70  
71 =head1 NAME
72  
73 OpenStack::MetaAPI::API::Images
74  
75 =head1 VERSION
76  
77 version 0.002
78  
79 Note loading all images can be very slow
80 as we have to use multiple requests (kind of pagination)...
81 and can result to require more than 50 requests...
82  
83 For this reason we would prefer selecting one image
84 either by its 'exact name' or its 'UID'
85  
86 =head1 AUTHOR
87  
88 Nicolas R <atoomic@cpan.org>
89  
90 =head1 COPYRIGHT AND LICENSE
91  
92 This software is copyright (c) 2019 by cPanel, Inc.
93  
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96  
97 =cut
98  
99 __DATA__
100 ---
101 keypairs:
102 listable: 1
103 flavors:
104 listable: 1
105  
106  
107  
« MetaAPI/API/Compute.pm ↑ Summary MetaAPI/API/Service.pm »