« blib/lib/VM/EC2/VPC/PeeringConnection/VpcInfo.pm
↑ Summary
blib/lib/VM/EC2/VPC/RouteTable/Association.pm »
| 1 | package VM::EC2::VPC::Route; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::VPC::Route -- An entry in a VPC routing table | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | my $ec2 = VM::EC2->new(...); | ||
| 11 | my $table = $ec2->describe_route_tables('rtb-123456'); | ||
| 12 | my @routes = $table->routes; | ||
| 13 | |||
| 14 | foreach my $r (@routes) { | ||
| 15 | print $r->destinationCidrBlock,"\n", | ||
| 16 | $r->gatewayId,"\n", | ||
| 17 | $r->instanceId,"\n", | ||
| 18 | $r->instanceOwnerId,"\n", | ||
| 19 | $r->networkInterfaceId,"\n", | ||
| 20 | $r->state,"\n" | ||
| 21 | my $target = $r->target,"\n"; # an instance, gateway or network interface object | ||
| 22 | } | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | This object supports the EC2 Virtual Private Cloud route interface, | ||
| 27 | and is used to control the routing of packets within and between | ||
| 28 | subnets. Each route has a destination CIDR address block, and a target | ||
| 29 | gateway, instance or network interface that will receive packets whose | ||
| 30 | destination matches the block. Routes are matched in order from the | ||
| 31 | most specific to the most general. | ||
| 32 | |||
| 33 | =head1 METHODS | ||
| 34 | |||
| 35 | These object methods are supported: | ||
| 36 | |||
| 37 | destinationCidrBlock -- The CIDR address block used in the destination | ||
| 38 | match. For example 0.0.0/0 for all packets. | ||
| 39 | gatewayId -- The ID of an internet gateway attached to your | ||
| 40 | VPC. | ||
| 41 | instanceId -- The ID of an instance in your VPC to act as the | ||
| 42 | destination for packets. Typically this will be | ||
| 43 | a NAT instance. | ||
| 44 | instanceOwnerId -- The account number of the owner of the instance. | ||
| 45 | networkInterfaceId -- The ID of an Elastic Network Interface to receive | ||
| 46 | packets matching the destination | ||
| 47 | state -- One of "active" or "blackhole". The blackhole state | ||
| 48 | applies when the route's target isn't usable for | ||
| 49 | one reason or another. | ||
| 50 | |||
| 51 | In addition, the following convenience methods are provided: | ||
| 52 | |||
| 53 | target -- Return the target of the route. This method will return | ||
| 54 | a VM::EC2::Instance, VM::EC2::VPC::InternetGateway, or | ||
| 55 | VM::EC2::NetworkInterface object depending on the nature | ||
| 56 | of the target. | ||
| 57 | |||
| 58 | instance -- If an instance is the target, return the corresponding | ||
| 59 | VM::EC2::Instance object | ||
| 60 | |||
| 61 | gateway -- If a gateway is the target, return the corresponding | ||
| 62 | VM::EC2::VPC::InternetGateway object. | ||
| 63 | |||
| 64 | network_interface -- If a network interface is the target, return the | ||
| 65 | corresponding VM::EC2::NetworkInterface object. | ||
| 66 | |||
| 67 | =head1 STRING OVERLOADING | ||
| 68 | |||
| 69 | When used in a string context, this object will be interpolated as the | ||
| 70 | destinationCidrBlock | ||
| 71 | |||
| 72 | =head1 SEE ALSO | ||
| 73 | |||
| 74 | L<VM::EC2> | ||
| 75 | L<VM::EC2::Generic> | ||
| 76 | |||
| 77 | =head1 AUTHOR | ||
| 78 | |||
| 79 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 80 | |||
| 81 | Copyright (c) 2012 Ontario Institute for Cancer Research | ||
| 82 | |||
| 83 | This package and its accompanying libraries is free software; you can | ||
| 84 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 85 | version 1, or at your option, any later version) or the Artistic | ||
| 86 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 87 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | use strict; | ||
| 92 | use Carp 'croak'; | ||
| 93 | use base 'VM::EC2::Generic'; | ||
| 94 | |||
| 95 | sub valid_fields { | ||
| 96 | my $self = shift; | ||
| 97 | return qw(destinationCidrBlock gatewayId instanceId instanceOwnerId networkInterfaceId state); | ||
| 98 | } | ||
| 99 | |||
| 100 | sub short_name { shift->destinationCidrBlock } | ||
| 101 | |||
| 102 | sub instance { | ||
| 103 | my $self = shift; | ||
| 104 | my $instance = $self->instanceId or return; | ||
| 105 | return $self->aws->describe_instances($instance); | ||
| 106 | } | ||
| 107 | |||
| 108 | sub gateway { | ||
| 109 | my $self = shift; | ||
| 110 | my $gw = $self->gatewayId or return; | ||
| 111 | return $self->aws->describe_internet_gateways($gw); | ||
| 112 | } | ||
| 113 | |||
| 114 | sub network_interface { | ||
| 115 | my $self = shift; | ||
| 116 | my $ni = $self->networkInterfaceId or return; | ||
| 117 | return $self->aws->describe_network_interfaces($ni); | ||
| 118 | } | ||
| 119 | |||
| 120 | sub target { | ||
| 121 | my $self = shift; | ||
| 122 | return $self->instance || $self->gateway || $self->network_interface; | ||
| 123 | } | ||
| 124 | |||
| 125 | 1; | ||
| 126 |