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