/usr/share/perl5/VM/EC2/VPC.pm is in libvm-ec2-perl 1.23-1.
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 | package VM::EC2::VPC;
=head1 NAME
VM::EC2::VPC - Manage EC2 VPC
=head1 SYNOPSIS
use VM::EC2;
$ec2 - VM::EC2->new(...);
$vpc = $ec2->create_vpc('10.0.0.0/16') or die $ec2->error_str;
$subnet1 = $vpc->create_subnet('10.0.0.0/24') or die $vpc->error_str;
$gateway = $vpc->create_internet_gateway or die $vpc->error_str;
$routeTbl = $subnet1->create_route_table or die $vpc->error_str;
$routeTbl->create_route('0.0.0.0/0' => $gateway) or die $vpc->error_str;
=head1 DESCRIPTION
Please see L<VM::EC2::Generic> for methods shared by all VM::EC2
objects.
=head1 METHODS
These object methods are supported:
vpcId -- ID of the VPC
state -- Current state of the VPC (pending, available)
cidrBlock -- The CIDR block the VPC covers.
dhcpOptionsId -- The ID of the set of DHCP options you've associated
with the VPC, or "default".
instanceTenancy -- Either "dedicated" or "default"
In addition, this object supports the following convenience methods:
dhcp_options() -- Return a VM::EC2::VPC::DhcpOptions object.
current_state() -- Refresh the object and then return its state
current_status() -- Same as above (for module consistency)
set_dhcp_options($options) -- Associate the Dhcp option set with
this VPC (DhcpOptionsId string or VM::EC2::VPC::DhcpOptions object).
Use "default" or pass no arguments to assign no Dhcp options.
internet_gateways() -- Return the list of internet gateways attached to
this VPC as a list of VM::EC2::VPC::InternetGateway.
create_subnet($cidr_block)
-- Create a subnet with the indicated CIDR block and
return the VM::EC2::VPC::Subnet object.
create_internet_gateway()
-- Create an internet gateway and immediately attach
it to this VPC. If successful returns a
VM::EC2::VPC::InternetGateway object.
subnets() -- Return the list of subnets attached to this VPC
as a list of VM::EC2::VPC::Subnet.
route_tables() -- Return the list of route tables attached to this VPC
as a list of VM::EC2::VPC::RouteTable.
=head1 STRING OVERLOADING
When used in a string context, this object will be interpolated as the
VPC 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 base 'VM::EC2::Generic';
use Carp 'croak';
sub valid_fields {
my $self = shift;
return qw(vpcId state cidrBlock dhcpOptionsId instanceTenancy);
}
sub refresh {
my $self = shift;
my $i = shift;
local $self->aws->{raise_error} = 1;
($i) = $self->aws->describe_vpcs(-vpc_id=>$self->vpcId) unless $i;
%$self = %$i;
}
sub current_state {
my $self = shift;
$self->refresh;
$self->state;
}
sub current_status {shift->current_state(@_)}
sub primary_id { shift->vpcId }
sub dhcp_options {
my $self = shift;
return $self->aws->describe_dhcp_options($self->dhcpOptionsId);
}
sub set_dhcp_options {
my $self = shift;
my $options = shift || 'default';
return $self->aws->associate_dhcp_options($self => $options);
}
sub internet_gateways {
my $self = shift;
return $self->aws->describe_internet_gateways({'attachment.vpc-id'=>$self->vpcId});
}
sub subnets {
my $self = shift;
return $self->aws->describe_subnets({'vpc-id'=>$self->vpcId});
}
sub route_tables {
my $self = shift;
return $self->aws->describe_route_tables({'vpc-id'=>$self->vpcId});
}
sub attach_internet_gateway {
my $self = shift;
my $gw = shift;
return $self->aws->attach_internet_gateway($gw => $self->vpcId);
}
sub detach_internet_gateway {
my $self = shift;
my $gw = shift || ($self->internet_gateways)[0];
return $self->aws->detach_internet_gateway($gw=>$self->vpcId);
}
sub create_subnet {
my $self = shift;
my $cidr_block = shift or croak "usage: create_subnet(\$cidr_block)";
my $result = $self->aws->create_subnet(-vpc_id=>$self->vpcId,
-cidr_block=>$cidr_block);
$self->refresh if $result;
return $result;
}
sub delete_internet_gateway {
my $self = shift;
my $gateway = shift || ($self->internet_gateways)[0];
$gateway or return;
$self->detach_internet_gateway($gateway) or return;
return $self->aws->delete_internet_gateway($gateway);
}
sub create_internet_gateway {
my $self = shift;
my $gateway = $self->aws->create_internet_gateway() or return;
my $attach = $self->attach_internet_gateway($gateway);
unless ($attach) {
local $self->aws->{error}; # so that we get the error from the attach call
$self->aws->delete_internet_gateway($gateway);
return;
}
return $gateway;
}
1;
|