line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Webservice::OVH::Cloud::Project::Network; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=encoding utf-8 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Webservice::OVH::Cloud::Project::Network |
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
|
|
|
|
|
|
|
my $example_project = $projects->[0]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $networks = $project->network->privates; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
foreach my $network (@$networks) { |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
print @$networks->status; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Bridge Object to private and in future public networks. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
36
|
|
|
36
|
|
273
|
use strict; |
|
36
|
|
|
|
|
93
|
|
|
36
|
|
|
|
|
1250
|
|
34
|
36
|
|
|
36
|
|
204
|
use warnings; |
|
36
|
|
|
|
|
87
|
|
|
36
|
|
|
|
|
1164
|
|
35
|
36
|
|
|
36
|
|
207
|
use Carp qw{ carp croak }; |
|
36
|
|
|
|
|
107
|
|
|
36
|
|
|
|
|
2918
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our $VERSION = 0.46; |
38
|
|
|
|
|
|
|
|
39
|
36
|
|
|
36
|
|
19277
|
use Webservice::OVH::Cloud::Project::Network::Private; |
|
36
|
|
|
|
|
111
|
|
|
36
|
|
|
|
|
25917
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 _new_existing |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Internal Method to create the Network object. |
44
|
|
|
|
|
|
|
This method is not ment to be called directly. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * Parameter: %params - key => value |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item * Return: L<Webservice::OVH::Cloud::Project::SSH> |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * Synopsis: Webservice::OVH::Cloud::Project::SSH->_new(wrapper => $ovh_api_wrapper, project => $project, module => $module ); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=back |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _new { |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
|
|
my ( $class, %params ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
die "Missing project" unless $params{project}; |
63
|
0
|
0
|
|
|
|
|
die "Missing module" unless $params{module}; |
64
|
0
|
0
|
|
|
|
|
die "Missing wrapper" unless $params{wrapper}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $self = bless { _project => $params{project}, _module => $params{module}, _api_wrapper => $params{wrapper}, _private => {}, _available_private => [] }, $class; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 project |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Shorthand to call $self->project directly for internal usage. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * Return: L<Webservice::OVH::Cloud::Project> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * Synopsis: my $project = $project->network->project; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=back |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub project { |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $self->{_project}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 private_exists |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns 1 if object is available for the connected account, 0 if not. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * Parameter: $network_id - api id, $no_recheck - (optional)only for internal usage |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * Return: VALUE |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item * Synopsis: print "network exists" if $project->network->private_exists($id); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub private_exists { |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
0
|
1
|
|
my ( $self, $network_id, $no_recheck ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ( !$no_recheck ) { |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
115
|
0
|
|
|
|
|
|
my $project_id = $self->project->id; |
116
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'get', path => "/cloud/project/$project_id/network/private", noSignature => 0 ); |
117
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $list = $response->content; |
120
|
0
|
|
|
|
|
|
my @net_ids = grep { $_ = $_->{id} } @$list; |
|
0
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
return ( grep { $_ eq $network_id } @net_ids ) ? 1 : 0; |
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} else { |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $list = $self->{_available_private}; |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
return ( grep { $_ eq $network_id } @$list ) ? 1 : 0; |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 privates |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Produces an array of all available private networks that are connected to the project. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * Return: ARRAY |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * Synopsis: my $private_networks = $project->privates; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=back |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub privates { |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
0
|
1
|
|
my ( $self, %filter ) = @_; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
151
|
0
|
|
|
|
|
|
my $project_id = $self->project->id; |
152
|
0
|
|
|
|
|
|
my $response = $api->rawCall( method => 'get', path => "/cloud/project/$project_id/network/private", noSignature => 0 ); |
153
|
0
|
0
|
|
|
|
|
croak $response->error if $response->error; |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my $private_array = $response->content; |
156
|
0
|
|
|
|
|
|
my $privates = []; |
157
|
0
|
|
|
|
|
|
my @net_ids = grep { $_ = $_->{id} } @$private_array; |
|
0
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$self->{_available_private} = \@net_ids; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
foreach my $network_id (@net_ids) { |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
|
if ( $self->private_exists( $network_id, 1 ) ) { |
163
|
0
|
|
0
|
|
|
|
my $private = $self->{_private}{$network_id} = $self->{_private}{$network_id} || Webservice::OVH::Cloud::Project::Network::Private->_new_existing( wrapper => $api, module => $self->{_module}, project => $self->project, id => $network_id ); |
164
|
0
|
|
|
|
|
|
push @$privates, $private; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return $privates; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 private |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns a single object by id |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * Parameter: $network_id - api id |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * Return: L<Webservice::OVH::Cloud::Project::Network::Private> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * Synopsis: my $private_network = $project->private($id); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub private { |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
0
|
1
|
|
my ( $self, $network_id ) = @_; |
190
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
if ( $self->private_exists($network_id) ) { |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $api = $self->{_api_wrapper}; |
194
|
0
|
|
0
|
|
|
|
my $private = $self->{_private}{$network_id} = $self->{_private}{$network_id} || Webservice::OVH::Cloud::Project::Network::Private->_new_existing( wrapper => $api, module => $self->{_module}, project => $self->project, id => $network_id ); |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
return $private; |
197
|
|
|
|
|
|
|
} else { |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
carp "Network $network_id doesn't exists"; |
200
|
0
|
|
|
|
|
|
return undef; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 create_private |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Creates a new network. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * Parameter: %params - key => value (required) vlan_id name (optional) region |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item * Return: <Webservice::OVH::Cloud::Project::Network::Private> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * Synopsis: my $private_network = $project->create_private( vlan_id => 6, name => 'Test Network' ); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=back |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub create_private { |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return Webservice::OVH::Cloud::Project::Network::Private->_new( module => $self->{_module}, wrapper => $self->{_api_wrapper}, project => $self->project, %params ); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |