| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $reply and $reply->{"images"}
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"}
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | my $images = $reply->{images}; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | return unless ref $images; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | if (scalar @$images > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||