blib/lib/VM/EC2/REST/subnet.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran n/a Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 48 CC 1 SCAR 6.9
CC
1
Cov
0%
create_subnet
2.0
delete_subnet
2.0
describe_subnets
2.0
CRAP 2.0
1 package VM::EC2::REST::subnet;
2  
3 use strict;
4 use VM::EC2 ''; # important not to import anything!
5 package VM::EC2; # add methods to VM::EC2
6  
7 VM::EC2::Dispatch->register(
8 CreateSubnet => 'fetch_one,subnet,VM::EC2::VPC::Subnet',
9 DeleteSubnet => 'boolean',
10 DescribeSubnets => 'fetch_items,subnetSet,VM::EC2::VPC::Subnet',
11 ModifySubnetAttribute => 'boolean',
12 );
13  
14 =head1 NAME VM::EC2::REST::subnet
15  
16 =head1 SYNOPSIS
17  
18 use VM::EC2 ':vpc';
19  
20 =head1 METHODS
21  
22 These methods manage subnet objects and the routing among them. A VPC
23 may have a single subnet or many, and routing rules determine whether
24 the subnet has access to the internet ("public"), is entirely private,
25 or is connected to a customer gateway device to form a Virtual Private
26 Network (VPN) in which your home network's address space is extended
27 into the Amazon VPC.
28  
29 All instances in a VPC are located in one subnet or another. Subnets
30 may be public or private, and are organized in a star topology with a
31 logical router in the middle.
32  
33 Although all these methods can be called from VM::EC2 objects, many
34 are more conveniently called from the VM::EC2::VPC object family. This
35 allows for steps that typically follow each other, such as creating a
36 route table and associating it with a subnet, happen
37 automatically. For example, this series of calls creates a VPC with a
38 single subnet, creates an Internet gateway attached to the VPC,
39 associates a new route table with the subnet and then creates a
40 default route from the subnet to the Internet gateway.
41  
42 $vpc = $ec2->create_vpc('10.0.0.0/16') or die $ec2->error_str;
43 $subnet1 = $vpc->create_subnet('10.0.0.0/24') or die $vpc->error_str;
44 $gateway = $vpc->create_internet_gateway or die $vpc->error_str;
45 $routeTbl = $subnet->create_route_table or die $vpc->error_str;
46 $routeTbl->create_route('0.0.0.0/0' => $gateway) or die $vpc->error_str;
47  
48 Implemented:
49 CreateSubnet
50 DeleteSubnet
51 DescribeSubnets
52  
53 Unimplemented:
54 (none)
55  
56 =head2 $subnet = $ec2->create_subnet(-vpc_id=>$id,-cidr_block=>$block)
57  
58 This method creates a new subnet within the given VPC. Pass a VPC
59 object or VPC ID, and a CIDR block string. If successful, the method
60 will return a VM::EC2::VPC::Subnet object.
61  
62 Required arguments:
63  
64 -vpc_id A VPC ID or previously-created VM::EC2::VPC object.
65  
66 -cidr_block A CIDR block string in the form "xx.xx.xx.xx/xx". The
67 CIDR address must be within the CIDR block previously
68 assigned to the VPC, and must not overlap other subnets
69 in the VPC.
70  
71 Optional arguments:
72  
73 -availability_zone The availability zone for the instances launched
74 within this instance, either an availability zone
75 name, or a VM::EC2::AvailabilityZone object. If
76 this is not specified, then AWS chooses a zone for
77 you automatically.
78  
79 =cut
80  
81 sub create_subnet {
82 my $self = shift;
83 my %args = @_;
84 $args{-vpc_id} && $args{-cidr_block}
85 or croak "Usage: create_subnet(-vpc_id=>\$id,-cidr_block=>\$block)";
86 my @parm = map {$self->single_parm($_ => \%args)} qw(VpcId CidrBlock AvailabilityZone);
87 return $self->call('CreateSubnet',@parm);
88 }
89  
90 =head2 $success = $ec2->delete_subnet($subnet_id)
91  
92 =head2 $success = $ec2->delete_subnet(-subnet_id=>$id)
93  
94 This method deletes the indicated subnet. It may be called with a
95 single argument consisting of the subnet ID, or a named argument form
96 with the argument -subnet_id.
97  
98 =cut
99  
100 sub delete_subnet {
101 my $self = shift;
102 my %args = $self->args(-subnet_id=>@_);
103 my @parm = $self->single_parm(SubnetId=>\%args);
104 return $self->call('DeleteSubnet',@parm);
105 }
106  
107 =head2 @subnets = $ec2->describe_subnets(@subnet_ids)
108  
109 =head2 @subnets = $ec2->describe_subnets(\%filters)
110  
111 =head2 @subnets = $ec2->describe_subnets(-subnet_id=>$id,
112 -filter => \%filters)
113  
114 This method returns a list of VM::EC2::VPC::Subnet objects. Called
115 with no arguments, it returns all Subnets (not filtered by VPC
116 Id). Pass a list of subnet IDs or a filter hashref in order to
117 restrict the search.
118  
119 Optional arguments:
120  
121 -subnet_id Scalar or arrayref of subnet IDs.
122 -filter Hashref of filters.
123  
124 Available filters are described at
125 http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html
126  
127 =cut
128  
129 sub describe_subnets {
130 my $self = shift;
131 my %args = $self->args(-subnet_id => @_);
132 my @parm = $self->list_parm('SubnetId',\%args);
133 push @parm, $self->filter_parm(\%args);
134 return $self->call('DescribeSubnets',@parm);
135 }
136  
137 =head2 $success = $ec2->modify_subnet_attribute(-subnet_id => $sub_id, -map_public_ip_on_launch => $boolean)
138  
139 Modifies a subnet attribute.
140  
141 Required arguments:
142  
143 -subnet_id The ID of the subnet to modify.
144  
145 -map_public_ip_on_launch Modifies the public IP addressing behavior for the
146 subnet. Specify true to indicate that instances
147 launched into the specified subnet should be
148 assigned a public IP address. If set to true, the
149 instance receives a public IP address only if the
150 instance is launched with a single, new network
151 interface with the device index of 0.
152  
153 Returns true on success.
154  
155 =cut
156  
157 sub modify_subnet_attribute {
158 my $self = shift;
159 my %args = @_;
160 $args{-subnet_id} && $args{-map_public_ip_on_launch}
161 or croak "Usage: modify_subnet_attribute(-subnet_id=>\$id,-map_public_ip_on_launch=>\$boolean)";
162 my @parm = $self->single_parm(SubnetId=>\%args);
163 push @parm, $self->boolean_value_parm(MapPublicIpOnLaunch=>\%args);
164 return $self->call('ModifySubnetAttribute',@parm);
165 }
166  
167 =head1 SEE ALSO
168  
169 L<VM::EC2>
170  
171 =head1 AUTHOR
172  
173 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
174  
175 Copyright (c) 2011 Ontario Institute for Cancer Research
176  
177 This package and its accompanying libraries is free software; you can
178 redistribute it and/or modify it under the terms of the GPL (either
179 version 1, or at your option, any later version) or the Artistic
180 License 2.0. Refer to LICENSE for the full license text. In addition,
181 please see DISCLAIMER.txt for disclaimers of warranty.
182  
183 =cut
184  
185  
186 1;