| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 36 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 36 | ▶ | use Carp qw{ carp croak }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 36 | our $VERSION = 0.48; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 36 | ▶ | use Webservice::OVH::Cloud::Project::Network::Private; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub _new { | ||||||||||||||||||
|
Subroutine
_new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | my ( $class, %params ) = @_; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | ▶ | die "Missing project" unless $params{project}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | ▶ | die "Missing module" unless $params{module}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | ▶ | die "Missing wrapper" unless $params{wrapper}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub project { | ||||||||||||||||||
|
Subroutine
project: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | 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 | 0 | ▶ | sub private_exists { | ||||||||||||||||||
|
Subroutine
private_exists: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | my ( $self, $network_id, $no_recheck ) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | ▶ | if ( !$no_recheck ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 0 | my $list = $response->content; | |||||||||||||||||||
| 120 | 0 | my @net_ids = grep { $_ = $_->{id} } @$list; | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | ▶ | return ( grep { $_ eq $network_id } @net_ids ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | my $list = $self->{_available_private}; | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | return ( grep { $_ eq $network_id } @$list ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub privates { | ||||||||||||||||||
|
Subroutine
privates: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 0 | 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 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | my $private_array = $response->content; | |||||||||||||||||||
| 156 | 0 | my $privates = []; | |||||||||||||||||||
| 157 | 0 | my @net_ids = grep { $_ = $_->{id} } @$private_array; | |||||||||||||||||||
| 158 | 0 | $self->{_available_private} = \@net_ids; | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | foreach my $network_id (@net_ids) { | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | ▶ | if ( $self->private_exists( $network_id, 1 ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 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 ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_private'}{$network_id} || 'Webservice::OVH::Cloud::Project::Network::Private'->_new_existing('wrapper', $api, 'module', $self->{'_module'}, 'project', $self->project, 'id', $network_id)
MC/DC0%0/2
$self->{'_private'}{$network_id} || 'Webservice::OVH::Cloud::Project::Network::Private'->_new_existing('wrapper', $api, 'module', $self->{'_module'}, 'project', $self->project, 'id', $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)
Truth table0%0/3
A || B
A= $self->{'_private'}{$network_id}B= '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 | 0 | ▶ | sub private { | ||||||||||||||||||
|
Subroutine
private: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 0 | my ( $self, $network_id ) = @_; | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 0 | ▶ | if ( $self->private_exists($network_id) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 194 | 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 ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_private'}{$network_id} || 'Webservice::OVH::Cloud::Project::Network::Private'->_new_existing('wrapper', $api, 'module', $self->{'_module'}, 'project', $self->project, 'id', $network_id)
MC/DC0%0/2
$self->{'_private'}{$network_id} || 'Webservice::OVH::Cloud::Project::Network::Private'->_new_existing('wrapper', $api, 'module', $self->{'_module'}, 'project', $self->project, 'id', $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)
Truth table0%0/3
A || B
A= $self->{'_private'}{$network_id}B= '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 | 0 | ▶ | sub create_private { | ||||||||||||||||||
|
Subroutine
create_private: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | 0 | 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 | 36 | 1; | |||||||||||||||||||