/usr/share/perl5/VM/EC2/VPC/Subnet.pm is in libvm-ec2-perl 1.28-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | package VM::EC2::VPC::Subnet;
=head1 NAME
VM::EC2::VPC::Subnet -- A VPC subnet
=head1 SYNOPSIS
use VM::EC2;
my $ec2 = VM::EC2->new(...);
my $vpc = $ec2->create_vpc('10.0.0.0/16');
my $subnet = $vpc->create_subnet('10.0.0.0/24') or die $vpc->error_str;
@subnets = $ec2->describe_subnets;
for my $sn (@subnets) {
print $sn->subnetId,"\n",
$sn->state,"\n",
$sn->vpcId,"\n",
$sn->cidrBlock,"\n",
$sn->availableIpAddressCount,"\n",
$sn->availabilityZone,"\n";
}
=head1 DESCRIPTION
This object supports the EC2 Virtual Private Cloud subnet
interface. Please see L<VM::EC2::Generic> for methods shared by all
VM::EC2 objects.
=head1 METHODS
These object methods are supported:
subnetId -- the ID of the subnet
state -- The current state of the subnet, either "pending" or "available"
vpcId -- The ID of the VPC the subnet is in.
cidrBlock -- The CIDR block assigned to the subnet.
availableIpAddressCount -- The number of unused IP addresses in the subnet.
availableZone -- This subnet's availability zone.
defaultForAz -- Indicates if this is the default subnet for the Availability Zone
mapPublicIpOnLaunch -- Indicates if instances launched in this subnet automatically receive a
public IP address
This class supports the VM::EC2 tagging interface. See
L<VM::EC2::Generic> for information.
In addition, this object supports the following convenience methods:
vpc() -- Return the associated VM::EC2::VPC object.
zone() -- Return the associated VM::EC2::AvailabilityZone object.
refresh() -- Refreshes the object from its current state in EC2.
current_state() -- Refreshes the object and returns its current state.
create_route_table() -- Create a new route table, associates it with this subnet, and
returns the corresponding VM::EC2::VPC::RouteTable
object.
associate_route_table($table)
-- Associates a route table with this subnet, returning true if
sucessful.
disassociate_route_table($table)
-- Removes the association of a route table with this subnet. Produces
a fatal error if $table is not associated with the subnet. Returns true
on success.
associate_network_acl($network_acl_id)
-- Associates a network ACL with this subnet, returning the new
association ID on success.
disassociate_network_acl()
-- Removes the association of a network ACL with this subnet. The subnet
will then be associated with the default network ACL. Returns the
the association ID.
=head1 STRING OVERLOADING
When used in a string context, this object will be interpolated as the
subnet ID.
=head1 SEE ALSO
L<VM::EC2>
L<VM::EC2::Generic>
=head1 AUTHOR
Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
Copyright (c) 2012 Ontario Institute for Cancer Research
This package and its accompanying libraries is free software; you can
redistribute it and/or modify it under the terms of the GPL (either
version 1, or at your option, any later version) or the Artistic
License 2.0. Refer to LICENSE for the full license text. In addition,
please see DISCLAIMER.txt for disclaimers of warranty.
=cut
use strict;
use Carp 'croak';
use base 'VM::EC2::Generic';
sub valid_fields {
my $self = shift;
return qw(subnetId state vpcId cidrBlock availableIpAddressCount
availabilityZone defaultForAz mapPublicIpOnLaunch);
}
sub primary_id { shift->subnetId }
sub vpc {
my $self = shift;
return $self->aws->describe_vpcs($self->vpcId);
}
sub zone {
my $self = shift;
return $self->aws->describe_availability_zones($self->availabilityZone);
}
sub refresh {
my $self = shift;
my $i = shift;
local $self->aws->{raise_error} = 1;
($i) = $self->aws->describe_subnets($self->subnetId) unless $i;
%$self = %$i if $i;
return defined $i;
}
sub current_state {
my $self = shift;
$self->refresh;
$self->state;
}
sub associate_route_table {
my $self = shift;
my $rt = shift or croak "usage: associate_route_table(\$route_table_id)";
return $self->aws->associate_route_table(-subnet_id => $self->subnetId,
-route_table_id => $rt);
}
sub disassociate_route_table {
my $self = shift;
my $rt = shift or croak "usage: disassociate_route_table(\$route_table_id)";
$rt = $self->aws->describe_route_tables($rt) unless ref $rt;
my ($association) = grep {$_->subnetId eq $self->subnetId} $rt->associations;
$association or croak "$rt is not associated with this subnet";
return $self->aws->disassociate_route_table($association);
}
sub create_route_table {
my $self = shift;
my $vpc = $self->vpcId;
my $rt = $self->aws->create_route_table($vpc) or return;
$self->associate_route_table($rt->routeTableId) or return;
return $rt
}
sub disassociate_network_acl {
my $self = shift;
my $acl = $self->aws->describe_network_acls(-filter=>{ 'association.subnet-id' => $self->subnetId});
if ($acl->default) {
print "disassociate_network_acl(): Cannot disassociate subnet from default ACL";
return;
}
my $default_acl = $self->aws->describe_network_acls(-filter=>{ 'default' => 'true', 'vpc-id' => $self->vpcId})
or croak "disassociate_network_acl(): Cannot determine default ACL";
return $self->associate_network_acl($default_acl->networkAclId);
}
sub associate_network_acl {
my $self = shift;
my $network_acl_id = shift or croak "usage: associate_network_acl(\$network_acl_id)";
my $acl = $self->aws->describe_network_acls(-filter=>{ 'association.subnet-id' => $self->subnetId})
or croak "associate_network_acl(): Cannot determine current ACL";
my ($association) = grep { $_->subnetId eq $self->subnetId } $acl->associations;
my $association_id = $association->networkAclAssociationId;
return $self->aws->replace_network_acl_association(-association_id=>$association_id,-network_acl_id=>$network_acl_id);
}
sub defaultForAz {
my $self = shift;
my $default = $self->SUPER::defaultForAz;
return $default eq 'true';
}
sub mapPublicIpOnLaunch {
my $self = shift;
my $map_ip = $self->SUPER::mapPublicIpOnLaunch;
return $map_ip eq 'true';
}
1;
|