line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webservice::OVH::Cloud; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=encoding utf-8 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Webservice::OVH::Domain |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Webservice::OVH; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $ovh = Webservice::OVH->new_from_json("credentials.json"); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $projects = $ovh->cloud->projects; |
16
|
|
|
|
|
|
|
foreach my $project (@$project) { |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
print $project->name; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
print "I have a project" if $ovh->cloud->project_exists("Name"); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Gives access to projects connected to the used account. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
36
|
|
|
36
|
|
292
|
use strict; |
|
36
|
|
|
|
|
84
|
|
|
36
|
|
|
|
|
1302
|
|
32
|
36
|
|
|
36
|
|
201
|
use warnings; |
|
36
|
|
|
|
|
83
|
|
|
36
|
|
|
|
|
1273
|
|
33
|
36
|
|
|
36
|
|
202
|
use Carp qw{ carp croak }; |
|
36
|
|
|
|
|
72
|
|
|
36
|
|
|
|
|
3100
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = 0.46; |
36
|
|
|
|
|
|
|
|
37
|
36
|
|
|
36
|
|
19169
|
use Webservice::OVH::Cloud::Project; |
|
36
|
|
|
|
|
131
|
|
|
36
|
|
|
|
|
28198
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 _new |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Internal Method to create the cloud object. |
42
|
|
|
|
|
|
|
This method is not ment to be called directly. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * Return: L<Webservice::OVH::Project> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * Synopsis: Webservice::OVH::Clooud->_new($ovh_api_wrapper, $self); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=back |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _new { |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
0
|
|
|
my ( $class, %params ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
die "Missing module" unless $params{module}; |
61
|
0
|
0
|
|
|
|
|
die "Missing wrapper" unless $params{wrapper}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $module = $params{module}; |
64
|
0
|
|
|
|
|
|
my $api_wrapper = $params{wrapper}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _projects => {}, _avaiable_projects => [] }, $class; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 project_exists |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns 1 if project is available for the connected account, 0 if not. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * Parameter: $project_name - Domain name, $no_recheck - (optional)only for internal usage |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * Return: VALUE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * Synopsis: print "Name exists" if $ovh->domain->project_exists("Name"); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub project_exists { |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
1
|
|
my ( $self, $id, $no_recheck ) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( !$no_recheck ) { |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
94
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'get', path => "/cloud/project", noSignature => 0 ); |
95
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $list = $response->content; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
return ( grep { $_ eq $id } @$list ) ? 1 : 0; |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} else { |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $list = $self->{_avaiable_projects}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
return ( grep { $_ eq $id } @$list ) ? 1 : 0; |
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 projects |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Produces an array of all available projects that are connected to the used account. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * Return: ARRAY |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * Synopsis: my $projects = $ovh->order->projects(); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub projects { |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
128
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'get', path => "/cloud/project", noSignature => 0 ); |
129
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $project_array = $response->content; |
132
|
0
|
|
|
|
|
|
my $projects = []; |
133
|
0
|
|
|
|
|
|
$self->{_avaiable_projects} = $project_array; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
foreach my $project_id (@$project_array) { |
136
|
0
|
0
|
|
|
|
|
if ( $self->project_exists( $project_id, 1 ) ) { |
137
|
0
|
|
0
|
|
|
|
my $project = $self->{_projects}{$project_id} = $self->{_projects}{$project_id} || Webservice::OVH::Cloud::Project->_new_existing( wrapper => $api, id => $project_id, module => $self->{_module} ); |
138
|
0
|
|
|
|
|
|
push @$projects, $project; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return $projects; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 project |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns a single project by name |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * Parameter: $project_name - project name |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * Return: L<Webservice::OVH::Cloud::Project> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * Synopsis: my $project = $ovh->cloud->project("Name"); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub project { |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
0
|
1
|
|
my ( $self, $project_id ) = @_; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
if ( $self->project_exists($project_id) ) { |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
168
|
0
|
|
0
|
|
|
|
my $project = $self->{_projects}{$project_id} = $self->{_projects}{$project_id} || Webservice::OVH::Cloud::Project->_new_existing( wrapper => $api, id => $project_id, module => $self->{_module} ); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
return $project; |
171
|
|
|
|
|
|
|
} else { |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
carp "Service $project_id doesn't exists"; |
174
|
0
|
|
|
|
|
|
return undef; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 create_project |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Price information for projects and other running cloud services |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * Parameter: $description - (optional) description, $voucher - (optional) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * Return: Return: L<Webservice::OVH::Cloud::Project> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * Synopsis: my $order = $ovh->cloud->create_project; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=back |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub create_project { |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
199
|
0
|
|
|
|
|
|
my $body = {}; |
200
|
0
|
0
|
|
|
|
|
$body->{description} = $params{description} if exists $params{description}; |
201
|
0
|
0
|
|
|
|
|
$body->{voucher} = $params{voucher} if exists $params{voucher}; |
202
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'post', path => "/cloud/createProject", body => $body, noSignature => 0 ); |
203
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
my $order_id = $response->content->{orderId}; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
return $self->{_module}->me->order($order_id); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 price |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Price information for projects and other running cloud services |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=over |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * Parameter: $flavor_id - Cloud flavor id, $region - region |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * Return: HASH |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item * Synopsis: my $prices = $ovh->cloud->price; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub price { |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
0
|
1
|
|
my ( $self, $flavor_id, $region ) = @_; |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
my $filter = Webservice::OVH::Helper->construct_filter( "flavorId" => $flavor_id, "region" => $region ); |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
233
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'get', path => sprintf( "/cloud/price%s", $filter ), noSignature => 0 ); |
234
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
return $response->content; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |