File Coverage

blib/lib/WebService/ProfitBricks/IpBlock.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4             # vim: set ts=3 sw=3 tw=0:
5             # vim: set expandtab:
6            
7             =head1 NAME
8              
9             WebService::ProfitBricks::IpBlock - Manage IP blocks
10              
11             =head1 DESCRIPTION
12              
13             Manage the IP blocks.
14              
15             =head1 SYNOPSIS
16              
17             my $block = IpBlock->new(blockSize => 2);
18             $block->save;
19              
20             =head1 METHODS
21              
22             =over 4
23              
24             =cut
25              
26             package WebService::ProfitBricks::IpBlock;
27              
28 1     1   1731 use strict;
  1         3  
  1         40  
29 1     1   5 use warnings;
  1         2  
  1         27  
30 1     1   7 use Data::Dumper;
  1         1  
  1         56  
31              
32 1     1   7 use WebService::ProfitBricks::Class;
  1         2  
  1         85  
33 1     1   7 use base qw(WebService::ProfitBricks);
  1         1  
  1         93  
34              
35             attrs qw/blockId
36             region
37             publicIps
38             blockSize/;
39              
40              
41             =item list
42              
43             =cut
44             does list => { through => "getAllPublicIpBlocks" };
45              
46             =item find($ip)
47              
48             Search the ip block to which $ip belongs to.
49              
50             =cut
51             does find => { code => sub {
52             my ($self, $search) = @_;
53             my @blocks = $self->list;
54            
55             for my $block (@blocks) {
56             for my $public_ip (@{ $block->publicIps }) {
57             if($public_ip->{ip} eq $search) {
58             return $block;
59             }
60             }
61             }
62             }};
63              
64             =item save
65              
66             Reserves the amount of IPs given to the constructor.
67              
68             =cut
69             sub save {
70             my ($self) = @_;
71             my $data = $self->connection->call("reservePublicIpBlock", blockSize => $self->blockSize, region => $self->region);
72             push(@{ $data->{publicIps} }, map { {ip => $_} } @{ $data->{ips} });
73             delete $data->{ips};
74             $self->set_data($data);
75             }
76              
77             =item reserve
78              
79             Alias for I.
80              
81             =cut
82             sub reserve {
83             my ($self) = @_;
84             $self->save;
85             }
86              
87             =item release
88              
89             Releases the current IP block.
90              
91             =cut
92             sub release {
93             my ($self) = @_;
94             my $data = $self->connection->call("releasePublicIpBlock", blockId => $self->blockId);
95             }
96              
97             =item removePublicIpFromNic($ip, $nicId)
98              
99             Remove the given public ip ($ip) from the nic represented by $nicId.
100              
101             =cut
102             sub removePublicIpFromNic {
103             my ($self, $ip, $nicId) = @_;
104             my $data = $self->connection->call("removePublicIpFromNic", ip => $ip, nicId => $nicId);
105             print Dumper($data);
106             }
107              
108             =back
109              
110             =cut
111              
112             1;