File Coverage

lib/Webservice/OVH/Cloud/Project/IP.pm
Criterion Covered Total %
statement 12 53 22.6
branch 0 20 0.0
condition 0 6 0.0
subroutine 4 9 44.4
pod 4 4 100.0
total 20 92 21.7


line stmt bran cond sub pod time code
1              
2             =encoding utf-8
3              
4             =head1 NAME
5              
6             Webservice::OVH::Cloud::Project::IP;
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 failover ips
27              
28             =head1 METHODS
29              
30             =cut
31              
32             use strict;
33 36     36   219 use warnings;
  36         75  
  36         880  
34 36     36   155 use Carp qw{ carp croak };
  36         70  
  36         820  
35 36     36   159  
  36         69  
  36         2024  
36             our $VERSION = 0.47;
37              
38             use Webservice::OVH::Cloud::Project::IP::Failover;
39 36     36   13868  
  36         100  
  36         18229  
40             =head2 _new_existing
41              
42             Internal Method to create the 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::IP>
50              
51             =item * Synopsis: Webservice::OVH::Cloud::Project::IP->_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 { module => $params{module}, _api_wrapper => $params{wrapper}, _project => $params{project}, _available_failovers => [], _failovers => {} }, $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->ip->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 failover_exists
90              
91             Returns 1 if failover is available for the connected account, 0 if not.
92              
93             =over
94              
95             =item * Parameter: $failover_id - api id, $no_recheck - (optional)only for internal usage
96              
97             =item * Return: VALUE
98              
99             =item * Synopsis: print "failover exists" if $project->ip->failover_exists(1234);
100              
101             =back
102              
103             =cut
104              
105              
106             my ( $self, $failover_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/ip/failover", noSignature => 0 );
113             croak $response->error if $response->error;
114 0            
115 0           my $list = $response->content;
116 0            
117 0 0         return ( grep { $_ eq $failover_id } @$list ) ? 1 : 0;
118              
119 0           } else {
120              
121 0 0         my $list = $self->{_avaiable_projects};
  0            
122              
123             return ( grep { $_ eq $failover_id } @$list ) ? 1 : 0;
124             }
125 0           }
126              
127 0 0         =head2 failovers
  0            
128              
129             Produces an array of all available failovers that are connected to the project.
130              
131             =over
132              
133             =item * Return: ARRAY
134              
135             =item * Synopsis: my $ips = $project->ip->failovers;
136              
137             =back
138              
139             =cut
140              
141              
142             my ($self) = @_;
143              
144             my $api = $self->{_api_wrapper};
145             my $project_id = $self->project->id;
146             my $response = $api->rawCall( method => 'get', path => "/cloud/project/$project_id/ip/failover", noSignature => 0 );
147 0     0 1   croak $response->error if $response->error;
148              
149 0           my $failover_array = $response->content;
150 0           my $failovers = [];
151 0           $self->{_available_failovers} = $failover_array;
152 0 0          
153             foreach my $failover_hash (@$failover_array) {
154 0            
155 0           my $failover_id = $failover_hash->{id};
156 0           if ( $self->failover_exists( $failover_id, 1 ) ) {
157             my $failover = $self->{_failovers}{$failover_id} = $self->{_failovers}{$failover_id} || Webservice::OVH::Cloud::Project::IP::Failover->_new( wrapper => $api, project => $self->project, id => $failover_id, module => $self->{_module} );
158 0           push @$failovers, $failover;
159             }
160 0           }
161 0 0          
162 0   0       return $failovers;
163 0           }
164              
165             =head2 failover
166              
167 0           Returns a single failover by id
168              
169             =over
170              
171             =item * Parameter: $failover_id - api id
172              
173             =item * Return: L<Webservice::OVH::Cloud::Project::IP::Failover>
174              
175             =item * Synopsis: my $failover = $project->ip->failover(1234);
176              
177             =back
178              
179             =cut
180              
181              
182             my ( $self, $failover_id ) = @_;
183              
184             if ( $self->failover_exists($failover_id) ) {
185              
186             my $api = $self->{_api_wrapper};
187             my $failover = $self->{_failovers}{$failover_id} = $self->{_failovers}{$failover_id} || Webservice::OVH::Cloud::Project::IP::Failover->_new( wrapper => $api, project => $self->project, id => $failover_id, module => $self->{_module} );
188 0     0 1    
189             return $failover;
190 0 0         } else {
191              
192 0           carp "Failover $failover_id doesn't exists";
193 0   0       return undef;
194             }
195 0           }
196              
197             1;