comparison env/lib/python3.9/site-packages/boto/vpc/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 # Copyright (c) 2009 Mitch Garnaat http://garnaat.org/
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21
22 """
23 Represents a connection to the EC2 service.
24 """
25
26 from boto.ec2.connection import EC2Connection
27 from boto.resultset import ResultSet
28 from boto.vpc.vpc import VPC
29 from boto.vpc.customergateway import CustomerGateway
30 from boto.vpc.networkacl import NetworkAcl
31 from boto.vpc.routetable import RouteTable
32 from boto.vpc.internetgateway import InternetGateway
33 from boto.vpc.vpngateway import VpnGateway, Attachment
34 from boto.vpc.dhcpoptions import DhcpOptions
35 from boto.vpc.subnet import Subnet
36 from boto.vpc.vpnconnection import VpnConnection
37 from boto.vpc.vpc_peering_connection import VpcPeeringConnection
38 from boto.ec2 import RegionData
39 from boto.regioninfo import RegionInfo, get_regions
40 from boto.regioninfo import connect
41
42
43 def regions(**kw_params):
44 """
45 Get all available regions for the EC2 service.
46 You may pass any of the arguments accepted by the VPCConnection
47 object's constructor as keyword arguments and they will be
48 passed along to the VPCConnection object.
49
50 :rtype: list
51 :return: A list of :class:`boto.ec2.regioninfo.RegionInfo`
52 """
53 return get_regions('ec2', connection_cls=VPCConnection)
54
55
56 def connect_to_region(region_name, **kw_params):
57 """
58 Given a valid region name, return a
59 :class:`boto.vpc.VPCConnection`.
60 Any additional parameters after the region_name are passed on to
61 the connect method of the region object.
62
63 :type: str
64 :param region_name: The name of the region to connect to.
65
66 :rtype: :class:`boto.vpc.VPCConnection` or ``None``
67 :return: A connection to the given region, or None if an invalid region
68 name is given
69 """
70 return connect('ec2', region_name, connection_cls=VPCConnection,
71 **kw_params)
72
73
74 class VPCConnection(EC2Connection):
75
76 # VPC methods
77
78 def get_all_vpcs(self, vpc_ids=None, filters=None, dry_run=False):
79 """
80 Retrieve information about your VPCs. You can filter results to
81 return information only about those VPCs that match your search
82 parameters. Otherwise, all VPCs associated with your account
83 are returned.
84
85 :type vpc_ids: list
86 :param vpc_ids: A list of strings with the desired VPC ID's
87
88 :type filters: list of tuples or dict
89 :param filters: A list of tuples or dict containing filters. Each tuple
90 or dict item consists of a filter key and a filter value.
91 Possible filter keys are:
92
93 * *state* - a list of states of the VPC (pending or available)
94 * *cidrBlock* - a list CIDR blocks of the VPC
95 * *dhcpOptionsId* - a list of IDs of a set of DHCP options
96
97 :type dry_run: bool
98 :param dry_run: Set to True if the operation should not actually run.
99
100 :rtype: list
101 :return: A list of :class:`boto.vpc.vpc.VPC`
102 """
103 params = {}
104 if vpc_ids:
105 self.build_list_params(params, vpc_ids, 'VpcId')
106 if filters:
107 self.build_filter_params(params, filters)
108 if dry_run:
109 params['DryRun'] = 'true'
110 return self.get_list('DescribeVpcs', params, [('item', VPC)])
111
112 def create_vpc(self, cidr_block, instance_tenancy=None, dry_run=False):
113 """
114 Create a new Virtual Private Cloud.
115
116 :type cidr_block: str
117 :param cidr_block: A valid CIDR block
118
119 :type instance_tenancy: str
120 :param instance_tenancy: The supported tenancy options for instances
121 launched into the VPC. Valid values are 'default' and 'dedicated'.
122
123 :type dry_run: bool
124 :param dry_run: Set to True if the operation should not actually run.
125
126 :rtype: The newly created VPC
127 :return: A :class:`boto.vpc.vpc.VPC` object
128 """
129 params = {'CidrBlock': cidr_block}
130 if instance_tenancy:
131 params['InstanceTenancy'] = instance_tenancy
132 if dry_run:
133 params['DryRun'] = 'true'
134 return self.get_object('CreateVpc', params, VPC)
135
136 def delete_vpc(self, vpc_id, dry_run=False):
137 """
138 Delete a Virtual Private Cloud.
139
140 :type vpc_id: str
141 :param vpc_id: The ID of the vpc to be deleted.
142
143 :type dry_run: bool
144 :param dry_run: Set to True if the operation should not actually run.
145
146 :rtype: bool
147 :return: True if successful
148 """
149 params = {'VpcId': vpc_id}
150 if dry_run:
151 params['DryRun'] = 'true'
152 return self.get_status('DeleteVpc', params)
153
154 def modify_vpc_attribute(self, vpc_id,
155 enable_dns_support=None,
156 enable_dns_hostnames=None, dry_run=False):
157 """
158 Modifies the specified attribute of the specified VPC.
159 You can only modify one attribute at a time.
160
161 :type vpc_id: str
162 :param vpc_id: The ID of the vpc to be deleted.
163
164 :type enable_dns_support: bool
165 :param enable_dns_support: Specifies whether the DNS server
166 provided by Amazon is enabled for the VPC.
167
168 :type enable_dns_hostnames: bool
169 :param enable_dns_hostnames: Specifies whether DNS hostnames are
170 provided for the instances launched in this VPC. You can only
171 set this attribute to ``true`` if EnableDnsSupport
172 is also ``true``.
173
174 :type dry_run: bool
175 :param dry_run: Set to True if the operation should not actually run.
176
177 """
178 params = {'VpcId': vpc_id}
179 if enable_dns_support is not None:
180 if enable_dns_support:
181 params['EnableDnsSupport.Value'] = 'true'
182 else:
183 params['EnableDnsSupport.Value'] = 'false'
184 if enable_dns_hostnames is not None:
185 if enable_dns_hostnames:
186 params['EnableDnsHostnames.Value'] = 'true'
187 else:
188 params['EnableDnsHostnames.Value'] = 'false'
189 if dry_run:
190 params['DryRun'] = 'true'
191 return self.get_status('ModifyVpcAttribute', params)
192
193 # Route Tables
194
195 def get_all_route_tables(self, route_table_ids=None, filters=None,
196 dry_run=False):
197 """
198 Retrieve information about your routing tables. You can filter results
199 to return information only about those route tables that match your
200 search parameters. Otherwise, all route tables associated with your
201 account are returned.
202
203 :type route_table_ids: list
204 :param route_table_ids: A list of strings with the desired route table
205 IDs.
206
207 :type filters: list of tuples or dict
208 :param filters: A list of tuples or dict containing filters. Each tuple
209 or dict item consists of a filter key and a filter value.
210
211 :type dry_run: bool
212 :param dry_run: Set to True if the operation should not actually run.
213
214 :rtype: list
215 :return: A list of :class:`boto.vpc.routetable.RouteTable`
216 """
217 params = {}
218 if route_table_ids:
219 self.build_list_params(params, route_table_ids, "RouteTableId")
220 if filters:
221 self.build_filter_params(params, filters)
222 if dry_run:
223 params['DryRun'] = 'true'
224 return self.get_list('DescribeRouteTables', params,
225 [('item', RouteTable)])
226
227 def associate_route_table(self, route_table_id, subnet_id, dry_run=False):
228 """
229 Associates a route table with a specific subnet.
230
231 :type route_table_id: str
232 :param route_table_id: The ID of the route table to associate.
233
234 :type subnet_id: str
235 :param subnet_id: The ID of the subnet to associate with.
236
237 :type dry_run: bool
238 :param dry_run: Set to True if the operation should not actually run.
239
240 :rtype: str
241 :return: The ID of the association created
242 """
243 params = {
244 'RouteTableId': route_table_id,
245 'SubnetId': subnet_id
246 }
247 if dry_run:
248 params['DryRun'] = 'true'
249 result = self.get_object('AssociateRouteTable', params, ResultSet)
250 return result.associationId
251
252 def disassociate_route_table(self, association_id, dry_run=False):
253 """
254 Removes an association from a route table. This will cause all subnets
255 that would've used this association to now use the main routing
256 association instead.
257
258 :type association_id: str
259 :param association_id: The ID of the association to disassociate.
260
261 :type dry_run: bool
262 :param dry_run: Set to True if the operation should not actually run.
263
264 :rtype: bool
265 :return: True if successful
266 """
267 params = {'AssociationId': association_id}
268 if dry_run:
269 params['DryRun'] = 'true'
270 return self.get_status('DisassociateRouteTable', params)
271
272 def create_route_table(self, vpc_id, dry_run=False):
273 """
274 Creates a new route table.
275
276 :type vpc_id: str
277 :param vpc_id: The VPC ID to associate this route table with.
278
279 :type dry_run: bool
280 :param dry_run: Set to True if the operation should not actually run.
281
282 :rtype: The newly created route table
283 :return: A :class:`boto.vpc.routetable.RouteTable` object
284 """
285 params = {'VpcId': vpc_id}
286 if dry_run:
287 params['DryRun'] = 'true'
288 return self.get_object('CreateRouteTable', params, RouteTable)
289
290 def delete_route_table(self, route_table_id, dry_run=False):
291 """
292 Delete a route table.
293
294 :type route_table_id: str
295 :param route_table_id: The ID of the route table to delete.
296
297 :type dry_run: bool
298 :param dry_run: Set to True if the operation should not actually run.
299
300 :rtype: bool
301 :return: True if successful
302 """
303 params = {'RouteTableId': route_table_id}
304 if dry_run:
305 params['DryRun'] = 'true'
306 return self.get_status('DeleteRouteTable', params)
307
308 def _replace_route_table_association(self, association_id,
309 route_table_id, dry_run=False):
310 """
311 Helper function for replace_route_table_association and
312 replace_route_table_association_with_assoc. Should not be used directly.
313
314 :type association_id: str
315 :param association_id: The ID of the existing association to replace.
316
317 :type route_table_id: str
318 :param route_table_id: The route table to ID to be used in the
319 association.
320
321 :type dry_run: bool
322 :param dry_run: Set to True if the operation should not actually run.
323
324 :rtype: ResultSet
325 :return: ResultSet of Amazon resposne
326 """
327 params = {
328 'AssociationId': association_id,
329 'RouteTableId': route_table_id
330 }
331 if dry_run:
332 params['DryRun'] = 'true'
333 return self.get_object('ReplaceRouteTableAssociation', params,
334 ResultSet)
335
336 def replace_route_table_assocation(self, association_id,
337 route_table_id, dry_run=False):
338 """
339 Replaces a route association with a new route table. This can be
340 used to replace the 'main' route table by using the main route
341 table association instead of the more common subnet type
342 association.
343
344 NOTE: It may be better to use replace_route_table_association_with_assoc
345 instead of this function; this function does not return the new
346 association ID. This function is retained for backwards compatibility.
347
348
349 :type association_id: str
350 :param association_id: The ID of the existing association to replace.
351
352 :type route_table_id: str
353 :param route_table_id: The route table to ID to be used in the
354 association.
355
356 :type dry_run: bool
357 :param dry_run: Set to True if the operation should not actually run.
358
359 :rtype: bool
360 :return: True if successful
361 """
362 return self._replace_route_table_association(
363 association_id, route_table_id, dry_run=dry_run).status
364
365 def replace_route_table_association_with_assoc(self, association_id,
366 route_table_id,
367 dry_run=False):
368 """
369 Replaces a route association with a new route table. This can be
370 used to replace the 'main' route table by using the main route
371 table association instead of the more common subnet type
372 association. Returns the new association ID.
373
374 :type association_id: str
375 :param association_id: The ID of the existing association to replace.
376
377 :type route_table_id: str
378 :param route_table_id: The route table to ID to be used in the
379 association.
380
381 :type dry_run: bool
382 :param dry_run: Set to True if the operation should not actually run.
383
384 :rtype: str
385 :return: New association ID
386 """
387 return self._replace_route_table_association(
388 association_id, route_table_id, dry_run=dry_run).newAssociationId
389
390 def create_route(self, route_table_id, destination_cidr_block,
391 gateway_id=None, instance_id=None, interface_id=None,
392 vpc_peering_connection_id=None,
393 dry_run=False):
394 """
395 Creates a new route in the route table within a VPC. The route's target
396 can be either a gateway attached to the VPC or a NAT instance in the
397 VPC.
398
399 :type route_table_id: str
400 :param route_table_id: The ID of the route table for the route.
401
402 :type destination_cidr_block: str
403 :param destination_cidr_block: The CIDR address block used for the
404 destination match.
405
406 :type gateway_id: str
407 :param gateway_id: The ID of the gateway attached to your VPC.
408
409 :type instance_id: str
410 :param instance_id: The ID of a NAT instance in your VPC.
411
412 :type interface_id: str
413 :param interface_id: Allows routing to network interface attachments.
414
415 :type vpc_peering_connection_id: str
416 :param vpc_peering_connection_id: Allows routing to VPC peering
417 connection.
418
419 :type dry_run: bool
420 :param dry_run: Set to True if the operation should not actually run.
421
422 :rtype: bool
423 :return: True if successful
424 """
425 params = {
426 'RouteTableId': route_table_id,
427 'DestinationCidrBlock': destination_cidr_block
428 }
429
430 if gateway_id is not None:
431 params['GatewayId'] = gateway_id
432 elif instance_id is not None:
433 params['InstanceId'] = instance_id
434 elif interface_id is not None:
435 params['NetworkInterfaceId'] = interface_id
436 elif vpc_peering_connection_id is not None:
437 params['VpcPeeringConnectionId'] = vpc_peering_connection_id
438 if dry_run:
439 params['DryRun'] = 'true'
440
441 return self.get_status('CreateRoute', params)
442
443 def replace_route(self, route_table_id, destination_cidr_block,
444 gateway_id=None, instance_id=None, interface_id=None,
445 vpc_peering_connection_id=None,
446 dry_run=False):
447 """
448 Replaces an existing route within a route table in a VPC.
449
450 :type route_table_id: str
451 :param route_table_id: The ID of the route table for the route.
452
453 :type destination_cidr_block: str
454 :param destination_cidr_block: The CIDR address block used for the
455 destination match.
456
457 :type gateway_id: str
458 :param gateway_id: The ID of the gateway attached to your VPC.
459
460 :type instance_id: str
461 :param instance_id: The ID of a NAT instance in your VPC.
462
463 :type interface_id: str
464 :param interface_id: Allows routing to network interface attachments.
465
466 :type vpc_peering_connection_id: str
467 :param vpc_peering_connection_id: Allows routing to VPC peering
468 connection.
469
470 :type dry_run: bool
471 :param dry_run: Set to True if the operation should not actually run.
472
473 :rtype: bool
474 :return: True if successful
475 """
476 params = {
477 'RouteTableId': route_table_id,
478 'DestinationCidrBlock': destination_cidr_block
479 }
480
481 if gateway_id is not None:
482 params['GatewayId'] = gateway_id
483 elif instance_id is not None:
484 params['InstanceId'] = instance_id
485 elif interface_id is not None:
486 params['NetworkInterfaceId'] = interface_id
487 elif vpc_peering_connection_id is not None:
488 params['VpcPeeringConnectionId'] = vpc_peering_connection_id
489 if dry_run:
490 params['DryRun'] = 'true'
491
492 return self.get_status('ReplaceRoute', params)
493
494 def delete_route(self, route_table_id, destination_cidr_block,
495 dry_run=False):
496 """
497 Deletes a route from a route table within a VPC.
498
499 :type route_table_id: str
500 :param route_table_id: The ID of the route table with the route.
501
502 :type destination_cidr_block: str
503 :param destination_cidr_block: The CIDR address block used for
504 destination match.
505
506 :type dry_run: bool
507 :param dry_run: Set to True if the operation should not actually run.
508
509 :rtype: bool
510 :return: True if successful
511 """
512 params = {
513 'RouteTableId': route_table_id,
514 'DestinationCidrBlock': destination_cidr_block
515 }
516 if dry_run:
517 params['DryRun'] = 'true'
518 return self.get_status('DeleteRoute', params)
519
520 #Network ACLs
521
522 def get_all_network_acls(self, network_acl_ids=None, filters=None):
523 """
524 Retrieve information about your network acls. You can filter results
525 to return information only about those network acls that match your
526 search parameters. Otherwise, all network acls associated with your
527 account are returned.
528
529 :type network_acl_ids: list
530 :param network_acl_ids: A list of strings with the desired network ACL
531 IDs.
532
533 :type filters: list of tuples or dict
534 :param filters: A list of tuples or dict containing filters. Each tuple
535 or dict item consists of a filter key and a filter value.
536
537 :rtype: list
538 :return: A list of :class:`boto.vpc.networkacl.NetworkAcl`
539 """
540 params = {}
541 if network_acl_ids:
542 self.build_list_params(params, network_acl_ids, "NetworkAclId")
543 if filters:
544 self.build_filter_params(params, filters)
545 return self.get_list('DescribeNetworkAcls', params,
546 [('item', NetworkAcl)])
547
548 def associate_network_acl(self, network_acl_id, subnet_id):
549 """
550 Associates a network acl with a specific subnet.
551
552 :type network_acl_id: str
553 :param network_acl_id: The ID of the network ACL to associate.
554
555 :type subnet_id: str
556 :param subnet_id: The ID of the subnet to associate with.
557
558 :rtype: str
559 :return: The ID of the association created
560 """
561
562 acl = self.get_all_network_acls(filters=[('association.subnet-id', subnet_id)])[0]
563 association = [ association for association in acl.associations if association.subnet_id == subnet_id ][0]
564
565 params = {
566 'AssociationId': association.id,
567 'NetworkAclId': network_acl_id
568 }
569
570 result = self.get_object('ReplaceNetworkAclAssociation', params, ResultSet)
571 return result.newAssociationId
572
573 def disassociate_network_acl(self, subnet_id, vpc_id=None):
574 """
575 Figures out what the default ACL is for the VPC, and associates
576 current network ACL with the default.
577
578 :type subnet_id: str
579 :param subnet_id: The ID of the subnet to which the ACL belongs.
580
581 :type vpc_id: str
582 :param vpc_id: The ID of the VPC to which the ACL/subnet belongs. Queries EC2 if omitted.
583
584 :rtype: str
585 :return: The ID of the association created
586 """
587 if not vpc_id:
588 vpc_id = self.get_all_subnets([subnet_id])[0].vpc_id
589 acls = self.get_all_network_acls(filters=[('vpc-id', vpc_id), ('default', 'true')])
590 default_acl_id = acls[0].id
591
592 return self.associate_network_acl(default_acl_id, subnet_id)
593
594 def create_network_acl(self, vpc_id):
595 """
596 Creates a new network ACL.
597
598 :type vpc_id: str
599 :param vpc_id: The VPC ID to associate this network ACL with.
600
601 :rtype: The newly created network ACL
602 :return: A :class:`boto.vpc.networkacl.NetworkAcl` object
603 """
604 params = {'VpcId': vpc_id}
605 return self.get_object('CreateNetworkAcl', params, NetworkAcl)
606
607 def delete_network_acl(self, network_acl_id):
608 """
609 Delete a network ACL
610
611 :type network_acl_id: str
612 :param network_acl_id: The ID of the network_acl to delete.
613
614 :rtype: bool
615 :return: True if successful
616 """
617 params = {'NetworkAclId': network_acl_id}
618 return self.get_status('DeleteNetworkAcl', params)
619
620 def create_network_acl_entry(self, network_acl_id, rule_number, protocol, rule_action,
621 cidr_block, egress=None, icmp_code=None, icmp_type=None,
622 port_range_from=None, port_range_to=None):
623 """
624 Creates a new network ACL entry in a network ACL within a VPC.
625
626 :type network_acl_id: str
627 :param network_acl_id: The ID of the network ACL for this network ACL entry.
628
629 :type rule_number: int
630 :param rule_number: The rule number to assign to the entry (for example, 100).
631
632 :type protocol: int
633 :param protocol: Valid values: -1 or a protocol number
634 (http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)
635
636 :type rule_action: str
637 :param rule_action: Indicates whether to allow or deny traffic that matches the rule.
638
639 :type cidr_block: str
640 :param cidr_block: The CIDR range to allow or deny, in CIDR notation (for example,
641 172.16.0.0/24).
642
643 :type egress: bool
644 :param egress: Indicates whether this rule applies to egress traffic from the subnet (true)
645 or ingress traffic to the subnet (false).
646
647 :type icmp_type: int
648 :param icmp_type: For the ICMP protocol, the ICMP type. You can use -1 to specify
649 all ICMP types.
650
651 :type icmp_code: int
652 :param icmp_code: For the ICMP protocol, the ICMP code. You can use -1 to specify
653 all ICMP codes for the given ICMP type.
654
655 :type port_range_from: int
656 :param port_range_from: The first port in the range.
657
658 :type port_range_to: int
659 :param port_range_to: The last port in the range.
660
661
662 :rtype: bool
663 :return: True if successful
664 """
665 params = {
666 'NetworkAclId': network_acl_id,
667 'RuleNumber': rule_number,
668 'Protocol': protocol,
669 'RuleAction': rule_action,
670 'CidrBlock': cidr_block
671 }
672
673 if egress is not None:
674 if isinstance(egress, bool):
675 egress = str(egress).lower()
676 params['Egress'] = egress
677 if icmp_code is not None:
678 params['Icmp.Code'] = icmp_code
679 if icmp_type is not None:
680 params['Icmp.Type'] = icmp_type
681 if port_range_from is not None:
682 params['PortRange.From'] = port_range_from
683 if port_range_to is not None:
684 params['PortRange.To'] = port_range_to
685
686 return self.get_status('CreateNetworkAclEntry', params)
687
688 def replace_network_acl_entry(self, network_acl_id, rule_number, protocol, rule_action,
689 cidr_block, egress=None, icmp_code=None, icmp_type=None,
690 port_range_from=None, port_range_to=None):
691 """
692 Creates a new network ACL entry in a network ACL within a VPC.
693
694 :type network_acl_id: str
695 :param network_acl_id: The ID of the network ACL for the id you want to replace
696
697 :type rule_number: int
698 :param rule_number: The rule number that you want to replace(for example, 100).
699
700 :type protocol: int
701 :param protocol: Valid values: -1 or a protocol number
702 (http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)
703
704 :type rule_action: str
705 :param rule_action: Indicates whether to allow or deny traffic that matches the rule.
706
707 :type cidr_block: str
708 :param cidr_block: The CIDR range to allow or deny, in CIDR notation (for example,
709 172.16.0.0/24).
710
711 :type egress: bool
712 :param egress: Indicates whether this rule applies to egress traffic from the subnet (true)
713 or ingress traffic to the subnet (false).
714
715 :type icmp_type: int
716 :param icmp_type: For the ICMP protocol, the ICMP type. You can use -1 to specify
717 all ICMP types.
718
719 :type icmp_code: int
720 :param icmp_code: For the ICMP protocol, the ICMP code. You can use -1 to specify
721 all ICMP codes for the given ICMP type.
722
723 :type port_range_from: int
724 :param port_range_from: The first port in the range.
725
726 :type port_range_to: int
727 :param port_range_to: The last port in the range.
728
729
730 :rtype: bool
731 :return: True if successful
732 """
733 params = {
734 'NetworkAclId': network_acl_id,
735 'RuleNumber': rule_number,
736 'Protocol': protocol,
737 'RuleAction': rule_action,
738 'CidrBlock': cidr_block
739 }
740
741 if egress is not None:
742 if isinstance(egress, bool):
743 egress = str(egress).lower()
744 params['Egress'] = egress
745 if icmp_code is not None:
746 params['Icmp.Code'] = icmp_code
747 if icmp_type is not None:
748 params['Icmp.Type'] = icmp_type
749 if port_range_from is not None:
750 params['PortRange.From'] = port_range_from
751 if port_range_to is not None:
752 params['PortRange.To'] = port_range_to
753
754 return self.get_status('ReplaceNetworkAclEntry', params)
755
756 def delete_network_acl_entry(self, network_acl_id, rule_number, egress=None):
757 """
758 Deletes a network ACL entry from a network ACL within a VPC.
759
760 :type network_acl_id: str
761 :param network_acl_id: The ID of the network ACL with the network ACL entry.
762
763 :type rule_number: int
764 :param rule_number: The rule number for the entry to delete.
765
766 :type egress: bool
767 :param egress: Specifies whether the rule to delete is an egress rule (true)
768 or ingress rule (false).
769
770 :rtype: bool
771 :return: True if successful
772 """
773 params = {
774 'NetworkAclId': network_acl_id,
775 'RuleNumber': rule_number
776 }
777
778 if egress is not None:
779 if isinstance(egress, bool):
780 egress = str(egress).lower()
781 params['Egress'] = egress
782
783 return self.get_status('DeleteNetworkAclEntry', params)
784
785 # Internet Gateways
786
787 def get_all_internet_gateways(self, internet_gateway_ids=None,
788 filters=None, dry_run=False):
789 """
790 Get a list of internet gateways. You can filter results to return information
791 about only those gateways that you're interested in.
792
793 :type internet_gateway_ids: list
794 :param internet_gateway_ids: A list of strings with the desired gateway IDs.
795
796 :type filters: list of tuples or dict
797 :param filters: A list of tuples or dict containing filters. Each tuple
798 or dict item consists of a filter key and a filter value.
799
800 :type dry_run: bool
801 :param dry_run: Set to True if the operation should not actually run.
802
803 """
804 params = {}
805
806 if internet_gateway_ids:
807 self.build_list_params(params, internet_gateway_ids,
808 'InternetGatewayId')
809 if filters:
810 self.build_filter_params(params, filters)
811 if dry_run:
812 params['DryRun'] = 'true'
813 return self.get_list('DescribeInternetGateways', params,
814 [('item', InternetGateway)])
815
816 def create_internet_gateway(self, dry_run=False):
817 """
818 Creates an internet gateway for VPC.
819
820 :type dry_run: bool
821 :param dry_run: Set to True if the operation should not actually run.
822
823 :rtype: Newly created internet gateway.
824 :return: `boto.vpc.internetgateway.InternetGateway`
825 """
826 params = {}
827 if dry_run:
828 params['DryRun'] = 'true'
829 return self.get_object('CreateInternetGateway', params, InternetGateway)
830
831 def delete_internet_gateway(self, internet_gateway_id, dry_run=False):
832 """
833 Deletes an internet gateway from the VPC.
834
835 :type internet_gateway_id: str
836 :param internet_gateway_id: The ID of the internet gateway to delete.
837
838 :type dry_run: bool
839 :param dry_run: Set to True if the operation should not actually run.
840
841 :rtype: Bool
842 :return: True if successful
843 """
844 params = {'InternetGatewayId': internet_gateway_id}
845 if dry_run:
846 params['DryRun'] = 'true'
847 return self.get_status('DeleteInternetGateway', params)
848
849 def attach_internet_gateway(self, internet_gateway_id, vpc_id,
850 dry_run=False):
851 """
852 Attach an internet gateway to a specific VPC.
853
854 :type internet_gateway_id: str
855 :param internet_gateway_id: The ID of the internet gateway to attach.
856
857 :type vpc_id: str
858 :param vpc_id: The ID of the VPC to attach to.
859
860 :type dry_run: bool
861 :param dry_run: Set to True if the operation should not actually run.
862
863 :rtype: Bool
864 :return: True if successful
865 """
866 params = {
867 'InternetGatewayId': internet_gateway_id,
868 'VpcId': vpc_id
869 }
870 if dry_run:
871 params['DryRun'] = 'true'
872 return self.get_status('AttachInternetGateway', params)
873
874 def detach_internet_gateway(self, internet_gateway_id, vpc_id,
875 dry_run=False):
876 """
877 Detach an internet gateway from a specific VPC.
878
879 :type internet_gateway_id: str
880 :param internet_gateway_id: The ID of the internet gateway to detach.
881
882 :type vpc_id: str
883 :param vpc_id: The ID of the VPC to attach to.
884
885 :type dry_run: bool
886 :param dry_run: Set to True if the operation should not actually run.
887
888 :rtype: Bool
889 :return: True if successful
890 """
891 params = {
892 'InternetGatewayId': internet_gateway_id,
893 'VpcId': vpc_id
894 }
895 if dry_run:
896 params['DryRun'] = 'true'
897 return self.get_status('DetachInternetGateway', params)
898
899 # Customer Gateways
900
901 def get_all_customer_gateways(self, customer_gateway_ids=None,
902 filters=None, dry_run=False):
903 """
904 Retrieve information about your CustomerGateways. You can filter
905 results to return information only about those CustomerGateways that
906 match your search parameters. Otherwise, all CustomerGateways
907 associated with your account are returned.
908
909 :type customer_gateway_ids: list
910 :param customer_gateway_ids: A list of strings with the desired
911 CustomerGateway ID's.
912
913 :type filters: list of tuples or dict
914 :param filters: A list of tuples or dict containing filters. Each tuple
915 or dict item consists of a filter key and a filter value.
916 Possible filter keys are:
917
918 - *state*, the state of the CustomerGateway
919 (pending,available,deleting,deleted)
920 - *type*, the type of customer gateway (ipsec.1)
921 - *ipAddress* the IP address of customer gateway's
922 internet-routable external inteface
923
924 :type dry_run: bool
925 :param dry_run: Set to True if the operation should not actually run.
926
927 :rtype: list
928 :return: A list of :class:`boto.vpc.customergateway.CustomerGateway`
929 """
930 params = {}
931 if customer_gateway_ids:
932 self.build_list_params(params, customer_gateway_ids,
933 'CustomerGatewayId')
934 if filters:
935 self.build_filter_params(params, filters)
936
937 if dry_run:
938 params['DryRun'] = 'true'
939
940 return self.get_list('DescribeCustomerGateways', params,
941 [('item', CustomerGateway)])
942
943 def create_customer_gateway(self, type, ip_address, bgp_asn, dry_run=False):
944 """
945 Create a new Customer Gateway
946
947 :type type: str
948 :param type: Type of VPN Connection. Only valid value currently is 'ipsec.1'
949
950 :type ip_address: str
951 :param ip_address: Internet-routable IP address for customer's gateway.
952 Must be a static address.
953
954 :type bgp_asn: int
955 :param bgp_asn: Customer gateway's Border Gateway Protocol (BGP)
956 Autonomous System Number (ASN)
957
958 :type dry_run: bool
959 :param dry_run: Set to True if the operation should not actually run.
960
961 :rtype: The newly created CustomerGateway
962 :return: A :class:`boto.vpc.customergateway.CustomerGateway` object
963 """
964 params = {'Type': type,
965 'IpAddress': ip_address,
966 'BgpAsn': bgp_asn}
967 if dry_run:
968 params['DryRun'] = 'true'
969 return self.get_object('CreateCustomerGateway', params, CustomerGateway)
970
971 def delete_customer_gateway(self, customer_gateway_id, dry_run=False):
972 """
973 Delete a Customer Gateway.
974
975 :type customer_gateway_id: str
976 :param customer_gateway_id: The ID of the customer_gateway to be deleted.
977
978 :type dry_run: bool
979 :param dry_run: Set to True if the operation should not actually run.
980
981 :rtype: bool
982 :return: True if successful
983 """
984 params = {'CustomerGatewayId': customer_gateway_id}
985 if dry_run:
986 params['DryRun'] = 'true'
987 return self.get_status('DeleteCustomerGateway', params)
988
989 # VPN Gateways
990
991 def get_all_vpn_gateways(self, vpn_gateway_ids=None, filters=None,
992 dry_run=False):
993 """
994 Retrieve information about your VpnGateways. You can filter results to
995 return information only about those VpnGateways that match your search
996 parameters. Otherwise, all VpnGateways associated with your account
997 are returned.
998
999 :type vpn_gateway_ids: list
1000 :param vpn_gateway_ids: A list of strings with the desired VpnGateway ID's
1001
1002 :type filters: list of tuples or dict
1003 :param filters: A list of tuples or dict containing filters. Each tuple
1004 or dict item consists of a filter key and a filter value.
1005 Possible filter keys are:
1006
1007 - *state*, a list of states of the VpnGateway
1008 (pending,available,deleting,deleted)
1009 - *type*, a list types of customer gateway (ipsec.1)
1010 - *availabilityZone*, a list of Availability zones the
1011 VPN gateway is in.
1012
1013 :type dry_run: bool
1014 :param dry_run: Set to True if the operation should not actually run.
1015
1016 :rtype: list
1017 :return: A list of :class:`boto.vpc.customergateway.VpnGateway`
1018 """
1019 params = {}
1020 if vpn_gateway_ids:
1021 self.build_list_params(params, vpn_gateway_ids, 'VpnGatewayId')
1022 if filters:
1023 self.build_filter_params(params, filters)
1024 if dry_run:
1025 params['DryRun'] = 'true'
1026 return self.get_list('DescribeVpnGateways', params,
1027 [('item', VpnGateway)])
1028
1029 def create_vpn_gateway(self, type, availability_zone=None, dry_run=False):
1030 """
1031 Create a new Vpn Gateway
1032
1033 :type type: str
1034 :param type: Type of VPN Connection. Only valid value currently is 'ipsec.1'
1035
1036 :type availability_zone: str
1037 :param availability_zone: The Availability Zone where you want the VPN gateway.
1038
1039 :type dry_run: bool
1040 :param dry_run: Set to True if the operation should not actually run.
1041
1042 :rtype: The newly created VpnGateway
1043 :return: A :class:`boto.vpc.vpngateway.VpnGateway` object
1044 """
1045 params = {'Type': type}
1046 if availability_zone:
1047 params['AvailabilityZone'] = availability_zone
1048 if dry_run:
1049 params['DryRun'] = 'true'
1050 return self.get_object('CreateVpnGateway', params, VpnGateway)
1051
1052 def delete_vpn_gateway(self, vpn_gateway_id, dry_run=False):
1053 """
1054 Delete a Vpn Gateway.
1055
1056 :type vpn_gateway_id: str
1057 :param vpn_gateway_id: The ID of the vpn_gateway to be deleted.
1058
1059 :type dry_run: bool
1060 :param dry_run: Set to True if the operation should not actually run.
1061
1062 :rtype: bool
1063 :return: True if successful
1064 """
1065 params = {'VpnGatewayId': vpn_gateway_id}
1066 if dry_run:
1067 params['DryRun'] = 'true'
1068 return self.get_status('DeleteVpnGateway', params)
1069
1070 def attach_vpn_gateway(self, vpn_gateway_id, vpc_id, dry_run=False):
1071 """
1072 Attaches a VPN gateway to a VPC.
1073
1074 :type vpn_gateway_id: str
1075 :param vpn_gateway_id: The ID of the vpn_gateway to attach
1076
1077 :type vpc_id: str
1078 :param vpc_id: The ID of the VPC you want to attach the gateway to.
1079
1080 :type dry_run: bool
1081 :param dry_run: Set to True if the operation should not actually run.
1082
1083 :rtype: An attachment
1084 :return: a :class:`boto.vpc.vpngateway.Attachment`
1085 """
1086 params = {'VpnGatewayId': vpn_gateway_id,
1087 'VpcId': vpc_id}
1088 if dry_run:
1089 params['DryRun'] = 'true'
1090 return self.get_object('AttachVpnGateway', params, Attachment)
1091
1092 def detach_vpn_gateway(self, vpn_gateway_id, vpc_id, dry_run=False):
1093 """
1094 Detaches a VPN gateway from a VPC.
1095
1096 :type vpn_gateway_id: str
1097 :param vpn_gateway_id: The ID of the vpn_gateway to detach
1098
1099 :type vpc_id: str
1100 :param vpc_id: The ID of the VPC you want to detach the gateway from.
1101
1102 :type dry_run: bool
1103 :param dry_run: Set to True if the operation should not actually run.
1104
1105 :rtype: bool
1106 :return: True if successful
1107 """
1108 params = {'VpnGatewayId': vpn_gateway_id,
1109 'VpcId': vpc_id}
1110 if dry_run:
1111 params['DryRun'] = 'true'
1112 return self.get_status('DetachVpnGateway', params)
1113
1114 # Subnets
1115
1116 def get_all_subnets(self, subnet_ids=None, filters=None, dry_run=False):
1117 """
1118 Retrieve information about your Subnets. You can filter results to
1119 return information only about those Subnets that match your search
1120 parameters. Otherwise, all Subnets associated with your account
1121 are returned.
1122
1123 :type subnet_ids: list
1124 :param subnet_ids: A list of strings with the desired Subnet ID's
1125
1126 :type filters: list of tuples or dict
1127 :param filters: A list of tuples or dict containing filters. Each tuple
1128 or dict item consists of a filter key and a filter value.
1129 Possible filter keys are:
1130
1131 - *state*, a list of states of the Subnet
1132 (pending,available)
1133 - *vpcId*, a list of IDs of the VPC that the subnet is in.
1134 - *cidrBlock*, a list of CIDR blocks of the subnet
1135 - *availabilityZone*, list of the Availability Zones
1136 the subnet is in.
1137
1138
1139 :type dry_run: bool
1140 :param dry_run: Set to True if the operation should not actually run.
1141
1142 :rtype: list
1143 :return: A list of :class:`boto.vpc.subnet.Subnet`
1144 """
1145 params = {}
1146 if subnet_ids:
1147 self.build_list_params(params, subnet_ids, 'SubnetId')
1148 if filters:
1149 self.build_filter_params(params, filters)
1150 if dry_run:
1151 params['DryRun'] = 'true'
1152 return self.get_list('DescribeSubnets', params, [('item', Subnet)])
1153
1154 def create_subnet(self, vpc_id, cidr_block, availability_zone=None,
1155 dry_run=False):
1156 """
1157 Create a new Subnet
1158
1159 :type vpc_id: str
1160 :param vpc_id: The ID of the VPC where you want to create the subnet.
1161
1162 :type cidr_block: str
1163 :param cidr_block: The CIDR block you want the subnet to cover.
1164
1165 :type availability_zone: str
1166 :param availability_zone: The AZ you want the subnet in
1167
1168 :type dry_run: bool
1169 :param dry_run: Set to True if the operation should not actually run.
1170
1171 :rtype: The newly created Subnet
1172 :return: A :class:`boto.vpc.customergateway.Subnet` object
1173 """
1174 params = {'VpcId': vpc_id,
1175 'CidrBlock': cidr_block}
1176 if availability_zone:
1177 params['AvailabilityZone'] = availability_zone
1178 if dry_run:
1179 params['DryRun'] = 'true'
1180 return self.get_object('CreateSubnet', params, Subnet)
1181
1182 def delete_subnet(self, subnet_id, dry_run=False):
1183 """
1184 Delete a subnet.
1185
1186 :type subnet_id: str
1187 :param subnet_id: The ID of the subnet to be deleted.
1188
1189 :type dry_run: bool
1190 :param dry_run: Set to True if the operation should not actually run.
1191
1192 :rtype: bool
1193 :return: True if successful
1194 """
1195 params = {'SubnetId': subnet_id}
1196 if dry_run:
1197 params['DryRun'] = 'true'
1198 return self.get_status('DeleteSubnet', params)
1199
1200 # DHCP Options
1201
1202 def get_all_dhcp_options(self, dhcp_options_ids=None, filters=None, dry_run=False):
1203 """
1204 Retrieve information about your DhcpOptions.
1205
1206 :type dhcp_options_ids: list
1207 :param dhcp_options_ids: A list of strings with the desired DhcpOption ID's
1208
1209 :type filters: list of tuples or dict
1210 :param filters: A list of tuples or dict containing filters. Each tuple
1211 or dict item consists of a filter key and a filter value.
1212
1213 :type dry_run: bool
1214 :param dry_run: Set to True if the operation should not actually run.
1215
1216 :rtype: list
1217 :return: A list of :class:`boto.vpc.dhcpoptions.DhcpOptions`
1218 """
1219 params = {}
1220 if dhcp_options_ids:
1221 self.build_list_params(params, dhcp_options_ids, 'DhcpOptionsId')
1222 if filters:
1223 self.build_filter_params(params, filters)
1224 if dry_run:
1225 params['DryRun'] = 'true'
1226 return self.get_list('DescribeDhcpOptions', params,
1227 [('item', DhcpOptions)])
1228
1229 def create_dhcp_options(self, domain_name=None, domain_name_servers=None,
1230 ntp_servers=None, netbios_name_servers=None,
1231 netbios_node_type=None, dry_run=False):
1232 """
1233 Create a new DhcpOption
1234
1235 This corresponds to
1236 http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateDhcpOptions.html
1237
1238 :type domain_name: str
1239 :param domain_name: A domain name of your choice (for example,
1240 example.com)
1241
1242 :type domain_name_servers: list of strings
1243 :param domain_name_servers: The IP address of a domain name server. You
1244 can specify up to four addresses.
1245
1246 :type ntp_servers: list of strings
1247 :param ntp_servers: The IP address of a Network Time Protocol (NTP)
1248 server. You can specify up to four addresses.
1249
1250 :type netbios_name_servers: list of strings
1251 :param netbios_name_servers: The IP address of a NetBIOS name server.
1252 You can specify up to four addresses.
1253
1254 :type netbios_node_type: str
1255 :param netbios_node_type: The NetBIOS node type (1, 2, 4, or 8). For
1256 more information about the values, see RFC 2132. We recommend you
1257 only use 2 at this time (broadcast and multicast are currently not
1258 supported).
1259
1260 :type dry_run: bool
1261 :param dry_run: Set to True if the operation should not actually run.
1262
1263 :rtype: The newly created DhcpOption
1264 :return: A :class:`boto.vpc.customergateway.DhcpOption` object
1265 """
1266
1267 key_counter = 1
1268 params = {}
1269
1270 def insert_option(params, name, value):
1271 params['DhcpConfiguration.%d.Key' % (key_counter,)] = name
1272 if isinstance(value, (list, tuple)):
1273 for idx, value in enumerate(value, 1):
1274 key_name = 'DhcpConfiguration.%d.Value.%d' % (
1275 key_counter, idx)
1276 params[key_name] = value
1277 else:
1278 key_name = 'DhcpConfiguration.%d.Value.1' % (key_counter,)
1279 params[key_name] = value
1280
1281 return key_counter + 1
1282
1283 if domain_name:
1284 key_counter = insert_option(params,
1285 'domain-name', domain_name)
1286 if domain_name_servers:
1287 key_counter = insert_option(params,
1288 'domain-name-servers', domain_name_servers)
1289 if ntp_servers:
1290 key_counter = insert_option(params,
1291 'ntp-servers', ntp_servers)
1292 if netbios_name_servers:
1293 key_counter = insert_option(params,
1294 'netbios-name-servers', netbios_name_servers)
1295 if netbios_node_type:
1296 key_counter = insert_option(params,
1297 'netbios-node-type', netbios_node_type)
1298 if dry_run:
1299 params['DryRun'] = 'true'
1300
1301 return self.get_object('CreateDhcpOptions', params, DhcpOptions)
1302
1303 def delete_dhcp_options(self, dhcp_options_id, dry_run=False):
1304 """
1305 Delete a DHCP Options
1306
1307 :type dhcp_options_id: str
1308 :param dhcp_options_id: The ID of the DHCP Options to be deleted.
1309
1310 :type dry_run: bool
1311 :param dry_run: Set to True if the operation should not actually run.
1312
1313 :rtype: bool
1314 :return: True if successful
1315 """
1316 params = {'DhcpOptionsId': dhcp_options_id}
1317 if dry_run:
1318 params['DryRun'] = 'true'
1319 return self.get_status('DeleteDhcpOptions', params)
1320
1321 def associate_dhcp_options(self, dhcp_options_id, vpc_id, dry_run=False):
1322 """
1323 Associate a set of Dhcp Options with a VPC.
1324
1325 :type dhcp_options_id: str
1326 :param dhcp_options_id: The ID of the Dhcp Options
1327
1328 :type vpc_id: str
1329 :param vpc_id: The ID of the VPC.
1330
1331 :type dry_run: bool
1332 :param dry_run: Set to True if the operation should not actually run.
1333
1334 :rtype: bool
1335 :return: True if successful
1336 """
1337 params = {'DhcpOptionsId': dhcp_options_id,
1338 'VpcId': vpc_id}
1339 if dry_run:
1340 params['DryRun'] = 'true'
1341 return self.get_status('AssociateDhcpOptions', params)
1342
1343 # VPN Connection
1344
1345 def get_all_vpn_connections(self, vpn_connection_ids=None, filters=None,
1346 dry_run=False):
1347 """
1348 Retrieve information about your VPN_CONNECTIONs. You can filter results to
1349 return information only about those VPN_CONNECTIONs that match your search
1350 parameters. Otherwise, all VPN_CONNECTIONs associated with your account
1351 are returned.
1352
1353 :type vpn_connection_ids: list
1354 :param vpn_connection_ids: A list of strings with the desired VPN_CONNECTION ID's
1355
1356 :type filters: list of tuples or dict
1357 :param filters: A list of tuples or dict containing filters. Each tuple
1358 or dict item consists of a filter key and a filter value.
1359 Possible filter keys are:
1360
1361 - *state*, a list of states of the VPN_CONNECTION
1362 pending,available,deleting,deleted
1363 - *type*, a list of types of connection, currently 'ipsec.1'
1364 - *customerGatewayId*, a list of IDs of the customer gateway
1365 associated with the VPN
1366 - *vpnGatewayId*, a list of IDs of the VPN gateway associated
1367 with the VPN connection
1368
1369 :type dry_run: bool
1370 :param dry_run: Set to True if the operation should not actually run.
1371
1372 :rtype: list
1373 :return: A list of :class:`boto.vpn_connection.vpnconnection.VpnConnection`
1374 """
1375 params = {}
1376 if vpn_connection_ids:
1377 self.build_list_params(params, vpn_connection_ids,
1378 'VpnConnectionId')
1379 if filters:
1380 self.build_filter_params(params, filters)
1381 if dry_run:
1382 params['DryRun'] = 'true'
1383 return self.get_list('DescribeVpnConnections', params,
1384 [('item', VpnConnection)])
1385
1386 def create_vpn_connection(self, type, customer_gateway_id, vpn_gateway_id,
1387 static_routes_only=None, dry_run=False):
1388 """
1389 Create a new VPN Connection.
1390
1391 :type type: str
1392 :param type: The type of VPN Connection. Currently only 'ipsec.1'
1393 is supported
1394
1395 :type customer_gateway_id: str
1396 :param customer_gateway_id: The ID of the customer gateway.
1397
1398 :type vpn_gateway_id: str
1399 :param vpn_gateway_id: The ID of the VPN gateway.
1400
1401 :type static_routes_only: bool
1402 :param static_routes_only: Indicates whether the VPN connection
1403 requires static routes. If you are creating a VPN connection
1404 for a device that does not support BGP, you must specify true.
1405
1406 :type dry_run: bool
1407 :param dry_run: Set to True if the operation should not actually run.
1408
1409 :rtype: The newly created VpnConnection
1410 :return: A :class:`boto.vpc.vpnconnection.VpnConnection` object
1411 """
1412 params = {'Type': type,
1413 'CustomerGatewayId': customer_gateway_id,
1414 'VpnGatewayId': vpn_gateway_id}
1415 if static_routes_only is not None:
1416 if isinstance(static_routes_only, bool):
1417 static_routes_only = str(static_routes_only).lower()
1418 params['Options.StaticRoutesOnly'] = static_routes_only
1419 if dry_run:
1420 params['DryRun'] = 'true'
1421 return self.get_object('CreateVpnConnection', params, VpnConnection)
1422
1423 def delete_vpn_connection(self, vpn_connection_id, dry_run=False):
1424 """
1425 Delete a VPN Connection.
1426
1427 :type vpn_connection_id: str
1428 :param vpn_connection_id: The ID of the vpn_connection to be deleted.
1429
1430 :type dry_run: bool
1431 :param dry_run: Set to True if the operation should not actually run.
1432
1433 :rtype: bool
1434 :return: True if successful
1435 """
1436 params = {'VpnConnectionId': vpn_connection_id}
1437 if dry_run:
1438 params['DryRun'] = 'true'
1439 return self.get_status('DeleteVpnConnection', params)
1440
1441 def disable_vgw_route_propagation(self, route_table_id, gateway_id,
1442 dry_run=False):
1443 """
1444 Disables a virtual private gateway (VGW) from propagating routes to the
1445 routing tables of an Amazon VPC.
1446
1447 :type route_table_id: str
1448 :param route_table_id: The ID of the routing table.
1449
1450 :type gateway_id: str
1451 :param gateway_id: The ID of the virtual private gateway.
1452
1453 :type dry_run: bool
1454 :param dry_run: Set to True if the operation should not actually run.
1455
1456 :rtype: bool
1457 :return: True if successful
1458 """
1459 params = {
1460 'RouteTableId': route_table_id,
1461 'GatewayId': gateway_id,
1462 }
1463 if dry_run:
1464 params['DryRun'] = 'true'
1465 return self.get_status('DisableVgwRoutePropagation', params)
1466
1467 def enable_vgw_route_propagation(self, route_table_id, gateway_id,
1468 dry_run=False):
1469 """
1470 Enables a virtual private gateway (VGW) to propagate routes to the
1471 routing tables of an Amazon VPC.
1472
1473 :type route_table_id: str
1474 :param route_table_id: The ID of the routing table.
1475
1476 :type gateway_id: str
1477 :param gateway_id: The ID of the virtual private gateway.
1478
1479 :type dry_run: bool
1480 :param dry_run: Set to True if the operation should not actually run.
1481
1482 :rtype: bool
1483 :return: True if successful
1484 """
1485 params = {
1486 'RouteTableId': route_table_id,
1487 'GatewayId': gateway_id,
1488 }
1489 if dry_run:
1490 params['DryRun'] = 'true'
1491 return self.get_status('EnableVgwRoutePropagation', params)
1492
1493 def create_vpn_connection_route(self, destination_cidr_block,
1494 vpn_connection_id, dry_run=False):
1495 """
1496 Creates a new static route associated with a VPN connection between an
1497 existing virtual private gateway and a VPN customer gateway. The static
1498 route allows traffic to be routed from the virtual private gateway to
1499 the VPN customer gateway.
1500
1501 :type destination_cidr_block: str
1502 :param destination_cidr_block: The CIDR block associated with the local
1503 subnet of the customer data center.
1504
1505 :type vpn_connection_id: str
1506 :param vpn_connection_id: The ID of the VPN connection.
1507
1508 :type dry_run: bool
1509 :param dry_run: Set to True if the operation should not actually run.
1510
1511 :rtype: bool
1512 :return: True if successful
1513 """
1514 params = {
1515 'DestinationCidrBlock': destination_cidr_block,
1516 'VpnConnectionId': vpn_connection_id,
1517 }
1518 if dry_run:
1519 params['DryRun'] = 'true'
1520 return self.get_status('CreateVpnConnectionRoute', params)
1521
1522 def delete_vpn_connection_route(self, destination_cidr_block,
1523 vpn_connection_id, dry_run=False):
1524 """
1525 Deletes a static route associated with a VPN connection between an
1526 existing virtual private gateway and a VPN customer gateway. The static
1527 route allows traffic to be routed from the virtual private gateway to
1528 the VPN customer gateway.
1529
1530 :type destination_cidr_block: str
1531 :param destination_cidr_block: The CIDR block associated with the local
1532 subnet of the customer data center.
1533
1534 :type vpn_connection_id: str
1535 :param vpn_connection_id: The ID of the VPN connection.
1536
1537 :type dry_run: bool
1538 :param dry_run: Set to True if the operation should not actually run.
1539
1540 :rtype: bool
1541 :return: True if successful
1542 """
1543 params = {
1544 'DestinationCidrBlock': destination_cidr_block,
1545 'VpnConnectionId': vpn_connection_id,
1546 }
1547 if dry_run:
1548 params['DryRun'] = 'true'
1549 return self.get_status('DeleteVpnConnectionRoute', params)
1550
1551 def get_all_vpc_peering_connections(self, vpc_peering_connection_ids=None,
1552 filters=None, dry_run=False):
1553 """
1554 Retrieve information about your VPC peering connections. You
1555 can filter results to return information only about those VPC
1556 peering connections that match your search parameters.
1557 Otherwise, all VPC peering connections associated with your
1558 account are returned.
1559
1560 :type vpc_peering_connection_ids: list
1561 :param vpc_peering_connection_ids: A list of strings with the desired VPC
1562 peering connection ID's
1563
1564 :type filters: list of tuples
1565 :param filters: A list of tuples containing filters. Each tuple
1566 consists of a filter key and a filter value.
1567 Possible filter keys are:
1568
1569 * *accepter-vpc-info.cidr-block* - The CIDR block of the peer VPC.
1570 * *accepter-vpc-info.owner-id* - The AWS account ID of the owner
1571 of the peer VPC.
1572 * *accepter-vpc-info.vpc-id* - The ID of the peer VPC.
1573 * *expiration-time* - The expiration date and time for the VPC
1574 peering connection.
1575 * *requester-vpc-info.cidr-block* - The CIDR block of the
1576 requester's VPC.
1577 * *requester-vpc-info.owner-id* - The AWS account ID of the
1578 owner of the requester VPC.
1579 * *requester-vpc-info.vpc-id* - The ID of the requester VPC.
1580 * *status-code* - The status of the VPC peering connection.
1581 * *status-message* - A message that provides more information
1582 about the status of the VPC peering connection, if applicable.
1583
1584 :type dry_run: bool
1585 :param dry_run: Set to True if the operation should not actually run.
1586
1587 :rtype: list
1588 :return: A list of :class:`boto.vpc.vpc.VPC`
1589 """
1590 params = {}
1591 if vpc_peering_connection_ids:
1592 self.build_list_params(params, vpc_peering_connection_ids, 'VpcPeeringConnectionId')
1593 if filters:
1594 self.build_filter_params(params, dict(filters))
1595 if dry_run:
1596 params['DryRun'] = 'true'
1597 return self.get_list('DescribeVpcPeeringConnections', params, [('item', VpcPeeringConnection)])
1598
1599 def create_vpc_peering_connection(self, vpc_id, peer_vpc_id,
1600 peer_owner_id=None, dry_run=False):
1601 """
1602 Create a new VPN Peering connection.
1603
1604 :type vpc_id: str
1605 :param vpc_id: The ID of the requester VPC.
1606
1607 :type peer_vpc_id: str
1608 :param vpc_peer_id: The ID of the VPC with which you are creating the peering connection.
1609
1610 :type peer_owner_id: str
1611 :param peer_owner_id: The AWS account ID of the owner of the peer VPC.
1612
1613 :rtype: The newly created VpcPeeringConnection
1614 :return: A :class:`boto.vpc.vpc_peering_connection.VpcPeeringConnection` object
1615 """
1616 params = {'VpcId': vpc_id,
1617 'PeerVpcId': peer_vpc_id }
1618 if peer_owner_id is not None:
1619 params['PeerOwnerId'] = peer_owner_id
1620 if dry_run:
1621 params['DryRun'] = 'true'
1622
1623 return self.get_object('CreateVpcPeeringConnection', params,
1624 VpcPeeringConnection)
1625
1626 def delete_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):
1627 """
1628 Deletes a VPC peering connection. Either the owner of the requester
1629 VPC or the owner of the peer VPC can delete the VPC peering connection
1630 if it's in the active state. The owner of the requester VPC can delete
1631 a VPC peering connection in the pending-acceptance state.
1632
1633 :type vpc_peering_connection_id: str
1634 :param vpc_peering_connection_id: The ID of the VPC peering connection.
1635
1636 :rtype: bool
1637 :return: True if successful
1638 """
1639 params = {
1640 'VpcPeeringConnectionId': vpc_peering_connection_id
1641 }
1642
1643 if dry_run:
1644 params['DryRun'] = 'true'
1645 return self.get_status('DeleteVpcPeeringConnection', params)
1646
1647 def reject_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):
1648 """
1649 Rejects a VPC peering connection request. The VPC peering connection
1650 must be in the pending-acceptance state.
1651
1652 :type vpc_peering_connection_id: str
1653 :param vpc_peering_connection_id: The ID of the VPC peering connection.
1654
1655 :rtype: bool
1656 :return: True if successful
1657 """
1658 params = {
1659 'VpcPeeringConnectionId': vpc_peering_connection_id
1660 }
1661
1662 if dry_run:
1663 params['DryRun'] = 'true'
1664 return self.get_status('RejectVpcPeeringConnection', params)
1665
1666 def accept_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):
1667 """
1668 Acceptss a VPC peering connection request. The VPC peering connection
1669 must be in the pending-acceptance state.
1670
1671 :type vpc_peering_connection_id: str
1672 :param vpc_peering_connection_id: The ID of the VPC peering connection.
1673
1674 :rtype: Accepted VpcPeeringConnection
1675 :return: A :class:`boto.vpc.vpc_peering_connection.VpcPeeringConnection` object
1676 """
1677 params = {
1678 'VpcPeeringConnectionId': vpc_peering_connection_id
1679 }
1680
1681 if dry_run:
1682 params['DryRun'] = 'true'
1683
1684 return self.get_object('AcceptVpcPeeringConnection', params,
1685 VpcPeeringConnection)
1686
1687 def get_all_classic_link_vpcs(self, vpc_ids=None, filters=None,
1688 dry_run=False):
1689 """
1690 Describes the ClassicLink status of one or more VPCs.
1691
1692 :type vpc_ids: list
1693 :param vpc_ids: A list of strings with the desired VPC ID's
1694
1695 :type dry_run: bool
1696 :param dry_run: Set to True if the operation should not actually run.
1697
1698 :type filters: list of tuples or dict
1699 :param filters: A list of tuples or dict containing filters. Each tuple
1700 or dict item consists of a filter key and a filter value.
1701
1702 :rtype: list
1703 :return: A list of :class:`boto.vpc.vpc.VPC`
1704 """
1705 params = {}
1706 if vpc_ids:
1707 self.build_list_params(params, vpc_ids, 'VpcId')
1708 if filters:
1709 self.build_filter_params(params, filters)
1710 if dry_run:
1711 params['DryRun'] = 'true'
1712 return self.get_list('DescribeVpcClassicLink', params, [('item', VPC)],
1713 verb='POST')
1714
1715 def attach_classic_link_vpc(self, vpc_id, instance_id, groups,
1716 dry_run=False):
1717 """
1718 Links an EC2-Classic instance to a ClassicLink-enabled VPC through one
1719 or more of the VPC's security groups. You cannot link an EC2-Classic
1720 instance to more than one VPC at a time. You can only link an instance
1721 that's in the running state. An instance is automatically unlinked from
1722 a VPC when it's stopped. You can link it to the VPC again when you
1723 restart it.
1724
1725 After you've linked an instance, you cannot change the VPC security
1726 groups that are associated with it. To change the security groups, you
1727 must first unlink the instance, and then link it again.
1728
1729 Linking your instance to a VPC is sometimes referred to as attaching
1730 your instance.
1731
1732 :type vpc_id: str
1733 :param vpc_id: The ID of a ClassicLink-enabled VPC.
1734
1735 :type intance_id: str
1736 :param instance_is: The ID of a ClassicLink-enabled VPC.
1737
1738 :tye groups: list
1739 :param groups: The ID of one or more of the VPC's security groups.
1740 You cannot specify security groups from a different VPC. The
1741 members of the list can be
1742 :class:`boto.ec2.securitygroup.SecurityGroup` objects or
1743 strings of the id's of the security groups.
1744
1745 :type dry_run: bool
1746 :param dry_run: Set to True if the operation should not actually run.
1747
1748 :rtype: bool
1749 :return: True if successful
1750 """
1751 params = {'VpcId': vpc_id, 'InstanceId': instance_id}
1752 if dry_run:
1753 params['DryRun'] = 'true'
1754 l = []
1755 for group in groups:
1756 if hasattr(group, 'id'):
1757 l.append(group.id)
1758 else:
1759 l.append(group)
1760 self.build_list_params(params, l, 'SecurityGroupId')
1761 return self.get_status('AttachClassicLinkVpc', params)
1762
1763 def detach_classic_link_vpc(self, vpc_id, instance_id, dry_run=False):
1764 """
1765 Unlinks a linked EC2-Classic instance from a VPC. After the instance
1766 has been unlinked, the VPC security groups are no longer associated
1767 with it. An instance is automatically unlinked from a VPC when
1768 it's stopped.
1769
1770 :type vpc_id: str
1771 :param vpc_id: The ID of the instance to unlink from the VPC.
1772
1773 :type intance_id: str
1774 :param instance_is: The ID of the VPC to which the instance is linked.
1775
1776 :type dry_run: bool
1777 :param dry_run: Set to True if the operation should not actually run.
1778
1779 :rtype: bool
1780 :return: True if successful
1781 """
1782 params = {'VpcId': vpc_id, 'InstanceId': instance_id}
1783 if dry_run:
1784 params['DryRun'] = 'true'
1785 return self.get_status('DetachClassicLinkVpc', params)
1786
1787 def disable_vpc_classic_link(self, vpc_id, dry_run=False):
1788 """
1789 Disables ClassicLink for a VPC. You cannot disable ClassicLink for a
1790 VPC that has EC2-Classic instances linked to it.
1791
1792 :type vpc_id: str
1793 :param vpc_id: The ID of the VPC.
1794
1795 :type dry_run: bool
1796 :param dry_run: Set to True if the operation should not actually run.
1797
1798 :rtype: bool
1799 :return: True if successful
1800 """
1801 params = {'VpcId': vpc_id}
1802 if dry_run:
1803 params['DryRun'] = 'true'
1804 return self.get_status('DisableVpcClassicLink', params)
1805
1806 def enable_vpc_classic_link(self, vpc_id, dry_run=False):
1807 """
1808 Enables a VPC for ClassicLink. You can then link EC2-Classic instances
1809 to your ClassicLink-enabled VPC to allow communication over private IP
1810 addresses. You cannot enable your VPC for ClassicLink if any of your
1811 VPC's route tables have existing routes for address ranges within the
1812 10.0.0.0/8 IP address range, excluding local routes for VPCs in the
1813 10.0.0.0/16 and 10.1.0.0/16 IP address ranges.
1814
1815 :type vpc_id: str
1816 :param vpc_id: The ID of the VPC.
1817
1818 :type dry_run: bool
1819 :param dry_run: Set to True if the operation should not actually run.
1820
1821 :rtype: bool
1822 :return: True if successful
1823 """
1824 params = {'VpcId': vpc_id}
1825 if dry_run:
1826 params['DryRun'] = 'true'
1827 return self.get_status('EnableVpcClassicLink', params)