| 1 | package VM::EC2::REST::internet_gateway; | ||
| 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 | CreateInternetGateway => 'fetch_one,internetGateway,VM::EC2::VPC::InternetGateway', | ||
| 9 | DescribeInternetGateways => 'fetch_items,internetGatewaySet,VM::EC2::VPC::InternetGateway', | ||
| 10 | DeleteInternetGateway => 'boolean', | ||
| 11 | AttachInternetGateway => 'boolean', | ||
| 12 | DetachInternetGateway => 'boolean', | ||
| 13 | ); | ||
| 14 | |||
| 15 | =head1 NAME VM::EC2::REST::internet_gateway | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use VM::EC2 ':vpc' | ||
| 20 | |||
| 21 | =head1 METHODS | ||
| 22 | |||
| 23 | These methods provide methods for creating, associating and deleting | ||
| 24 | Internet Gateway objects. | ||
| 25 | |||
| 26 | Implemented: | ||
| 27 | AttachInternetGateway | ||
| 28 | CreateInternetGateway | ||
| 29 | DeleteInternetGateway | ||
| 30 | DescribeInternetGateways | ||
| 31 | DetachInternetGateway | ||
| 32 | |||
| 33 | Unimplemented: | ||
| 34 | (none) | ||
| 35 | |||
| 36 | =head2 $gateway = $ec2->create_internet_gateway() | ||
| 37 | |||
| 38 | This method creates a new Internet gateway. It takes no arguments and | ||
| 39 | returns a VM::EC2::VPC::InternetGateway object. Gateways are initially | ||
| 40 | independent of any VPC, but later can be attached to one or more VPCs | ||
| 41 | using attach_internet_gateway(). | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | sub create_internet_gateway { | ||
| 46 | my $self = shift; | ||
| 47 | return $self->call('CreateInternetGateway'); | ||
| 48 | } | ||
| 49 | |||
| 50 | =head2 $success = $ec2->delete_internet_gateway($internet_gateway_id) | ||
| 51 | |||
| 52 | =head2 $success = $ec2->delete_internet_gateway(-internet_gateway_id=>$id) | ||
| 53 | |||
| 54 | This method deletes the indicated internet gateway. It may be called | ||
| 55 | with a single argument corresponding to the route table's ID, or using | ||
| 56 | the named form with argument -internet_gateway_id. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | sub delete_internet_gateway { | ||
| 61 | my $self = shift; | ||
| 62 | my %args = $self->args(-internet_gateway_id=>@_); | ||
| 63 | my @parm = $self->single_parm(InternetGatewayId=>\%args); | ||
| 64 | return $self->call('DeleteInternetGateway',@parm); | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | =head2 @gateways = $ec2->describe_internet_gateways(@gateway_ids) | ||
| 69 | |||
| 70 | =head2 @gateways = $ec2->describe_internet_gateways(\%filters) | ||
| 71 | |||
| 72 | =head2 @gateways = $ec2->describe_internet_gateways(-internet_gateway_id=>\@ids, | ||
| 73 | -filter =>\$filters) | ||
| 74 | |||
| 75 | This method describes all or some of the internet gateways available | ||
| 76 | to you. You may use the filter to restrict the search to a particular | ||
| 77 | type of internet gateway using one or more of the filters described at | ||
| 78 | http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInternetGateways.html. | ||
| 79 | |||
| 80 | Some of the commonly used filters are: | ||
| 81 | |||
| 82 | attachment.vpc-id ID of one of the VPCs the gateway is attached to | ||
| 83 | attachment.state State of the gateway, always "available" | ||
| 84 | tag:<key> Value of a tag | ||
| 85 | |||
| 86 | On success this method returns a list of VM::EC2::VPC::InternetGateway | ||
| 87 | objects. | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub describe_internet_gateways { | ||
| 92 | my $self = shift; | ||
| 93 | my %args = $self->args(-internet_gateway_id => @_); | ||
| 94 | my @parm = $self->list_parm('InternetGatewayId',\%args); | ||
| 95 | push @parm, $self->filter_parm(\%args); | ||
| 96 | return $self->call('DescribeInternetGateways',@parm); | ||
| 97 | } | ||
| 98 | |||
| 99 | =head2 $boolean = $ec2->attach_internet_gateway($internet_gateway_id,$vpc_id) | ||
| 100 | |||
| 101 | =head2 $boolean = $ec2->attach_internet_gateway(-internet_gateway_id => $id, | ||
| 102 | -vpc_id => $id) | ||
| 103 | |||
| 104 | This method attaches an internet gateway to a VPC. You can use | ||
| 105 | internet gateway and VPC IDs, or their corresponding | ||
| 106 | VM::EC2::VPC::InternetGateway and VM::EC2::VPC objects. | ||
| 107 | |||
| 108 | Required arguments: | ||
| 109 | |||
| 110 | -internet_gateway_id ID of the network interface to attach. | ||
| 111 | -vpc_id ID of the instance to attach the interface to. | ||
| 112 | |||
| 113 | On success, this method a true value. | ||
| 114 | |||
| 115 | Note that it may be more convenient to attach and detach gateways via | ||
| 116 | methods in the VM::EC2::VPC and VM::EC2::VPC::Gateway objects. | ||
| 117 | |||
| 118 | $vpc->attach_internet_gateway($gateway); | ||
| 119 | $gateway->attach($vpc); | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | sub attach_internet_gateway { | ||
| 124 | my $self = shift; | ||
| 125 | my %args; | ||
| 126 | if ($_[0] !~ /^-/ && @_ == 2) { | ||
| 127 | @args{qw(-internet_gateway_id -vpc_id)} = @_; | ||
| 128 | } else { | ||
| 129 | %args = @_; | ||
| 130 | } | ||
| 131 | $args{-internet_gateway_id} && $args{-vpc_id} | ||
| 132 | or croak "-internet_gateway_id and-vpc_id arguments must be specified"; | ||
| 133 | |||
| 134 | $args{-device_index} =~ s/^eth//; | ||
| 135 | |||
| 136 | my @param = $self->single_parm(InternetGatewayId=>\%args); | ||
| 137 | push @param,$self->single_parm(VpcId=>\%args); | ||
| 138 | return $self->call('AttachInternetGateway',@param); | ||
| 139 | } | ||
| 140 | |||
| 141 | =head2 $boolean = $ec2->detach_internet_gateway($internet_gateway_id,$vpc_id) | ||
| 142 | |||
| 143 | =head2 $boolean = $ec2->detach_internet_gateway(-internet_gateway_id => $id, | ||
| 144 | -vpc_id => $id) | ||
| 145 | |||
| 146 | This method detaches an internet gateway to a VPC. You can use | ||
| 147 | internet gateway and VPC IDs, or their corresponding | ||
| 148 | VM::EC2::VPC::InternetGateway and VM::EC2::VPC objects. | ||
| 149 | |||
| 150 | Required arguments: | ||
| 151 | |||
| 152 | -internet_gateway_id ID of the network interface to detach. | ||
| 153 | -vpc_id ID of the VPC to detach the gateway from. | ||
| 154 | |||
| 155 | On success, this method a true value. | ||
| 156 | |||
| 157 | Note that it may be more convenient to detach and detach gateways via | ||
| 158 | methods in the VM::EC2::VPC and VM::EC2::VPC::Gateway objects. | ||
| 159 | |||
| 160 | $vpc->detach_internet_gateway($gateway); | ||
| 161 | $gateway->detach($vpc); | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | sub detach_internet_gateway { | ||
| 166 | my $self = shift; | ||
| 167 | my %args; | ||
| 168 | if ($_[0] !~ /^-/ && @_ == 2) { | ||
| 169 | @args{qw(-internet_gateway_id -vpc_id)} = @_; | ||
| 170 | } else { | ||
| 171 | %args = @_; | ||
| 172 | } | ||
| 173 | $args{-internet_gateway_id} && $args{-vpc_id} | ||
| 174 | or croak "-internet_gateway_id and-vpc_id arguments must be specified"; | ||
| 175 | |||
| 176 | $args{-device_index} =~ s/^eth//; | ||
| 177 | |||
| 178 | my @param = $self->single_parm(InternetGatewayId=>\%args); | ||
| 179 | push @param,$self->single_parm(VpcId=>\%args); | ||
| 180 | return $self->call('DetachInternetGateway',@param); | ||
| 181 | } | ||
| 182 | |||
| 183 | =head1 SEE ALSO | ||
| 184 | |||
| 185 | L<VM::EC2> | ||
| 186 | |||
| 187 | =head1 AUTHOR | ||
| 188 | |||
| 189 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 190 | |||
| 191 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 192 | |||
| 193 | This package and its accompanying libraries is free software; you can | ||
| 194 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 195 | version 1, or at your option, any later version) or the Artistic | ||
| 196 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 197 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 198 | |||
| 199 | =cut | ||
| 200 | |||
| 201 | |||
| 202 | 1; |