line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenStack::MetaAPI::API::Images; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'OpenStack::MetaAPI::API::Service'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# roles |
11
|
|
|
|
|
|
|
with 'OpenStack::MetaAPI::Roles::Listable'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has '+name' => (default => 'image'); |
14
|
|
|
|
|
|
|
has '+version_prefix' => (default => 'v2'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub images { |
18
|
0
|
|
|
0
|
0
|
0
|
my ($self, @args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
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
|
|
|
3
|
0
|
12
|
my ($self, $uid) = @_; |
29
|
|
|
|
|
|
|
|
30
|
3
|
50
|
|
|
|
11
|
die unless defined $uid; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
24
|
my $uri = $self->root_uri('/images/' . $uid); |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
64
|
return $self->get($uri); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub image_from_name { |
38
|
1
|
|
|
1
|
0
|
4
|
my ($self, $name) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# v2/images?name=in:"glass,%20darkly" |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
5
|
die unless defined $name; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
6
|
my $uri = $self->root_uri('/images'); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
19
|
my $reply = $self->get($uri, name => qq{in:"$name"}); |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
33
|
|
|
4945
|
return unless ref $reply && $reply->{images}; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
3
|
my $images = $reply->{images}; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
4
|
return unless ref $images; |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
5
|
if (scalar @$images > 1) { |
55
|
0
|
|
|
|
|
0
|
warn |
56
|
|
|
|
|
|
|
"image_from_name: more than one image sharing the same name '$name'"; |
57
|
0
|
|
|
|
|
0
|
return $images; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
9
|
return $images->[0]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
### helpers |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
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.001 |
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 |
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__ |