| 1 | package VM::EC2::VPC::InternetGateway; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::VPC::InternetGateway -- A VPC internet gateway | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | my $ec2 = VM::EC2->new(...); | ||
| 11 | my @gateways = $ec2->describe_internet_gateways; | ||
| 12 | |||
| 13 | for my $gw (@gateways) { | ||
| 14 | print $gw->internetGatewayId,"\n"; | ||
| 15 | my @attachments = $gw->attachments; | ||
| 16 | } | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | This object provides information about EC2 Virtual Private Cloud | ||
| 21 | internet gateways, which, together with routing tables, allow | ||
| 22 | instances within a VPC to communicate with the outside world. | ||
| 23 | |||
| 24 | =head1 METHODS | ||
| 25 | |||
| 26 | These object methods are supported: | ||
| 27 | |||
| 28 | internetGatewayId -- the ID of the gateway | ||
| 29 | attachments -- An array of VM::EC2::VPC::InternetGateway::Attachment | ||
| 30 | objects, each describing a VPC attached to this gateway. | ||
| 31 | |||
| 32 | This class supports the VM::EC2 tagging interface. See | ||
| 33 | L<VM::EC2::Generic> for information. | ||
| 34 | |||
| 35 | In addition, this object supports the following convenience methods: | ||
| 36 | |||
| 37 | attach($vpc) -- Attach this gateway to the indicated VPC (ID or | ||
| 38 | VM::EC2::VPC object). | ||
| 39 | detach($vpc) -- Detach this gateway from the indicated VPC (ID or | ||
| 40 | VM::EC2::VPC object). | ||
| 41 | refresh -- Refreshes the contents of the object, primarily to | ||
| 42 | check for changes in attachment state. | ||
| 43 | |||
| 44 | =head1 STRING OVERLOADING | ||
| 45 | |||
| 46 | When used in a string context, this object will be interpolated as the | ||
| 47 | internet gateway ID. | ||
| 48 | |||
| 49 | =head1 SEE ALSO | ||
| 50 | |||
| 51 | L<VM::EC2> | ||
| 52 | L<VM::EC2::Generic> | ||
| 53 | L<VM::EC2::VPC> | ||
| 54 | |||
| 55 | =head1 AUTHOR | ||
| 56 | |||
| 57 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 58 | |||
| 59 | Copyright (c) 2012 Ontario Institute for Cancer Research | ||
| 60 | |||
| 61 | This package and its accompanying libraries is free software; you can | ||
| 62 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 63 | version 1, or at your option, any later version) or the Artistic | ||
| 64 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 65 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | use strict; | ||
| 70 | use Carp 'croak'; | ||
| 71 | use base 'VM::EC2::Generic'; | ||
| 72 | use VM::EC2::VPC::InternetGateway::Attachment; | ||
| 73 | |||
| 74 | sub valid_fields { | ||
| 75 | my $self = shift; | ||
| 76 | return qw(internetGatewayId attachmentSet); | ||
| 77 | } | ||
| 78 | |||
| 79 | sub primary_id { shift->internetGatewayId } | ||
| 80 | |||
| 81 | sub attachments { | ||
| 82 | my $self = shift; | ||
| 83 | my $set = $self->attachmentSet or return; | ||
| 84 | return map {VM::EC2::VPC::InternetGateway::Attachment->new($_,$self->aws)} @{$set->{item}}; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub attach { | ||
| 88 | my $self = shift; | ||
| 89 | my $vpc = shift or croak "Usage: attach(\$vpc)"; | ||
| 90 | my $result = $self->aws->attach_internet_gateway($self=>$vpc); | ||
| 91 | $self->refresh if $result; | ||
| 92 | return $result; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub detach { | ||
| 96 | my $self = shift; | ||
| 97 | my $vpc = shift or croak "Usage: detach(\$vpc)"; | ||
| 98 | my $result = $self->aws->detach_internet_gateway($self => $vpc); | ||
| 99 | $self->refresh if $result; | ||
| 100 | return $result; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub refresh { | ||
| 104 | my $self = shift; | ||
| 105 | my $i = shift; | ||
| 106 | local $self->aws->{raise_error} = 1; | ||
| 107 | ($i) = $self->aws->describe_internet_gateways($self->internetGatewayId) unless $i; | ||
| 108 | %$self = %$i if $i; | ||
| 109 | return defined $i; | ||
| 110 | } | ||
| 111 | |||
| 112 | 1; | ||
| 113 |