« Webservice/OVH/Email/Domain/Domain.pm
↑ Summary
Webservice/OVH/Email/Domain/Domain/Task/Redirection.pm »
| 1 | package Webservice::OVH::Cloud::Project::Instance::Group; | ||||||||||
| 2 | |||||||||||
| 3 | =encoding utf-8 | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Webservice::OVH::Cloud::Project::Instance::Group | ||||||||||
| 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 $groups = $project->instance->groups; | ||||||||||
| 19 | |||||||||||
| 20 | foreach my $group (@$groups) { | ||||||||||
| 21 | |||||||||||
| 22 | print $group->name; | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||
| 26 | |||||||||||
| 27 | Provides Instance object methods and id less methods for groups. | ||||||||||
| 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 | =head2 _new_existing | ||||||||||
| 40 | |||||||||||
| 41 | Internal Method to create the Network object. | ||||||||||
| 42 | This method is not ment to be called directly. | ||||||||||
| 43 | This method can be reached by using the bridge object instance in project. | ||||||||||
| 44 | |||||||||||
| 45 | =over | ||||||||||
| 46 | |||||||||||
| 47 | =item * Parameter: %params - key => value | ||||||||||
| 48 | |||||||||||
| 49 | =item * Return: L<Webservice::OVH::Cloud::Project::Instance::Group> | ||||||||||
| 50 | |||||||||||
| 51 | =item * Synopsis: Webservice::OVH::Cloud::Project::Instance::Group->_new(wrapper => $ovh_api_wrapper, project => $project, module => $module, id => $id ); | ||||||||||
| 52 | |||||||||||
| 53 | =back | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub _new_existing { | ||||||||
|
Subroutine
_new_existing: not called CC=7 SCAR=40.3
| |||||||||||
| 58 | |||||||||||
| 59 | 0 | my ( $class, %params ) = @_; | |||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | die "Missing module" unless $params{module}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | die "Missing wrapper" unless $params{wrapper}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | ▶ | die "Missing id" unless $params{id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | ▶ | die "Missing project" unless $params{project}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 0 | my $group_id = $params{id}; | |||||||||
| 67 | 0 | my $api_wrapper = $params{wrapper}; | |||||||||
| 68 | 0 | my $module = $params{module}; | |||||||||
| 69 | 0 | my $project = $params{project}; | |||||||||
| 70 | 0 | my $project_id = $project->id; | |||||||||
| 71 | |||||||||||
| 72 | 0 | my $response = $api_wrapper->rawCall( method => 'get', path => "/cloud/project/$project_id/instance/group/$group_id", noSignature => 0 ); | |||||||||
| 73 | 0 | ▶ | carp $response->error if $response->error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | if ( !$response->error ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | 0 | my $porperties = $response->content; | |||||||||
| 78 | 0 | my $self = bless { _module => $module, _valid => 1, _api_wrapper => $api_wrapper, _id => $group_id, _properties => $porperties, _project => $project }, $class; | |||||||||
| 79 | |||||||||||
| 80 | 0 | return $self; | |||||||||
| 81 | } else { | ||||||||||
| 82 | |||||||||||
| 83 | 0 | return undef; | |||||||||
| 84 | } | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | =head2 _new | ||||||||||
| 88 | |||||||||||
| 89 | Internal Method to create the Network object. | ||||||||||
| 90 | This method is not ment to be called directly. | ||||||||||
| 91 | This method can be reached by using the bridge object instance in project. | ||||||||||
| 92 | |||||||||||
| 93 | =over | ||||||||||
| 94 | |||||||||||
| 95 | =item * Parameter: %params - key => value | ||||||||||
| 96 | |||||||||||
| 97 | =item * Return: L<Webservice::OVH::Cloud::Project::Instance::Group> | ||||||||||
| 98 | |||||||||||
| 99 | =item * Synopsis: Webservice::OVH::Cloud::Project::Instance::Group->_new(wrapper => $ovh_api_wrapper, project => $project, module => $module ); | ||||||||||
| 100 | |||||||||||
| 101 | =back | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | sub _new { | ||||||||
|
Subroutine
_new: not called CC=6 SCAR=37.4
| |||||||||||
| 106 | |||||||||||
| 107 | 0 | my ( $class, %params ) = @_; | |||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | die "Missing module" unless $params{module}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | ▶ | die "Missing wrapper" unless $params{wrapper}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | ▶ | die "Missing project" unless $params{project}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | |||||||||||
| 113 | 0 | my $api_wrapper = $params{wrapper}; | |||||||||
| 114 | 0 | my $module = $params{module}; | |||||||||
| 115 | 0 | my $project = $params{project}; | |||||||||
| 116 | 0 | my $project_id = $project->id; | |||||||||
| 117 | |||||||||||
| 118 | 0 | my @keys_needed = qw{ region name }; | |||||||||
| 119 | 0 | ▶ | if ( my @missing_parameters = grep { not $params{$_} } @keys_needed ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 120 | |||||||||||
| 121 | 0 | croak "Missing parameter: @missing_parameters"; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 0 | my $body = { region => $params{region}, name => $params{name} }; | |||||||||
| 125 | 0 | my $response = $api_wrapper->rawCall( method => 'post', path => "/cloud/project/$project_id/instance/group", body => $body, noSignature => 0 ); | |||||||||
| 126 | 0 | ▶ | croak $response->error if $response->error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | |||||||||||
| 128 | 0 | my $group_id = $response->content->{id}; | |||||||||
| 129 | 0 | my $properties = $response->content; | |||||||||
| 130 | |||||||||||
| 131 | 0 | my $self = bless { _module => $module, _valid => 1, _api_wrapper => $api_wrapper, _id => $group_id, _properties => $properties, _project => $project }, $class; | |||||||||
| 132 | |||||||||||
| 133 | 0 | return $self; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | =head2 project | ||||||||||
| 137 | |||||||||||
| 138 | Root Project. | ||||||||||
| 139 | |||||||||||
| 140 | =over | ||||||||||
| 141 | |||||||||||
| 142 | =item * Return: L<Webservice::OVH::Cloud::Project> | ||||||||||
| 143 | |||||||||||
| 144 | =item * Synopsis: my $project = $group->project; | ||||||||||
| 145 | |||||||||||
| 146 | =back | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||
| 149 | |||||||||||
| 150 | 0 | ▶ | sub project { | ||||||||
|
Subroutine
project: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 151 | |||||||||||
| 152 | 0 | my ($self) = @_; | |||||||||
| 153 | |||||||||||
| 154 | 0 | return $self->{_project}; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | =head2 is_valid | ||||||||||
| 158 | |||||||||||
| 159 | When this object is deleted on the api side, this method returns 0. | ||||||||||
| 160 | |||||||||||
| 161 | =over | ||||||||||
| 162 | |||||||||||
| 163 | =item * Return: VALUE | ||||||||||
| 164 | |||||||||||
| 165 | =item * Synopsis: print "Valid" if $group->is_valid; | ||||||||||
| 166 | |||||||||||
| 167 | =back | ||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||
| 170 | |||||||||||
| 171 | 0 | ▶ | sub is_valid { | ||||||||
|
Subroutine
is_valid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 172 | |||||||||||
| 173 | 0 | my ($self) = @_; | |||||||||
| 174 | |||||||||||
| 175 | 0 | return $self->{_valid}; | |||||||||
| 176 | } | ||||||||||
| 177 | |||||||||||
| 178 | =head2 _is_valid | ||||||||||
| 179 | |||||||||||
| 180 | Internal method to check validity. | ||||||||||
| 181 | Difference is that this method carps an error. | ||||||||||
| 182 | |||||||||||
| 183 | =over | ||||||||||
| 184 | |||||||||||
| 185 | =item * Return: VALUE | ||||||||||
| 186 | |||||||||||
| 187 | =item * Synopsis: $group->_is_valid; | ||||||||||
| 188 | |||||||||||
| 189 | =back | ||||||||||
| 190 | |||||||||||
| 191 | =cut | ||||||||||
| 192 | |||||||||||
| 193 | 0 | ▶ | sub _is_valid { | ||||||||
|
Subroutine
_is_valid: not called CC=2 SCAR=17.9
| |||||||||||
| 194 | |||||||||||
| 195 | 0 | my ($self) = @_; | |||||||||
| 196 | |||||||||||
| 197 | 0 | ▶ | carp "Group is not valid anymore" unless $self->is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 198 | 0 | return $self->is_valid; | |||||||||
| 199 | } | ||||||||||
| 200 | |||||||||||
| 201 | =head2 id | ||||||||||
| 202 | |||||||||||
| 203 | Returns the api id | ||||||||||
| 204 | |||||||||||
| 205 | =over | ||||||||||
| 206 | |||||||||||
| 207 | =item * Return: VALUE | ||||||||||
| 208 | |||||||||||
| 209 | =item * Synopsis: my $id = $group->id; | ||||||||||
| 210 | |||||||||||
| 211 | =back | ||||||||||
| 212 | |||||||||||
| 213 | =cut | ||||||||||
| 214 | |||||||||||
| 215 | 0 | ▶ | sub id { | ||||||||
|
Subroutine
id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 216 | |||||||||||
| 217 | 0 | my ($self) = @_; | |||||||||
| 218 | |||||||||||
| 219 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 220 | |||||||||||
| 221 | 0 | return $self->{_id}; | |||||||||
| 222 | } | ||||||||||
| 223 | |||||||||||
| 224 | =head2 properties | ||||||||||
| 225 | |||||||||||
| 226 | Returns the raw properties as a hash. | ||||||||||
| 227 | This is the original return value of the web-api. | ||||||||||
| 228 | |||||||||||
| 229 | =over | ||||||||||
| 230 | |||||||||||
| 231 | =item * Return: HASH | ||||||||||
| 232 | |||||||||||
| 233 | =item * Synopsis: my $properties = $group->properties; | ||||||||||
| 234 | |||||||||||
| 235 | =back | ||||||||||
| 236 | |||||||||||
| 237 | =cut | ||||||||||
| 238 | |||||||||||
| 239 | 0 | ▶ | sub properties { | ||||||||
|
Subroutine
properties: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 240 | |||||||||||
| 241 | 0 | my ($self) = @_; | |||||||||
| 242 | |||||||||||
| 243 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 244 | |||||||||||
| 245 | 0 | my $api = $self->{_api_wrapper}; | |||||||||
| 246 | 0 | my $project_id = $self->project->id; | |||||||||
| 247 | 0 | my $group_id = $self->id; | |||||||||
| 248 | 0 | my $response = $api->rawCall( method => 'get', path => "/cloud/project/$project_id/instance/group/$group_id", noSignature => 0 ); | |||||||||
| 249 | 0 | ▶ | croak $response->error if $response->error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 250 | 0 | $self->{_properties} = $response->content; | |||||||||
| 251 | 0 | return $self->{_properties}; | |||||||||
| 252 | } | ||||||||||
| 253 | |||||||||||
| 254 | =head2 name | ||||||||||
| 255 | |||||||||||
| 256 | Exposed property value. | ||||||||||
| 257 | |||||||||||
| 258 | =over | ||||||||||
| 259 | |||||||||||
| 260 | =item * Return: VALUE | ||||||||||
| 261 | |||||||||||
| 262 | =item * Synopsis: my $name = $group->name; | ||||||||||
| 263 | |||||||||||
| 264 | =back | ||||||||||
| 265 | |||||||||||
| 266 | =cut | ||||||||||
| 267 | |||||||||||
| 268 | 0 | ▶ | sub name { | ||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 269 | |||||||||||
| 270 | 0 | my ($self) = @_; | |||||||||
| 271 | |||||||||||
| 272 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 273 | |||||||||||
| 274 | 0 | return $self->{_properties}->{name}; | |||||||||
| 275 | } | ||||||||||
| 276 | |||||||||||
| 277 | =head2 region | ||||||||||
| 278 | |||||||||||
| 279 | Exposed property value. | ||||||||||
| 280 | |||||||||||
| 281 | =over | ||||||||||
| 282 | |||||||||||
| 283 | =item * Return: VALUE | ||||||||||
| 284 | |||||||||||
| 285 | =item * Synopsis: my $region = $group->region; | ||||||||||
| 286 | |||||||||||
| 287 | =back | ||||||||||
| 288 | |||||||||||
| 289 | =cut | ||||||||||
| 290 | |||||||||||
| 291 | 0 | ▶ | sub region { | ||||||||
|
Subroutine
region: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 292 | |||||||||||
| 293 | 0 | my ($self) = @_; | |||||||||
| 294 | |||||||||||
| 295 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 296 | |||||||||||
| 297 | 0 | return $self->{_properties}->{region}; | |||||||||
| 298 | } | ||||||||||
| 299 | |||||||||||
| 300 | =head2 instance_ids | ||||||||||
| 301 | |||||||||||
| 302 | Exposed property value. | ||||||||||
| 303 | |||||||||||
| 304 | =over | ||||||||||
| 305 | |||||||||||
| 306 | =item * Return: ARRAY | ||||||||||
| 307 | |||||||||||
| 308 | =item * Synopsis: my $instance_ids = $group->instance_ids; | ||||||||||
| 309 | |||||||||||
| 310 | =back | ||||||||||
| 311 | |||||||||||
| 312 | =cut | ||||||||||
| 313 | |||||||||||
| 314 | 0 | ▶ | sub instance_ids { | ||||||||
|
Subroutine
instance_ids: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 315 | |||||||||||
| 316 | 0 | my ($self) = @_; | |||||||||
| 317 | |||||||||||
| 318 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 319 | |||||||||||
| 320 | 0 | return $self->{_properties}->{instance_ids}; | |||||||||
| 321 | } | ||||||||||
| 322 | |||||||||||
| 323 | =head2 affinity | ||||||||||
| 324 | |||||||||||
| 325 | Exposed property value. | ||||||||||
| 326 | |||||||||||
| 327 | =over | ||||||||||
| 328 | |||||||||||
| 329 | =item * Return: ARRAY | ||||||||||
| 330 | |||||||||||
| 331 | =item * Synopsis: my $affinity = $group->affinity; | ||||||||||
| 332 | |||||||||||
| 333 | =back | ||||||||||
| 334 | |||||||||||
| 335 | =cut | ||||||||||
| 336 | |||||||||||
| 337 | 0 | ▶ | sub affinity { | ||||||||
|
Subroutine
affinity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 338 | |||||||||||
| 339 | 0 | my ($self) = @_; | |||||||||
| 340 | |||||||||||
| 341 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 342 | |||||||||||
| 343 | 0 | return $self->{_properties}->{Affinity}; | |||||||||
| 344 | } | ||||||||||
| 345 | |||||||||||
| 346 | =head2 delete | ||||||||||
| 347 | |||||||||||
| 348 | Deletes the object api sided and sets it invalid. | ||||||||||
| 349 | |||||||||||
| 350 | =over | ||||||||||
| 351 | |||||||||||
| 352 | =item * Synopsis: $group->delete; | ||||||||||
| 353 | |||||||||||
| 354 | =back | ||||||||||
| 355 | |||||||||||
| 356 | =cut | ||||||||||
| 357 | |||||||||||
| 358 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 359 | |||||||||||
| 360 | 0 | my ($self) = @_; | |||||||||
| 361 | |||||||||||
| 362 | 0 | ▶ | return unless $self->_is_valid; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 363 | |||||||||||
| 364 | 0 | my $api = $self->{_api_wrapper}; | |||||||||
| 365 | 0 | my $project_id = $self->project->id; | |||||||||
| 366 | 0 | my $group_id = $self->id; | |||||||||
| 367 | |||||||||||
| 368 | 0 | my $response = $api->rawCall( method => 'delete', path => "/cloud/project/$project_id/instance/group/$group_id", noSignature => 0 ); | |||||||||
| 369 | 0 | ▶ | croak $response->error if $response->error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 370 | |||||||||||
| 371 | 0 | $self->{_valid} = 0; | |||||||||
| 372 | } | ||||||||||
| 373 | |||||||||||
| 374 | 36 | 1; | |||||||||