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