| 1 | package VM::EC2::REST::vpc; | ||
| 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 | AcceptVpcPeeringConnection => 'fetch_one,vpcPeeringConnection,VM::EC2::VPC::PeeringConnection', | ||
| 9 | CreateVpc => 'fetch_one,vpc,VM::EC2::VPC', | ||
| 10 | CreateVpcPeeringConnection => 'fetch_one,vpcPeeringConnection,VM::EC2::VPC::PeeringConnection', | ||
| 11 | DeleteVpc => 'boolean', | ||
| 12 | DeleteVpcPeeringConnection => 'boolean', | ||
| 13 | DescribeVpcs => 'fetch_items,vpcSet,VM::EC2::VPC', | ||
| 14 | DescribeVpcAttribute => 'boolean', | ||
| 15 | DescribeVpcPeeringConnections => 'fetch_items,vpcPeeringConnectionSet,VM::EC2::VPC::PeeringConnection', | ||
| 16 | ModifyVpcAttribute => 'boolean', | ||
| 17 | RejectVpcPeeringConnection => 'boolean', | ||
| 18 | ); | ||
| 19 | |||
| 20 | my $VEP = 'VM::EC2::ParmParser'; | ||
| 21 | |||
| 22 | =head1 NAME VM::EC2::REST::vpc | ||
| 23 | |||
| 24 | =head1 SYNOPSIS | ||
| 25 | |||
| 26 | use VM::EC2 ':vpc'; | ||
| 27 | |||
| 28 | =head1 METHODS | ||
| 29 | |||
| 30 | EC2 virtual private clouds (VPCs) provide facilities for creating | ||
| 31 | tiered applications combining public and private subnetworks, and for | ||
| 32 | extending your home/corporate network into the cloud. | ||
| 33 | |||
| 34 | Implemented: | ||
| 35 | AcceptVpcPeeringConnection | ||
| 36 | CreateVpc | ||
| 37 | CreateVpcPeeringConnection | ||
| 38 | DeleteVpc | ||
| 39 | DeleteVpcPeeringConnection | ||
| 40 | DescribeVpcPeeringConnections | ||
| 41 | DescribeVpcs | ||
| 42 | DescribeVpcAttribute | ||
| 43 | ModifyVpcAttribute | ||
| 44 | RejectVpcPeeringConnection | ||
| 45 | |||
| 46 | Unimplemented: | ||
| 47 | (none) | ||
| 48 | |||
| 49 | =cut | ||
| 50 | |||
| 51 | =head2 $vpx = $ec2->accept_vpc_peering_connection(-vpc_peering_connection_id => $id) | ||
| 52 | |||
| 53 | =head2 $vpx = $ec2->accept_vpc_peering_connection($id) | ||
| 54 | |||
| 55 | Accepts a VPC peering connection request. To accept a request, the VPC peering | ||
| 56 | connection must be in the pending-acceptance state, and the request must come from | ||
| 57 | the owner of the peer VPC. | ||
| 58 | Use describe_vpc_peering_connections(-filter => { 'status-code' => 'pending-acceptance' }) | ||
| 59 | to view outstanding VPC peering connection requests. | ||
| 60 | |||
| 61 | Required arguments: | ||
| 62 | |||
| 63 | -vpc_peering_connection_id -- The ID of the VPC peering connection | ||
| 64 | |||
| 65 | Returns a L<VM::EC2::VPC::PeeringConnection> object. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub accept_vpc_peering_connection { | ||
| 70 | my $self = shift; | ||
| 71 | my %args = $VEP->args(-vpc_peering_connection_id,@_); | ||
| 72 | $args{-vpc_peering_connection_id} or | ||
| 73 | croak "accept_vpc_peering_connection(): -vpc_peering_connection_id argument required"; | ||
| 74 | my @param = $VEP->format_parms(\%args, | ||
| 75 | { | ||
| 76 | single_parm => 'VpcPeeringConnectionId', | ||
| 77 | }); | ||
| 78 | return $self->call('AcceptVpcPeeringConnection',@param); | ||
| 79 | } | ||
| 80 | |||
| 81 | =head2 $vpc = $ec2->create_vpc(-cidr_block=>$cidr,-instance_tenancy=>$tenancy) | ||
| 82 | |||
| 83 | Create a new VPC. This can be called with a single argument, in which | ||
| 84 | case it is interpreted as the desired CIDR block, or | ||
| 85 | |||
| 86 | $vpc = $ec2->$ec2->create_vpc('10.0.0.0/16') or die $ec2->error_str; | ||
| 87 | |||
| 88 | Or it can be called with named arguments. | ||
| 89 | |||
| 90 | Required arguments: | ||
| 91 | |||
| 92 | -cidr_block The Classless Internet Domain Routing address, in the | ||
| 93 | form xx.xx.xx.xx/xx. One or more subnets will be allocated | ||
| 94 | from within this block. | ||
| 95 | |||
| 96 | Optional arguments: | ||
| 97 | |||
| 98 | -instance_tenancy "default" or "dedicated". The latter requests AWS to | ||
| 99 | launch all your instances in the VPC on single-tenant | ||
| 100 | hardware (at additional cost). | ||
| 101 | |||
| 102 | See | ||
| 103 | http://docs.amazonwebservices.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html | ||
| 104 | for a description of the valid CIDRs that can be used with EC2. | ||
| 105 | |||
| 106 | On success, this method will return a new VM::EC2::VPC object. You can | ||
| 107 | then use this object to create new subnets within the VPC: | ||
| 108 | |||
| 109 | $vpc = $ec2->create_vpc('10.0.0.0/16') or die $ec2->error_str; | ||
| 110 | $subnet1 = $vpc->create_subnet('10.0.0.0/24') or die $vpc->error_str; | ||
| 111 | $subnet2 = $vpc->create_subnet('10.0.1.0/24') or die $vpc->error_str; | ||
| 112 | $subnet3 = $vpc->create_subnet('10.0.2.0/24') or die $vpc->error_str; | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub create_vpc { | ||
| 117 | my $self = shift; | ||
| 118 | my %args = $VEP->args(-cidr_block,@_); | ||
| 119 | $args{-cidr_block} or | ||
| 120 | croak "create_vpc(): must provide a -cidr_block parameter"; | ||
| 121 | my @param = $VEP->format_parms(\%args, | ||
| 122 | { | ||
| 123 | list_parm => 'CidrBlock', | ||
| 124 | single_parm => 'instanceTenancy', | ||
| 125 | }); | ||
| 126 | return $self->call('CreateVpc',@param); | ||
| 127 | } | ||
| 128 | |||
| 129 | =head2 $pcx = $ec2->create_vpc_peering_connection(-vpc_id => $vpc_id, | ||
| 130 | -peer_vpc_id => $peer_id, | ||
| 131 | -peer_owner_id => $owner_id) | ||
| 132 | |||
| 133 | Requests a VPC peering connection between two VPCs: a requester VPC and a peer | ||
| 134 | VPC with which to create the connection. The peer VPC can belong to another AWS | ||
| 135 | account. The requester VPC and peer VPC must not have overlapping CIDR blocks. | ||
| 136 | |||
| 137 | The owner of the peer VPC must accept the peering request to activate the | ||
| 138 | peering connection. The VPC peering connection request expires after seven days, | ||
| 139 | after which it cannot be accepted or rejected. | ||
| 140 | |||
| 141 | Required arguments: | ||
| 142 | |||
| 143 | -vpc_id The ID of the requester VPC | ||
| 144 | |||
| 145 | -peer_vpc_id The ID of the VPC with which the peering connection is to be | ||
| 146 | made | ||
| 147 | |||
| 148 | Conditional arguments: | ||
| 149 | |||
| 150 | -peer_owner_id The AWS account ID of the owner of the peer VPC | ||
| 151 | Required if the peer VPC is not in the same account as the | ||
| 152 | requester VPC | ||
| 153 | |||
| 154 | Returns a L<VM::EC2::VPC::PeeringConnection> object. | ||
| 155 | |||
| 156 | =cut | ||
| 157 | |||
| 158 | sub create_vpc_peering_connection { | ||
| 159 | my $self = shift; | ||
| 160 | my %args = @_; | ||
| 161 | $args{-vpc_id} or | ||
| 162 | croak "create_vpc_peering_connection(): -vpc_id argument required"; | ||
| 163 | $args{-peer_vpc_id} or | ||
| 164 | croak "create_vpc_peering_connection(): -peer_vpc_id argument required"; | ||
| 165 | my @param = $VEP->format_parms(\%args, | ||
| 166 | { | ||
| 167 | single_parm => [qw(VpcId PeerVpcId PeerOwnerId)], | ||
| 168 | }); | ||
| 169 | return $self->call('CreateVpcPeeringConnection',@param); | ||
| 170 | } | ||
| 171 | |||
| 172 | =head2 @vpc = $ec2->describe_vpcs(@vpc_ids) | ||
| 173 | |||
| 174 | =head2 @vpc = $ec2->describe_vpcs(\%filter) | ||
| 175 | |||
| 176 | =head2 @vpc = $ec2->describe_vpcs(-vpc_id=>\@list,-filter=>\%filter) | ||
| 177 | |||
| 178 | Describe VPCs that you own and return a list of VM::EC2::VPC | ||
| 179 | objects. Call with no arguments to return all VPCs, or provide a list | ||
| 180 | of VPC IDs to return information on those only. You may also provide a | ||
| 181 | filter list, or named argument forms. | ||
| 182 | |||
| 183 | Optional arguments: | ||
| 184 | |||
| 185 | -vpc_id A scalar or array ref containing the VPC IDs you want | ||
| 186 | information on. | ||
| 187 | |||
| 188 | -filter A hashref of filters to apply to the query. | ||
| 189 | |||
| 190 | The filters you can use are described at | ||
| 191 | http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVpcs.html | ||
| 192 | |||
| 193 | =cut | ||
| 194 | |||
| 195 | sub describe_vpcs { | ||
| 196 | my $self = shift; | ||
| 197 | my %args = $VEP->args(-vpc_id,@_); | ||
| 198 | my @param = $VEP->format_parms(\%args, | ||
| 199 | { | ||
| 200 | list_parm => 'VpcId', | ||
| 201 | filter_parm => 'Filter', | ||
| 202 | }); | ||
| 203 | return $self->call('DescribeVpcs',@param); | ||
| 204 | } | ||
| 205 | |||
| 206 | =head2 @vpx = $ec2->describe_vpc_peering_connections(@vpx_ids) | ||
| 207 | |||
| 208 | =head2 @vpx = $ec2->describe_vpc_peering_connections(\%filter) | ||
| 209 | |||
| 210 | =head2 @vpx = $ec2->describe_vpc_peering_connections(vpc_peering_connection_id=>\@list,-filter=>\%filter) | ||
| 211 | |||
| 212 | Describes one or more of your VPC peering connections. | ||
| 213 | |||
| 214 | Optional arguments: | ||
| 215 | |||
| 216 | -vpc_peering_connection_id A scalar or array ref containing the VPC IDs you want | ||
| 217 | information on. | ||
| 218 | |||
| 219 | -filter A hashref of filters to apply to the query. | ||
| 220 | |||
| 221 | The filters you can use are described at | ||
| 222 | http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVpcPeeringConnections.html | ||
| 223 | |||
| 224 | Returns a scalar or array of L<VM::EC2::VPC::PeeringConnection> objects. | ||
| 225 | |||
| 226 | =cut | ||
| 227 | |||
| 228 | sub describe_vpc_peering_connections { | ||
| 229 | my $self = shift; | ||
| 230 | my %args = $VEP->args(-vpc_peering_connection_id,@_); | ||
| 231 | my @param = $VEP->format_parms(\%args, | ||
| 232 | { | ||
| 233 | list_parm => 'VpcPeeringConnectionId', | ||
| 234 | filter_parm => 'Filter', | ||
| 235 | }); | ||
| 236 | return $self->call('DescribeVpcPeeringConnections',@param); | ||
| 237 | } | ||
| 238 | |||
| 239 | =head2 $success = $ec2->delete_vpc($vpc_id) | ||
| 240 | |||
| 241 | =head2 $success = $ec2->delete_vpc(-vpc_id=>$vpc_id) | ||
| 242 | |||
| 243 | Delete the indicated VPC, returning true if successful. | ||
| 244 | |||
| 245 | =cut | ||
| 246 | |||
| 247 | sub delete_vpc { | ||
| 248 | my $self = shift; | ||
| 249 | my %args = $VEP->args(-vpc_id,@_); | ||
| 250 | my @param = $VEP->format_parms(\%args, | ||
| 251 | { | ||
| 252 | single_parm => 'VpcId', | ||
| 253 | }); | ||
| 254 | return $self->call('DeleteVpc',@param); | ||
| 255 | } | ||
| 256 | |||
| 257 | =head2 $success = $ec2->delete_vpc_peering_connection(-vpc_peering_connection_id => $id) | ||
| 258 | |||
| 259 | =head2 $success = $ec2->delete_vpc_peering_connection($id) | ||
| 260 | |||
| 261 | Deletes a VPC peering connection. Either the owner of the requester VPC or the | ||
| 262 | owner of the peer VPC can delete the VPC peering connection if it's in the | ||
| 263 | 'active' state. The owner of the requester VPC can delete a VPC peering | ||
| 264 | connection in the 'pending-acceptance' state. | ||
| 265 | |||
| 266 | Required arguments: | ||
| 267 | |||
| 268 | -vpc_peering_connection_id The ID of the VPC peering connection to delete | ||
| 269 | |||
| 270 | Returns true if the deletion was successful. | ||
| 271 | |||
| 272 | =cut | ||
| 273 | |||
| 274 | sub delete_vpc_peering_connection { | ||
| 275 | my $self = shift; | ||
| 276 | my %args = $VEP->args(-vpc_peering_connection_id,@_); | ||
| 277 | $args{-vpc_peering_connection_id} or | ||
| 278 | croak "delete_vpc_peering_connection(): -vpc_peering_connection_id argument required"; | ||
| 279 | my @param = $VEP->format_parms(\%args, | ||
| 280 | { | ||
| 281 | single_parm => 'VpcPeeringConnectionId', | ||
| 282 | }); | ||
| 283 | return $self->call('DeleteVpcPeeringConnection',@param); | ||
| 284 | } | ||
| 285 | |||
| 286 | =head2 $attr = $ec2->describe_vpc_attribute(-vpc_id => $id, -attribute => $attr) | ||
| 287 | |||
| 288 | Describes an attribute of the specified VPC. | ||
| 289 | |||
| 290 | Required arguments: | ||
| 291 | |||
| 292 | -vpc_id The ID of the VPC. | ||
| 293 | |||
| 294 | -attribute The VPC attribute. | ||
| 295 | Valid values: | ||
| 296 | enableDnsSupport | enableDnsHostnames | ||
| 297 | |||
| 298 | Returns true if attribute is set. | ||
| 299 | |||
| 300 | =cut | ||
| 301 | |||
| 302 | sub describe_vpc_attribute { | ||
| 303 | my $self = shift; | ||
| 304 | my %args = @_; | ||
| 305 | $args{-vpc_id} or croak "modify_vpc_attribute(): -vpc_id argument missing"; | ||
| 306 | $args{-attribute} or | ||
| 307 | croak "modify_vpc_attribute(): -attribute argument missing"; | ||
| 308 | my @param = $VEP->format_parms(\%args, | ||
| 309 | { | ||
| 310 | single_parm => [qw(VpcId Attribute)], | ||
| 311 | }); | ||
| 312 | my $result = $self->call('DescribeVpcAttribute',@param); | ||
| 313 | return $result && $result->attribute($args{-attribute}) eq 'true'; | ||
| 314 | } | ||
| 315 | |||
| 316 | =head2 $success = $ec2->modify_vpc_attribute(-vpc_id => $id, | ||
| 317 | -enable_dns_support => $boolen, | ||
| 318 | -enable_dns_hostnames => $boolean) | ||
| 319 | |||
| 320 | Modify attributes of a VPC. | ||
| 321 | |||
| 322 | Required Arguments: | ||
| 323 | |||
| 324 | -vpc_id The ID of the VPC. | ||
| 325 | |||
| 326 | One or more of the following arguments is required: | ||
| 327 | |||
| 328 | -enable_dns_support Specifies whether the DNS server provided | ||
| 329 | by Amazon is enabled for the VPC. | ||
| 330 | |||
| 331 | -enable_dns_hostnames Specifies whether DNS hostnames are provided | ||
| 332 | for the instances launched in this VPC. You | ||
| 333 | can only set this attribute to true if | ||
| 334 | -enable_dns_support is also true. | ||
| 335 | |||
| 336 | Returns true on success. | ||
| 337 | |||
| 338 | =cut | ||
| 339 | |||
| 340 | sub modify_vpc_attribute { | ||
| 341 | my $self = shift; | ||
| 342 | my %args = @_; | ||
| 343 | $args{-vpc_id} or croak "modify_vpc_attribute(): -vpc_id argument missing"; | ||
| 344 | $args{-enable_dns_support} || $args{-enable_dns_hostnames} or | ||
| 345 | croak "modify_vpc_attribute(): -enable_dns_support or -enable_dns_hostnames argument required"; | ||
| 346 | my @param = $VEP->format_parms(\%args, | ||
| 347 | { | ||
| 348 | boolean_parm => [qw(enableDnsSupport enableDnsHostnames)], | ||
| 349 | single_parm => 'VpcId', | ||
| 350 | }); | ||
| 351 | return $self->call('ModifyVpcAttribute',@param); | ||
| 352 | } | ||
| 353 | |||
| 354 | =head2 $success = $ec2->reject_vpc_peering_connection(-vpc_peering_connection_id => $id) | ||
| 355 | |||
| 356 | Rejects a VPC peering connection request. The VPC peering connection must be in | ||
| 357 | the 'pending-acceptance' state. | ||
| 358 | Use describe_vpc_peering_connections(-filter => { 'status-code' => 'pending-acceptance' }) | ||
| 359 | to view outstanding VPC peering connection requests. | ||
| 360 | |||
| 361 | Required arguments: | ||
| 362 | |||
| 363 | -vpc_peering_connection_id The ID of the VPC peering connection to delete | ||
| 364 | |||
| 365 | Returns true if the deletion was successful. | ||
| 366 | |||
| 367 | =cut | ||
| 368 | |||
| 369 | sub reject_vpc_peering_connection { | ||
| 370 | my $self = shift; | ||
| 371 | my %args = $VEP->args(-vpc_peering_connection_id,@_); | ||
| 372 | $args{-vpc_peering_connection_id} or | ||
| 373 | croak "reject_vpc_peering_connection(): -vpc_peering_connection_id argument required"; | ||
| 374 | my @param = $VEP->format_parms(\%args, | ||
| 375 | { | ||
| 376 | single_parm => 'VpcPeeringConnectionId', | ||
| 377 | }); | ||
| 378 | return $self->call('RejectVpcPeeringConnection',@param); | ||
| 379 | } | ||
| 380 | |||
| 381 | =head1 SEE ALSO | ||
| 382 | |||
| 383 | L<VM::EC2> | ||
| 384 | |||
| 385 | =head1 AUTHOR | ||
| 386 | |||
| 387 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 388 | |||
| 389 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 390 | |||
| 391 | Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt> | ||
| 392 | |||
| 393 | Copyright (c) 2014 Loyalty Methods, Inc. | ||
| 394 | |||
| 395 | This package and its accompanying libraries is free software; you can | ||
| 396 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 397 | version 1, or at your option, any later version) or the Artistic | ||
| 398 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 399 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 400 | |||
| 401 | =cut | ||
| 402 | |||
| 403 | |||
| 404 | 1; |