Best Python code snippet using tempest_python
__init__.py
Source:__init__.py  
1# Copyright (c) 2009 Mitch Garnaat http://garnaat.org/2#3# Permission is hereby granted, free of charge, to any person obtaining a4# copy of this software and associated documentation files (the5# "Software"), to deal in the Software without restriction, including6# without limitation the rights to use, copy, modify, merge, publish, dis-7# tribute, sublicense, and/or sell copies of the Software, and to permit8# 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 included12# in all copies or substantial portions of the Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS15# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-16# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT17# 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 DEALINGS20# IN THE SOFTWARE.21"""22Represents a connection to the EC2 service.23"""24from boto.ec2.connection import EC2Connection25from boto.resultset import ResultSet26from boto.vpc.vpc import VPC27from boto.vpc.customergateway import CustomerGateway28from boto.vpc.networkacl import NetworkAcl29from boto.vpc.routetable import RouteTable30from boto.vpc.internetgateway import InternetGateway31from boto.vpc.vpngateway import VpnGateway, Attachment32from boto.vpc.dhcpoptions import DhcpOptions33from boto.vpc.subnet import Subnet34from boto.vpc.vpnconnection import VpnConnection35from boto.vpc.vpc_peering_connection import VpcPeeringConnection36from boto.ec2 import RegionData37from boto.regioninfo import RegionInfo, get_regions38from boto.regioninfo import connect39def regions(**kw_params):40    """41    Get all available regions for the EC2 service.42    You may pass any of the arguments accepted by the VPCConnection43    object's constructor as keyword arguments and they will be44    passed along to the VPCConnection object.45    :rtype: list46    :return: A list of :class:`boto.ec2.regioninfo.RegionInfo`47    """48    return get_regions('ec2', connection_cls=VPCConnection)49def connect_to_region(region_name, **kw_params):50    """51    Given a valid region name, return a52    :class:`boto.vpc.VPCConnection`.53    Any additional parameters after the region_name are passed on to54    the connect method of the region object.55    :type: str56    :param region_name: The name of the region to connect to.57    :rtype: :class:`boto.vpc.VPCConnection` or ``None``58    :return: A connection to the given region, or None if an invalid region59             name is given60    """61    return connect('ec2', region_name, connection_cls=VPCConnection,62                   **kw_params)63class VPCConnection(EC2Connection):64    # VPC methods65    def get_all_vpcs(self, vpc_ids=None, filters=None, dry_run=False):66        """67        Retrieve information about your VPCs.  You can filter results to68        return information only about those VPCs that match your search69        parameters.  Otherwise, all VPCs associated with your account70        are returned.71        :type vpc_ids: list72        :param vpc_ids: A list of strings with the desired VPC ID's73        :type filters: list of tuples or dict74        :param filters: A list of tuples or dict containing filters.  Each tuple75            or dict item consists of a filter key and a filter value.76            Possible filter keys are:77            * *state* - a list of states of the VPC (pending or available)78            * *cidrBlock* - a list CIDR blocks of the VPC79            * *dhcpOptionsId* - a list of IDs of a set of DHCP options80        :type dry_run: bool81        :param dry_run: Set to True if the operation should not actually run.82        :rtype: list83        :return: A list of :class:`boto.vpc.vpc.VPC`84        """85        params = {}86        if vpc_ids:87            self.build_list_params(params, vpc_ids, 'VpcId')88        if filters:89            self.build_filter_params(params, filters)90        if dry_run:91            params['DryRun'] = 'true'92        return self.get_list('DescribeVpcs', params, [('item', VPC)])93    def create_vpc(self, cidr_block, instance_tenancy=None, dry_run=False):94        """95        Create a new Virtual Private Cloud.96        :type cidr_block: str97        :param cidr_block: A valid CIDR block98        :type instance_tenancy: str99        :param instance_tenancy: The supported tenancy options for instances100            launched into the VPC. Valid values are 'default' and 'dedicated'.101        :type dry_run: bool102        :param dry_run: Set to True if the operation should not actually run.103        :rtype: The newly created VPC104        :return: A :class:`boto.vpc.vpc.VPC` object105        """106        params = {'CidrBlock': cidr_block}107        if instance_tenancy:108            params['InstanceTenancy'] = instance_tenancy109        if dry_run:110            params['DryRun'] = 'true'111        return self.get_object('CreateVpc', params, VPC)112    def delete_vpc(self, vpc_id, dry_run=False):113        """114        Delete a Virtual Private Cloud.115        :type vpc_id: str116        :param vpc_id: The ID of the vpc to be deleted.117        :type dry_run: bool118        :param dry_run: Set to True if the operation should not actually run.119        :rtype: bool120        :return: True if successful121        """122        params = {'VpcId': vpc_id}123        if dry_run:124            params['DryRun'] = 'true'125        return self.get_status('DeleteVpc', params)126    def modify_vpc_attribute(self, vpc_id,127                             enable_dns_support=None,128                             enable_dns_hostnames=None, dry_run=False):129        """130        Modifies the specified attribute of the specified VPC.131        You can only modify one attribute at a time.132        :type vpc_id: str133        :param vpc_id: The ID of the vpc to be deleted.134        :type enable_dns_support: bool135        :param enable_dns_support: Specifies whether the DNS server136            provided by Amazon is enabled for the VPC.137        :type enable_dns_hostnames: bool138        :param enable_dns_hostnames: Specifies whether DNS hostnames are139            provided for the instances launched in this VPC. You can only140            set this attribute to ``true`` if EnableDnsSupport141            is also ``true``.142        :type dry_run: bool143        :param dry_run: Set to True if the operation should not actually run.144        """145        params = {'VpcId': vpc_id}146        if enable_dns_support is not None:147            if enable_dns_support:148                params['EnableDnsSupport.Value'] = 'true'149            else:150                params['EnableDnsSupport.Value'] = 'false'151        if enable_dns_hostnames is not None:152            if enable_dns_hostnames:153                params['EnableDnsHostnames.Value'] = 'true'154            else:155                params['EnableDnsHostnames.Value'] = 'false'156        if dry_run:157            params['DryRun'] = 'true'158        return self.get_status('ModifyVpcAttribute', params)159    # Route Tables160    def get_all_route_tables(self, route_table_ids=None, filters=None,161                             dry_run=False):162        """163        Retrieve information about your routing tables. You can filter results164        to return information only about those route tables that match your165        search parameters. Otherwise, all route tables associated with your166        account are returned.167        :type route_table_ids: list168        :param route_table_ids: A list of strings with the desired route table169                                IDs.170        :type filters: list of tuples or dict171        :param filters: A list of tuples or dict containing filters. Each tuple172                        or dict item consists of a filter key and a filter value.173        :type dry_run: bool174        :param dry_run: Set to True if the operation should not actually run.175        :rtype: list176        :return: A list of :class:`boto.vpc.routetable.RouteTable`177        """178        params = {}179        if route_table_ids:180            self.build_list_params(params, route_table_ids, "RouteTableId")181        if filters:182            self.build_filter_params(params, filters)183        if dry_run:184            params['DryRun'] = 'true'185        return self.get_list('DescribeRouteTables', params,186                             [('item', RouteTable)])187    def associate_route_table(self, route_table_id, subnet_id, dry_run=False):188        """189        Associates a route table with a specific subnet.190        :type route_table_id: str191        :param route_table_id: The ID of the route table to associate.192        :type subnet_id: str193        :param subnet_id: The ID of the subnet to associate with.194        :type dry_run: bool195        :param dry_run: Set to True if the operation should not actually run.196        :rtype: str197        :return: The ID of the association created198        """199        params = {200            'RouteTableId': route_table_id,201            'SubnetId': subnet_id202        }203        if dry_run:204            params['DryRun'] = 'true'205        result = self.get_object('AssociateRouteTable', params, ResultSet)206        return result.associationId207    def disassociate_route_table(self, association_id, dry_run=False):208        """209        Removes an association from a route table. This will cause all subnets210        that would've used this association to now use the main routing211        association instead.212        :type association_id: str213        :param association_id: The ID of the association to disassociate.214        :type dry_run: bool215        :param dry_run: Set to True if the operation should not actually run.216        :rtype: bool217        :return: True if successful218        """219        params = {'AssociationId': association_id}220        if dry_run:221            params['DryRun'] = 'true'222        return self.get_status('DisassociateRouteTable', params)223    def create_route_table(self, vpc_id, dry_run=False):224        """225        Creates a new route table.226        :type vpc_id: str227        :param vpc_id: The VPC ID to associate this route table with.228        :type dry_run: bool229        :param dry_run: Set to True if the operation should not actually run.230        :rtype: The newly created route table231        :return: A :class:`boto.vpc.routetable.RouteTable` object232        """233        params = {'VpcId': vpc_id}234        if dry_run:235            params['DryRun'] = 'true'236        return self.get_object('CreateRouteTable', params, RouteTable)237    def delete_route_table(self, route_table_id, dry_run=False):238        """239        Delete a route table.240        :type route_table_id: str241        :param route_table_id: The ID of the route table to delete.242        :type dry_run: bool243        :param dry_run: Set to True if the operation should not actually run.244        :rtype: bool245        :return: True if successful246        """247        params = {'RouteTableId': route_table_id}248        if dry_run:249            params['DryRun'] = 'true'250        return self.get_status('DeleteRouteTable', params)251    def _replace_route_table_association(self, association_id,252                                        route_table_id, dry_run=False):253        """254        Helper function for replace_route_table_association and255        replace_route_table_association_with_assoc. Should not be used directly.256        :type association_id: str257        :param association_id: The ID of the existing association to replace.258        :type route_table_id: str259        :param route_table_id: The route table to ID to be used in the260            association.261        :type dry_run: bool262        :param dry_run: Set to True if the operation should not actually run.263        :rtype: ResultSet264        :return: ResultSet of Amazon resposne265        """266        params = {267            'AssociationId': association_id,268            'RouteTableId': route_table_id269        }270        if dry_run:271            params['DryRun'] = 'true'272        return self.get_object('ReplaceRouteTableAssociation', params,273                               ResultSet)274    def replace_route_table_assocation(self, association_id,275                                       route_table_id, dry_run=False):276        """277        Replaces a route association with a new route table.  This can be278        used to replace the 'main' route table by using the main route279        table association instead of the more common subnet type280        association.281        NOTE: It may be better to use replace_route_table_association_with_assoc282        instead of this function; this function does not return the new283        association ID. This function is retained for backwards compatibility.284        :type association_id: str285        :param association_id: The ID of the existing association to replace.286        :type route_table_id: str287        :param route_table_id: The route table to ID to be used in the288            association.289        :type dry_run: bool290        :param dry_run: Set to True if the operation should not actually run.291        :rtype: bool292        :return: True if successful293        """294        return self._replace_route_table_association(295            association_id, route_table_id, dry_run=dry_run).status296    def replace_route_table_association_with_assoc(self, association_id,297                                                   route_table_id,298                                                   dry_run=False):299        """300        Replaces a route association with a new route table.  This can be301        used to replace the 'main' route table by using the main route302        table association instead of the more common subnet type303        association. Returns the new association ID.304        :type association_id: str305        :param association_id: The ID of the existing association to replace.306        :type route_table_id: str307        :param route_table_id: The route table to ID to be used in the308            association.309        :type dry_run: bool310        :param dry_run: Set to True if the operation should not actually run.311        :rtype: str312        :return: New association ID313        """314        return self._replace_route_table_association(315            association_id, route_table_id, dry_run=dry_run).newAssociationId316    def create_route(self, route_table_id, destination_cidr_block,317                     gateway_id=None, instance_id=None, interface_id=None,318                     vpc_peering_connection_id=None,319                     dry_run=False):320        """321        Creates a new route in the route table within a VPC. The route's target322        can be either a gateway attached to the VPC or a NAT instance in the323        VPC.324        :type route_table_id: str325        :param route_table_id: The ID of the route table for the route.326        :type destination_cidr_block: str327        :param destination_cidr_block: The CIDR address block used for the328                                       destination match.329        :type gateway_id: str330        :param gateway_id: The ID of the gateway attached to your VPC.331        :type instance_id: str332        :param instance_id: The ID of a NAT instance in your VPC.333        :type interface_id: str334        :param interface_id: Allows routing to network interface attachments.335        :type vpc_peering_connection_id: str336        :param vpc_peering_connection_id: Allows routing to VPC peering337                                          connection.338        :type dry_run: bool339        :param dry_run: Set to True if the operation should not actually run.340        :rtype: bool341        :return: True if successful342        """343        params = {344            'RouteTableId': route_table_id,345            'DestinationCidrBlock': destination_cidr_block346        }347        if gateway_id is not None:348            params['GatewayId'] = gateway_id349        elif instance_id is not None:350            params['InstanceId'] = instance_id351        elif interface_id is not None:352            params['NetworkInterfaceId'] = interface_id353        elif vpc_peering_connection_id is not None:354            params['VpcPeeringConnectionId'] = vpc_peering_connection_id355        if dry_run:356            params['DryRun'] = 'true'357        return self.get_status('CreateRoute', params)358    def replace_route(self, route_table_id, destination_cidr_block,359                      gateway_id=None, instance_id=None, interface_id=None,360                      vpc_peering_connection_id=None,361                      dry_run=False):362        """363        Replaces an existing route within a route table in a VPC.364        :type route_table_id: str365        :param route_table_id: The ID of the route table for the route.366        :type destination_cidr_block: str367        :param destination_cidr_block: The CIDR address block used for the368                                       destination match.369        :type gateway_id: str370        :param gateway_id: The ID of the gateway attached to your VPC.371        :type instance_id: str372        :param instance_id: The ID of a NAT instance in your VPC.373        :type interface_id: str374        :param interface_id: Allows routing to network interface attachments.375        :type vpc_peering_connection_id: str376        :param vpc_peering_connection_id: Allows routing to VPC peering377                                          connection.378        :type dry_run: bool379        :param dry_run: Set to True if the operation should not actually run.380        :rtype: bool381        :return: True if successful382        """383        params = {384            'RouteTableId': route_table_id,385            'DestinationCidrBlock': destination_cidr_block386        }387        if gateway_id is not None:388            params['GatewayId'] = gateway_id389        elif instance_id is not None:390            params['InstanceId'] = instance_id391        elif interface_id is not None:392            params['NetworkInterfaceId'] = interface_id393        elif vpc_peering_connection_id is not None:394            params['VpcPeeringConnectionId'] = vpc_peering_connection_id395        if dry_run:396            params['DryRun'] = 'true'397        return self.get_status('ReplaceRoute', params)398    def delete_route(self, route_table_id, destination_cidr_block,399                     dry_run=False):400        """401        Deletes a route from a route table within a VPC.402        :type route_table_id: str403        :param route_table_id: The ID of the route table with the route.404        :type destination_cidr_block: str405        :param destination_cidr_block: The CIDR address block used for406                                       destination match.407        :type dry_run: bool408        :param dry_run: Set to True if the operation should not actually run.409        :rtype: bool410        :return: True if successful411        """412        params = {413            'RouteTableId': route_table_id,414            'DestinationCidrBlock': destination_cidr_block415        }416        if dry_run:417            params['DryRun'] = 'true'418        return self.get_status('DeleteRoute', params)419    #Network ACLs420    def get_all_network_acls(self, network_acl_ids=None, filters=None):421        """422        Retrieve information about your network acls. You can filter results423        to return information only about those network acls that match your424        search parameters. Otherwise, all network acls associated with your425        account are returned.426        :type network_acl_ids: list427        :param network_acl_ids: A list of strings with the desired network ACL428                                IDs.429        :type filters: list of tuples or dict430        :param filters: A list of tuples or dict containing filters. Each tuple431                        or dict item consists of a filter key and a filter value.432        :rtype: list433        :return: A list of :class:`boto.vpc.networkacl.NetworkAcl`434        """435        params = {}436        if network_acl_ids:437            self.build_list_params(params, network_acl_ids, "NetworkAclId")438        if filters:439            self.build_filter_params(params, filters)440        return self.get_list('DescribeNetworkAcls', params,441                             [('item', NetworkAcl)])442    def associate_network_acl(self, network_acl_id, subnet_id):443        """444        Associates a network acl with a specific subnet.445        :type network_acl_id: str446        :param network_acl_id: The ID of the network ACL to associate.447        :type subnet_id: str448        :param subnet_id: The ID of the subnet to associate with.449        :rtype: str450        :return: The ID of the association created451        """452        acl = self.get_all_network_acls(filters=[('association.subnet-id', subnet_id)])[0]453        association = [ association for association in acl.associations if association.subnet_id == subnet_id ][0]454        params = {455            'AssociationId': association.id,456            'NetworkAclId': network_acl_id457        }458        result = self.get_object('ReplaceNetworkAclAssociation', params, ResultSet)459        return result.newAssociationId460    def disassociate_network_acl(self, subnet_id, vpc_id=None):461        """462        Figures out what the default ACL is for the VPC, and associates463        current network ACL with the default.464        :type subnet_id: str465        :param subnet_id: The ID of the subnet to which the ACL belongs.466        :type vpc_id: str467        :param vpc_id: The ID of the VPC to which the ACL/subnet belongs. Queries EC2 if omitted.468        :rtype: str469        :return: The ID of the association created470        """471        if not vpc_id:472            vpc_id = self.get_all_subnets([subnet_id])[0].vpc_id473        acls = self.get_all_network_acls(filters=[('vpc-id', vpc_id), ('default', 'true')])474        default_acl_id = acls[0].id475        return self.associate_network_acl(default_acl_id, subnet_id)476    def create_network_acl(self, vpc_id):477        """478        Creates a new network ACL.479        :type vpc_id: str480        :param vpc_id: The VPC ID to associate this network ACL with.481        :rtype: The newly created network ACL482        :return: A :class:`boto.vpc.networkacl.NetworkAcl` object483        """484        params = {'VpcId': vpc_id}485        return self.get_object('CreateNetworkAcl', params, NetworkAcl)486    def delete_network_acl(self, network_acl_id):487        """488        Delete a network ACL489        :type network_acl_id: str490        :param network_acl_id: The ID of the network_acl to delete.491        :rtype: bool492        :return: True if successful493        """494        params = {'NetworkAclId': network_acl_id}495        return self.get_status('DeleteNetworkAcl', params)496    def create_network_acl_entry(self, network_acl_id, rule_number, protocol, rule_action,497                                 cidr_block, egress=None, icmp_code=None, icmp_type=None,498                                 port_range_from=None, port_range_to=None):499        """500        Creates a new network ACL entry in a network ACL within a VPC.501        :type network_acl_id: str502        :param network_acl_id: The ID of the network ACL for this network ACL entry.503        :type rule_number: int504        :param rule_number: The rule number to assign to the entry (for example, 100).505        :type protocol: int506        :param protocol: Valid values: -1 or a protocol number507        (http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)508        :type rule_action: str509        :param rule_action: Indicates whether to allow or deny traffic that matches the rule.510        :type cidr_block: str511        :param cidr_block: The CIDR range to allow or deny, in CIDR notation (for example,512        172.16.0.0/24).513        :type egress: bool514        :param egress: Indicates whether this rule applies to egress traffic from the subnet (true)515        or ingress traffic to the subnet (false).516        :type icmp_type: int517        :param icmp_type: For the ICMP protocol, the ICMP type. You can use -1 to specify518         all ICMP types.519        :type icmp_code: int520        :param icmp_code: For the ICMP protocol, the ICMP code. You can use -1 to specify521        all ICMP codes for the given ICMP type.522        :type port_range_from: int523        :param port_range_from: The first port in the range.524        :type port_range_to: int525        :param port_range_to: The last port in the range.526        :rtype: bool527        :return: True if successful528        """529        params = {530            'NetworkAclId': network_acl_id,531            'RuleNumber': rule_number,532            'Protocol': protocol,533            'RuleAction': rule_action,534            'CidrBlock': cidr_block535        }536        if egress is not None:537            if isinstance(egress, bool):538                egress = str(egress).lower()539            params['Egress'] = egress540        if icmp_code is not None:541            params['Icmp.Code'] = icmp_code542        if icmp_type is not None:543            params['Icmp.Type'] = icmp_type544        if port_range_from is not None:545            params['PortRange.From'] = port_range_from546        if port_range_to is not None:547            params['PortRange.To'] = port_range_to548        return self.get_status('CreateNetworkAclEntry', params)549    def replace_network_acl_entry(self, network_acl_id, rule_number, protocol, rule_action,550                                  cidr_block, egress=None, icmp_code=None, icmp_type=None,551                                  port_range_from=None, port_range_to=None):552        """553        Creates a new network ACL entry in a network ACL within a VPC.554        :type network_acl_id: str555        :param network_acl_id: The ID of the network ACL for the id you want to replace556        :type rule_number: int557        :param rule_number: The rule number that you want to replace(for example, 100).558        :type protocol: int559        :param protocol: Valid values: -1 or a protocol number560        (http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)561        :type rule_action: str562        :param rule_action: Indicates whether to allow or deny traffic that matches the rule.563        :type cidr_block: str564        :param cidr_block: The CIDR range to allow or deny, in CIDR notation (for example,565        172.16.0.0/24).566        :type egress: bool567        :param egress: Indicates whether this rule applies to egress traffic from the subnet (true)568        or ingress traffic to the subnet (false).569        :type icmp_type: int570        :param icmp_type: For the ICMP protocol, the ICMP type. You can use -1 to specify571         all ICMP types.572        :type icmp_code: int573        :param icmp_code: For the ICMP protocol, the ICMP code. You can use -1 to specify574        all ICMP codes for the given ICMP type.575        :type port_range_from: int576        :param port_range_from: The first port in the range.577        :type port_range_to: int578        :param port_range_to: The last port in the range.579        :rtype: bool580        :return: True if successful581        """582        params = {583            'NetworkAclId': network_acl_id,584            'RuleNumber': rule_number,585            'Protocol': protocol,586            'RuleAction': rule_action,587            'CidrBlock': cidr_block588        }589        if egress is not None:590            if isinstance(egress, bool):591                egress = str(egress).lower()592            params['Egress'] = egress593        if icmp_code is not None:594            params['Icmp.Code'] = icmp_code595        if icmp_type is not None:596            params['Icmp.Type'] = icmp_type597        if port_range_from is not None:598            params['PortRange.From'] = port_range_from599        if port_range_to is not None:600            params['PortRange.To'] = port_range_to601        return self.get_status('ReplaceNetworkAclEntry', params)602    def delete_network_acl_entry(self, network_acl_id, rule_number, egress=None):603        """604        Deletes a network ACL entry from a network ACL within a VPC.605        :type network_acl_id: str606        :param network_acl_id: The ID of the network ACL with the network ACL entry.607        :type rule_number: int608        :param rule_number: The rule number for the entry to delete.609        :type egress: bool610        :param egress: Specifies whether the rule to delete is an egress rule (true)611        or ingress rule (false).612        :rtype: bool613        :return: True if successful614        """615        params = {616            'NetworkAclId': network_acl_id,617            'RuleNumber': rule_number618        }619        if egress is not None:620            if isinstance(egress, bool):621                egress = str(egress).lower()622            params['Egress'] = egress623        return self.get_status('DeleteNetworkAclEntry', params)624    # Internet Gateways625    def get_all_internet_gateways(self, internet_gateway_ids=None,626                                  filters=None, dry_run=False):627        """628        Get a list of internet gateways. You can filter results to return information629        about only those gateways that you're interested in.630        :type internet_gateway_ids: list631        :param internet_gateway_ids: A list of strings with the desired gateway IDs.632        :type filters: list of tuples or dict633        :param filters: A list of tuples or dict containing filters.  Each tuple634                        or dict item consists of a filter key and a filter value.635        :type dry_run: bool636        :param dry_run: Set to True if the operation should not actually run.637        """638        params = {}639        if internet_gateway_ids:640            self.build_list_params(params, internet_gateway_ids,641                                   'InternetGatewayId')642        if filters:643            self.build_filter_params(params, filters)644        if dry_run:645            params['DryRun'] = 'true'646        return self.get_list('DescribeInternetGateways', params,647                             [('item', InternetGateway)])648    def create_internet_gateway(self, dry_run=False):649        """650        Creates an internet gateway for VPC.651        :type dry_run: bool652        :param dry_run: Set to True if the operation should not actually run.653        :rtype: Newly created internet gateway.654        :return: `boto.vpc.internetgateway.InternetGateway`655        """656        params = {}657        if dry_run:658            params['DryRun'] = 'true'659        return self.get_object('CreateInternetGateway', params, InternetGateway)660    def delete_internet_gateway(self, internet_gateway_id, dry_run=False):661        """662        Deletes an internet gateway from the VPC.663        :type internet_gateway_id: str664        :param internet_gateway_id: The ID of the internet gateway to delete.665        :type dry_run: bool666        :param dry_run: Set to True if the operation should not actually run.667        :rtype: Bool668        :return: True if successful669        """670        params = {'InternetGatewayId': internet_gateway_id}671        if dry_run:672            params['DryRun'] = 'true'673        return self.get_status('DeleteInternetGateway', params)674    def attach_internet_gateway(self, internet_gateway_id, vpc_id,675                                dry_run=False):676        """677        Attach an internet gateway to a specific VPC.678        :type internet_gateway_id: str679        :param internet_gateway_id: The ID of the internet gateway to attach.680        :type vpc_id: str681        :param vpc_id: The ID of the VPC to attach to.682        :type dry_run: bool683        :param dry_run: Set to True if the operation should not actually run.684        :rtype: Bool685        :return: True if successful686        """687        params = {688            'InternetGatewayId': internet_gateway_id,689            'VpcId': vpc_id690        }691        if dry_run:692            params['DryRun'] = 'true'693        return self.get_status('AttachInternetGateway', params)694    def detach_internet_gateway(self, internet_gateway_id, vpc_id,695                                dry_run=False):696        """697        Detach an internet gateway from a specific VPC.698        :type internet_gateway_id: str699        :param internet_gateway_id: The ID of the internet gateway to detach.700        :type vpc_id: str701        :param vpc_id: The ID of the VPC to attach to.702        :type dry_run: bool703        :param dry_run: Set to True if the operation should not actually run.704        :rtype: Bool705        :return: True if successful706        """707        params = {708            'InternetGatewayId': internet_gateway_id,709            'VpcId': vpc_id710        }711        if dry_run:712            params['DryRun'] = 'true'713        return self.get_status('DetachInternetGateway', params)714    # Customer Gateways715    def get_all_customer_gateways(self, customer_gateway_ids=None,716                                  filters=None, dry_run=False):717        """718        Retrieve information about your CustomerGateways.  You can filter719        results to return information only about those CustomerGateways that720        match your search parameters.  Otherwise, all CustomerGateways721        associated with your account are returned.722        :type customer_gateway_ids: list723        :param customer_gateway_ids: A list of strings with the desired724            CustomerGateway ID's.725        :type filters: list of tuples or dict726        :param filters: A list of tuples or dict containing filters.  Each tuple727                        or dict item consists of a filter key and a filter value.728                        Possible filter keys are:729                         - *state*, the state of the CustomerGateway730                           (pending,available,deleting,deleted)731                         - *type*, the type of customer gateway (ipsec.1)732                         - *ipAddress* the IP address of customer gateway's733                           internet-routable external inteface734        :type dry_run: bool735        :param dry_run: Set to True if the operation should not actually run.736        :rtype: list737        :return: A list of :class:`boto.vpc.customergateway.CustomerGateway`738        """739        params = {}740        if customer_gateway_ids:741            self.build_list_params(params, customer_gateway_ids,742                                   'CustomerGatewayId')743        if filters:744            self.build_filter_params(params, filters)745        if dry_run:746            params['DryRun'] = 'true'747        return self.get_list('DescribeCustomerGateways', params,748                             [('item', CustomerGateway)])749    def create_customer_gateway(self, type, ip_address, bgp_asn, dry_run=False):750        """751        Create a new Customer Gateway752        :type type: str753        :param type: Type of VPN Connection.  Only valid value currently is 'ipsec.1'754        :type ip_address: str755        :param ip_address: Internet-routable IP address for customer's gateway.756                           Must be a static address.757        :type bgp_asn: int758        :param bgp_asn: Customer gateway's Border Gateway Protocol (BGP)759                        Autonomous System Number (ASN)760        :type dry_run: bool761        :param dry_run: Set to True if the operation should not actually run.762        :rtype: The newly created CustomerGateway763        :return: A :class:`boto.vpc.customergateway.CustomerGateway` object764        """765        params = {'Type': type,766                  'IpAddress': ip_address,767                  'BgpAsn': bgp_asn}768        if dry_run:769            params['DryRun'] = 'true'770        return self.get_object('CreateCustomerGateway', params, CustomerGateway)771    def delete_customer_gateway(self, customer_gateway_id, dry_run=False):772        """773        Delete a Customer Gateway.774        :type customer_gateway_id: str775        :param customer_gateway_id: The ID of the customer_gateway to be deleted.776        :type dry_run: bool777        :param dry_run: Set to True if the operation should not actually run.778        :rtype: bool779        :return: True if successful780        """781        params = {'CustomerGatewayId': customer_gateway_id}782        if dry_run:783            params['DryRun'] = 'true'784        return self.get_status('DeleteCustomerGateway', params)785    # VPN Gateways786    def get_all_vpn_gateways(self, vpn_gateway_ids=None, filters=None,787                             dry_run=False):788        """789        Retrieve information about your VpnGateways.  You can filter results to790        return information only about those VpnGateways that match your search791        parameters.  Otherwise, all VpnGateways associated with your account792        are returned.793        :type vpn_gateway_ids: list794        :param vpn_gateway_ids: A list of strings with the desired VpnGateway ID's795        :type filters: list of tuples or dict796        :param filters: A list of tuples or dict containing filters.  Each tuple797                        or dict item consists of a filter key and a filter value.798                        Possible filter keys are:799                        - *state*, a list of states of the VpnGateway800                          (pending,available,deleting,deleted)801                        - *type*, a list types of customer gateway (ipsec.1)802                        - *availabilityZone*, a list of  Availability zones the803                          VPN gateway is in.804        :type dry_run: bool805        :param dry_run: Set to True if the operation should not actually run.806        :rtype: list807        :return: A list of :class:`boto.vpc.customergateway.VpnGateway`808        """809        params = {}810        if vpn_gateway_ids:811            self.build_list_params(params, vpn_gateway_ids, 'VpnGatewayId')812        if filters:813            self.build_filter_params(params, filters)814        if dry_run:815            params['DryRun'] = 'true'816        return self.get_list('DescribeVpnGateways', params,817                             [('item', VpnGateway)])818    def create_vpn_gateway(self, type, availability_zone=None, dry_run=False):819        """820        Create a new Vpn Gateway821        :type type: str822        :param type: Type of VPN Connection.  Only valid value currently is 'ipsec.1'823        :type availability_zone: str824        :param availability_zone: The Availability Zone where you want the VPN gateway.825        :type dry_run: bool826        :param dry_run: Set to True if the operation should not actually run.827        :rtype: The newly created VpnGateway828        :return: A :class:`boto.vpc.vpngateway.VpnGateway` object829        """830        params = {'Type': type}831        if availability_zone:832            params['AvailabilityZone'] = availability_zone833        if dry_run:834            params['DryRun'] = 'true'835        return self.get_object('CreateVpnGateway', params, VpnGateway)836    def delete_vpn_gateway(self, vpn_gateway_id, dry_run=False):837        """838        Delete a Vpn Gateway.839        :type vpn_gateway_id: str840        :param vpn_gateway_id: The ID of the vpn_gateway to be deleted.841        :type dry_run: bool842        :param dry_run: Set to True if the operation should not actually run.843        :rtype: bool844        :return: True if successful845        """846        params = {'VpnGatewayId': vpn_gateway_id}847        if dry_run:848            params['DryRun'] = 'true'849        return self.get_status('DeleteVpnGateway', params)850    def attach_vpn_gateway(self, vpn_gateway_id, vpc_id, dry_run=False):851        """852        Attaches a VPN gateway to a VPC.853        :type vpn_gateway_id: str854        :param vpn_gateway_id: The ID of the vpn_gateway to attach855        :type vpc_id: str856        :param vpc_id: The ID of the VPC you want to attach the gateway to.857        :type dry_run: bool858        :param dry_run: Set to True if the operation should not actually run.859        :rtype: An attachment860        :return: a :class:`boto.vpc.vpngateway.Attachment`861        """862        params = {'VpnGatewayId': vpn_gateway_id,863                  'VpcId': vpc_id}864        if dry_run:865            params['DryRun'] = 'true'866        return self.get_object('AttachVpnGateway', params, Attachment)867    def detach_vpn_gateway(self, vpn_gateway_id, vpc_id, dry_run=False):868        """869        Detaches a VPN gateway from a VPC.870        :type vpn_gateway_id: str871        :param vpn_gateway_id: The ID of the vpn_gateway to detach872        :type vpc_id: str873        :param vpc_id: The ID of the VPC you want to detach the gateway from.874        :type dry_run: bool875        :param dry_run: Set to True if the operation should not actually run.876        :rtype: bool877        :return: True if successful878        """879        params = {'VpnGatewayId': vpn_gateway_id,880                  'VpcId': vpc_id}881        if dry_run:882            params['DryRun'] = 'true'883        return self.get_status('DetachVpnGateway', params)884    # Subnets885    def get_all_subnets(self, subnet_ids=None, filters=None, dry_run=False):886        """887        Retrieve information about your Subnets.  You can filter results to888        return information only about those Subnets that match your search889        parameters.  Otherwise, all Subnets associated with your account890        are returned.891        :type subnet_ids: list892        :param subnet_ids: A list of strings with the desired Subnet ID's893        :type filters: list of tuples or dict894        :param filters: A list of tuples or dict containing filters.  Each tuple895                        or dict item consists of a filter key and a filter value.896                        Possible filter keys are:897                        - *state*, a list of states of the Subnet898                          (pending,available)899                        - *vpcId*, a list of IDs of the VPC that the subnet is in.900                        - *cidrBlock*, a list of CIDR blocks of the subnet901                        - *availabilityZone*, list of the Availability Zones902                          the subnet is in.903        :type dry_run: bool904        :param dry_run: Set to True if the operation should not actually run.905        :rtype: list906        :return: A list of :class:`boto.vpc.subnet.Subnet`907        """908        params = {}909        if subnet_ids:910            self.build_list_params(params, subnet_ids, 'SubnetId')911        if filters:912            self.build_filter_params(params, filters)913        if dry_run:914            params['DryRun'] = 'true'915        return self.get_list('DescribeSubnets', params, [('item', Subnet)])916    def create_subnet(self, vpc_id, cidr_block, availability_zone=None,917                      dry_run=False):918        """919        Create a new Subnet920        :type vpc_id: str921        :param vpc_id: The ID of the VPC where you want to create the subnet.922        :type cidr_block: str923        :param cidr_block: The CIDR block you want the subnet to cover.924        :type availability_zone: str925        :param availability_zone: The AZ you want the subnet in926        :type dry_run: bool927        :param dry_run: Set to True if the operation should not actually run.928        :rtype: The newly created Subnet929        :return: A :class:`boto.vpc.customergateway.Subnet` object930        """931        params = {'VpcId': vpc_id,932                  'CidrBlock': cidr_block}933        if availability_zone:934            params['AvailabilityZone'] = availability_zone935        if dry_run:936            params['DryRun'] = 'true'937        return self.get_object('CreateSubnet', params, Subnet)938    def delete_subnet(self, subnet_id, dry_run=False):939        """940        Delete a subnet.941        :type subnet_id: str942        :param subnet_id: The ID of the subnet to be deleted.943        :type dry_run: bool944        :param dry_run: Set to True if the operation should not actually run.945        :rtype: bool946        :return: True if successful947        """948        params = {'SubnetId': subnet_id}949        if dry_run:950            params['DryRun'] = 'true'951        return self.get_status('DeleteSubnet', params)952    # DHCP Options953    def get_all_dhcp_options(self, dhcp_options_ids=None, filters=None, dry_run=False):954        """955        Retrieve information about your DhcpOptions.956        :type dhcp_options_ids: list957        :param dhcp_options_ids: A list of strings with the desired DhcpOption ID's958        :type filters: list of tuples or dict959        :param filters: A list of tuples or dict containing filters.  Each tuple960            or dict item consists of a filter key and a filter value.961        :type dry_run: bool962        :param dry_run: Set to True if the operation should not actually run.963        :rtype: list964        :return: A list of :class:`boto.vpc.dhcpoptions.DhcpOptions`965        """966        params = {}967        if dhcp_options_ids:968            self.build_list_params(params, dhcp_options_ids, 'DhcpOptionsId')969        if filters:970            self.build_filter_params(params, filters)971        if dry_run:972            params['DryRun'] = 'true'973        return self.get_list('DescribeDhcpOptions', params,974                             [('item', DhcpOptions)])975    def create_dhcp_options(self, domain_name=None, domain_name_servers=None,976                            ntp_servers=None, netbios_name_servers=None,977                            netbios_node_type=None, dry_run=False):978        """979        Create a new DhcpOption980        This corresponds to981        http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateDhcpOptions.html982        :type domain_name: str983        :param domain_name: A domain name of your choice (for example,984            example.com)985        :type domain_name_servers: list of strings986        :param domain_name_servers: The IP address of a domain name server. You987            can specify up to four addresses.988        :type ntp_servers: list of strings989        :param ntp_servers: The IP address of a Network Time Protocol (NTP)990            server. You can specify up to four addresses.991        :type netbios_name_servers: list of strings992        :param netbios_name_servers: The IP address of a NetBIOS name server.993            You can specify up to four addresses.994        :type netbios_node_type: str995        :param netbios_node_type: The NetBIOS node type (1, 2, 4, or 8). For996            more information about the values, see RFC 2132. We recommend you997            only use 2 at this time (broadcast and multicast are currently not998            supported).999        :type dry_run: bool1000        :param dry_run: Set to True if the operation should not actually run.1001        :rtype: The newly created DhcpOption1002        :return: A :class:`boto.vpc.customergateway.DhcpOption` object1003        """1004        key_counter = 11005        params = {}1006        def insert_option(params, name, value):1007            params['DhcpConfiguration.%d.Key' % (key_counter,)] = name1008            if isinstance(value, (list, tuple)):1009                for idx, value in enumerate(value, 1):1010                    key_name = 'DhcpConfiguration.%d.Value.%d' % (1011                        key_counter, idx)1012                    params[key_name] = value1013            else:1014                key_name = 'DhcpConfiguration.%d.Value.1' % (key_counter,)1015                params[key_name] = value1016            return key_counter + 11017        if domain_name:1018            key_counter = insert_option(params,1019                                        'domain-name', domain_name)1020        if domain_name_servers:1021            key_counter = insert_option(params,1022                                        'domain-name-servers', domain_name_servers)1023        if ntp_servers:1024            key_counter = insert_option(params,1025                                        'ntp-servers', ntp_servers)1026        if netbios_name_servers:1027            key_counter = insert_option(params,1028                                        'netbios-name-servers', netbios_name_servers)1029        if netbios_node_type:1030            key_counter = insert_option(params,1031                                        'netbios-node-type', netbios_node_type)1032        if dry_run:1033            params['DryRun'] = 'true'1034        return self.get_object('CreateDhcpOptions', params, DhcpOptions)1035    def delete_dhcp_options(self, dhcp_options_id, dry_run=False):1036        """1037        Delete a DHCP Options1038        :type dhcp_options_id: str1039        :param dhcp_options_id: The ID of the DHCP Options to be deleted.1040        :type dry_run: bool1041        :param dry_run: Set to True if the operation should not actually run.1042        :rtype: bool1043        :return: True if successful1044        """1045        params = {'DhcpOptionsId': dhcp_options_id}1046        if dry_run:1047            params['DryRun'] = 'true'1048        return self.get_status('DeleteDhcpOptions', params)1049    def associate_dhcp_options(self, dhcp_options_id, vpc_id, dry_run=False):1050        """1051        Associate a set of Dhcp Options with a VPC.1052        :type dhcp_options_id: str1053        :param dhcp_options_id: The ID of the Dhcp Options1054        :type vpc_id: str1055        :param vpc_id: The ID of the VPC.1056        :type dry_run: bool1057        :param dry_run: Set to True if the operation should not actually run.1058        :rtype: bool1059        :return: True if successful1060        """1061        params = {'DhcpOptionsId': dhcp_options_id,1062                  'VpcId': vpc_id}1063        if dry_run:1064            params['DryRun'] = 'true'1065        return self.get_status('AssociateDhcpOptions', params)1066    # VPN Connection1067    def get_all_vpn_connections(self, vpn_connection_ids=None, filters=None,1068                                dry_run=False):1069        """1070        Retrieve information about your VPN_CONNECTIONs.  You can filter results to1071        return information only about those VPN_CONNECTIONs that match your search1072        parameters.  Otherwise, all VPN_CONNECTIONs associated with your account1073        are returned.1074        :type vpn_connection_ids: list1075        :param vpn_connection_ids: A list of strings with the desired VPN_CONNECTION ID's1076        :type filters: list of tuples or dict1077        :param filters: A list of tuples or dict containing filters.  Each tuple1078                        or dict item consists of a filter key and a filter value.1079                        Possible filter keys are:1080                        - *state*, a list of states of the VPN_CONNECTION1081                          pending,available,deleting,deleted1082                        - *type*, a list of types of connection, currently 'ipsec.1'1083                        - *customerGatewayId*, a list of IDs of the customer gateway1084                          associated with the VPN1085                        - *vpnGatewayId*, a list of IDs of the VPN gateway associated1086                          with the VPN connection1087        :type dry_run: bool1088        :param dry_run: Set to True if the operation should not actually run.1089        :rtype: list1090        :return: A list of :class:`boto.vpn_connection.vpnconnection.VpnConnection`1091        """1092        params = {}1093        if vpn_connection_ids:1094            self.build_list_params(params, vpn_connection_ids,1095                                   'VpnConnectionId')1096        if filters:1097            self.build_filter_params(params, filters)1098        if dry_run:1099            params['DryRun'] = 'true'1100        return self.get_list('DescribeVpnConnections', params,1101                             [('item', VpnConnection)])1102    def create_vpn_connection(self, type, customer_gateway_id, vpn_gateway_id,1103                              static_routes_only=None, dry_run=False):1104        """1105        Create a new VPN Connection.1106        :type type: str1107        :param type: The type of VPN Connection.  Currently only 'ipsec.1'1108                     is supported1109        :type customer_gateway_id: str1110        :param customer_gateway_id: The ID of the customer gateway.1111        :type vpn_gateway_id: str1112        :param vpn_gateway_id: The ID of the VPN gateway.1113        :type static_routes_only: bool1114        :param static_routes_only: Indicates whether the VPN connection1115        requires static routes. If you are creating a VPN connection1116        for a device that does not support BGP, you must specify true.1117        :type dry_run: bool1118        :param dry_run: Set to True if the operation should not actually run.1119        :rtype: The newly created VpnConnection1120        :return: A :class:`boto.vpc.vpnconnection.VpnConnection` object1121        """1122        params = {'Type': type,1123                  'CustomerGatewayId': customer_gateway_id,1124                  'VpnGatewayId': vpn_gateway_id}1125        if static_routes_only is not None:1126            if isinstance(static_routes_only, bool):1127                static_routes_only = str(static_routes_only).lower()1128            params['Options.StaticRoutesOnly'] = static_routes_only1129        if dry_run:1130            params['DryRun'] = 'true'1131        return self.get_object('CreateVpnConnection', params, VpnConnection)1132    def delete_vpn_connection(self, vpn_connection_id, dry_run=False):1133        """1134        Delete a VPN Connection.1135        :type vpn_connection_id: str1136        :param vpn_connection_id: The ID of the vpn_connection to be deleted.1137        :type dry_run: bool1138        :param dry_run: Set to True if the operation should not actually run.1139        :rtype: bool1140        :return: True if successful1141        """1142        params = {'VpnConnectionId': vpn_connection_id}1143        if dry_run:1144            params['DryRun'] = 'true'1145        return self.get_status('DeleteVpnConnection', params)1146    def disable_vgw_route_propagation(self, route_table_id, gateway_id,1147                                      dry_run=False):1148        """1149        Disables a virtual private gateway (VGW) from propagating routes to the1150        routing tables of an Amazon VPC.1151        :type route_table_id: str1152        :param route_table_id: The ID of the routing table.1153        :type gateway_id: str1154        :param gateway_id: The ID of the virtual private gateway.1155        :type dry_run: bool1156        :param dry_run: Set to True if the operation should not actually run.1157        :rtype: bool1158        :return: True if successful1159        """1160        params = {1161            'RouteTableId': route_table_id,1162            'GatewayId': gateway_id,1163        }1164        if dry_run:1165            params['DryRun'] = 'true'1166        return self.get_status('DisableVgwRoutePropagation', params)1167    def enable_vgw_route_propagation(self, route_table_id, gateway_id,1168                                     dry_run=False):1169        """1170        Enables a virtual private gateway (VGW) to propagate routes to the1171        routing tables of an Amazon VPC.1172        :type route_table_id: str1173        :param route_table_id: The ID of the routing table.1174        :type gateway_id: str1175        :param gateway_id: The ID of the virtual private gateway.1176        :type dry_run: bool1177        :param dry_run: Set to True if the operation should not actually run.1178        :rtype: bool1179        :return: True if successful1180        """1181        params = {1182            'RouteTableId': route_table_id,1183            'GatewayId': gateway_id,1184        }1185        if dry_run:1186            params['DryRun'] = 'true'1187        return self.get_status('EnableVgwRoutePropagation', params)1188    def create_vpn_connection_route(self, destination_cidr_block,1189                                    vpn_connection_id, dry_run=False):1190        """1191        Creates a new static route associated with a VPN connection between an1192        existing virtual private gateway and a VPN customer gateway. The static1193        route allows traffic to be routed from the virtual private gateway to1194        the VPN customer gateway.1195        :type destination_cidr_block: str1196        :param destination_cidr_block: The CIDR block associated with the local1197            subnet of the customer data center.1198        :type vpn_connection_id: str1199        :param vpn_connection_id: The ID of the VPN connection.1200        :type dry_run: bool1201        :param dry_run: Set to True if the operation should not actually run.1202        :rtype: bool1203        :return: True if successful1204        """1205        params = {1206            'DestinationCidrBlock': destination_cidr_block,1207            'VpnConnectionId': vpn_connection_id,1208        }1209        if dry_run:1210            params['DryRun'] = 'true'1211        return self.get_status('CreateVpnConnectionRoute', params)1212    def delete_vpn_connection_route(self, destination_cidr_block,1213                                    vpn_connection_id, dry_run=False):1214        """1215        Deletes a static route associated with a VPN connection between an1216        existing virtual private gateway and a VPN customer gateway. The static1217        route allows traffic to be routed from the virtual private gateway to1218        the VPN customer gateway.1219        :type destination_cidr_block: str1220        :param destination_cidr_block: The CIDR block associated with the local1221            subnet of the customer data center.1222        :type vpn_connection_id: str1223        :param vpn_connection_id: The ID of the VPN connection.1224        :type dry_run: bool1225        :param dry_run: Set to True if the operation should not actually run.1226        :rtype: bool1227        :return: True if successful1228        """1229        params = {1230            'DestinationCidrBlock': destination_cidr_block,1231            'VpnConnectionId': vpn_connection_id,1232        }1233        if dry_run:1234            params['DryRun'] = 'true'1235        return self.get_status('DeleteVpnConnectionRoute', params)1236    def get_all_vpc_peering_connections(self, vpc_peering_connection_ids=None, 1237                                        filters=None, dry_run=False):1238        """1239        Retrieve information about your VPC peering connections. You1240        can filter results to return information only about those VPC1241        peering connections that match your search parameters.1242        Otherwise, all VPC peering connections associated with your1243        account are returned.1244        :type vpc_peering_connection_ids: list1245        :param vpc_peering_connection_ids: A list of strings with the desired VPC1246            peering connection ID's1247        :type filters: list of tuples1248        :param filters: A list of tuples containing filters. Each tuple1249            consists of a filter key and a filter value.1250            Possible filter keys are:1251            * *accepter-vpc-info.cidr-block* - The CIDR block of the peer VPC.1252            * *accepter-vpc-info.owner-id* - The AWS account ID of the owner 1253                of the peer VPC.1254            * *accepter-vpc-info.vpc-id* - The ID of the peer VPC.1255            * *expiration-time* - The expiration date and time for the VPC 1256                peering connection.1257            * *requester-vpc-info.cidr-block* - The CIDR block of the 1258                requester's VPC.1259            * *requester-vpc-info.owner-id* - The AWS account ID of the 1260                owner of the requester VPC.1261            * *requester-vpc-info.vpc-id* - The ID of the requester VPC.1262            * *status-code* - The status of the VPC peering connection.1263            * *status-message* - A message that provides more information 1264                about the status of the VPC peering connection, if applicable.1265            1266        :type dry_run: bool1267        :param dry_run: Set to True if the operation should not actually run.1268        :rtype: list1269        :return: A list of :class:`boto.vpc.vpc.VPC`1270        """1271        params = {}1272        if vpc_peering_connection_ids:1273            self.build_list_params(params, vpc_peering_connection_ids, 'VpcPeeringConnectionId')1274        if filters:1275            self.build_filter_params(params, dict(filters))1276        if dry_run:1277            params['DryRun'] = 'true'1278        return self.get_list('DescribeVpcPeeringConnections', params, [('item', VpcPeeringConnection)])1279    1280    def create_vpc_peering_connection(self, vpc_id, peer_vpc_id, 1281                                      peer_owner_id=None, dry_run=False):1282        """1283        Create a new VPN Peering connection.1284        :type vpc_id: str1285        :param vpc_id: The ID of the requester VPC.1286        :type peer_vpc_id: str1287        :param vpc_peer_id: The ID of the VPC with which you are creating the peering connection.1288        :type peer_owner_id: str1289        :param peer_owner_id: The AWS account ID of the owner of the peer VPC.1290        :rtype: The newly created VpcPeeringConnection1291        :return: A :class:`boto.vpc.vpc_peering_connection.VpcPeeringConnection` object1292        """1293        params = {'VpcId': vpc_id,1294                  'PeerVpcId': peer_vpc_id }1295        if peer_owner_id is not None:1296            params['PeerOwnerId'] = peer_owner_id1297        if dry_run:1298            params['DryRun'] = 'true'1299        return self.get_object('CreateVpcPeeringConnection', params, 1300                               VpcPeeringConnection)1301    def delete_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):1302        """1303        Deletes a VPC peering connection. Either the owner of the requester 1304        VPC or the owner of the peer VPC can delete the VPC peering connection 1305        if it's in the active state. The owner of the requester VPC can delete 1306        a VPC peering connection in the pending-acceptance state.1307        :type vpc_peering_connection_id: str1308        :param vpc_peering_connection_id: The ID of the VPC peering connection.1309        :rtype: bool1310        :return: True if successful1311        """1312        params = {1313            'VpcPeeringConnectionId': vpc_peering_connection_id1314        }1315        if dry_run:1316            params['DryRun'] = 'true'1317        return self.get_status('DeleteVpcPeeringConnection', params)1318    def reject_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):1319        """1320        Rejects a VPC peering connection request. The VPC peering connection 1321        must be in the pending-acceptance state. 1322        :type vpc_peering_connection_id: str1323        :param vpc_peering_connection_id: The ID of the VPC peering connection.1324        :rtype: bool1325        :return: True if successful1326        """1327        params = {1328            'VpcPeeringConnectionId': vpc_peering_connection_id1329        }1330        if dry_run:1331            params['DryRun'] = 'true'1332        return self.get_status('RejectVpcPeeringConnection', params)1333    def accept_vpc_peering_connection(self, vpc_peering_connection_id, dry_run=False):1334        """1335        Acceptss a VPC peering connection request. The VPC peering connection 1336        must be in the pending-acceptance state. 1337        :type vpc_peering_connection_id: str1338        :param vpc_peering_connection_id: The ID of the VPC peering connection.1339        :rtype: Accepted VpcPeeringConnection1340        :return: A :class:`boto.vpc.vpc_peering_connection.VpcPeeringConnection` object1341        """1342        params = {1343            'VpcPeeringConnectionId': vpc_peering_connection_id1344        }1345        if dry_run:1346            params['DryRun'] = 'true'1347        return self.get_object('AcceptVpcPeeringConnection', params, 1348                               VpcPeeringConnection)1349    def get_all_classic_link_vpcs(self, vpc_ids=None, filters=None,1350                                   dry_run=False):1351        """1352        Describes the ClassicLink status of one or more VPCs.1353        :type vpc_ids: list1354        :param vpc_ids: A list of strings with the desired VPC ID's1355        :type dry_run: bool1356        :param dry_run: Set to True if the operation should not actually run.1357        :type filters: list of tuples or dict1358        :param filters: A list of tuples or dict containing filters. Each tuple1359            or dict item consists of a filter key and a filter value.1360        :rtype: list1361        :return: A list of :class:`boto.vpc.vpc.VPC`1362        """1363        params = {}1364        if vpc_ids:1365            self.build_list_params(params, vpc_ids, 'VpcId')1366        if filters:1367            self.build_filter_params(params, filters)1368        if dry_run:1369            params['DryRun'] = 'true'1370        return self.get_list('DescribeVpcClassicLink', params, [('item', VPC)],1371                             verb='POST')1372    def attach_classic_link_vpc(self, vpc_id, instance_id, groups,1373                                dry_run=False):1374        """1375        Links  an EC2-Classic instance to a ClassicLink-enabled VPC through one1376        or more of the VPC's security groups. You cannot link an EC2-Classic1377        instance to more than one VPC at a time. You can only link an instance1378        that's in the running state. An instance is automatically unlinked from1379        a VPC when it's stopped. You can link it to the VPC again when you1380        restart it.1381        After you've linked an instance, you cannot  change  the VPC security1382        groups  that are associated with it. To change the security groups, you1383        must first unlink the instance, and then link it again.1384        Linking your instance to a VPC is sometimes referred  to  as  attaching1385        your instance.1386        :type vpc_id: str1387        :param vpc_id: The ID of a ClassicLink-enabled VPC.1388        :type intance_id: str1389        :param instance_is: The ID of a ClassicLink-enabled VPC.1390        :tye groups: list1391        :param groups: The ID of one or more of the VPC's security groups.1392            You cannot specify security groups from a different VPC. The1393            members of the list can be1394            :class:`boto.ec2.securitygroup.SecurityGroup` objects or1395            strings of the id's of the security groups.1396        :type dry_run: bool1397        :param dry_run: Set to True if the operation should not actually run.1398        :rtype: bool1399        :return: True if successful1400        """1401        params = {'VpcId': vpc_id, 'InstanceId': instance_id}1402        if dry_run:1403            params['DryRun'] = 'true'1404        l = []1405        for group in groups:1406            if hasattr(group, 'id'):1407                l.append(group.id)1408            else:1409                l.append(group)1410        self.build_list_params(params, l, 'SecurityGroupId')1411        return self.get_status('AttachClassicLinkVpc', params)1412    def detach_classic_link_vpc(self, vpc_id, instance_id, dry_run=False):1413        """1414        Unlinks a linked EC2-Classic instance from a VPC. After the instance1415        has been unlinked, the VPC security groups are no longer associated1416        with it. An instance is automatically unlinked from a VPC when1417        it's stopped.1418        :type vpc_id: str1419        :param vpc_id: The ID of the instance to unlink from the VPC.1420        :type intance_id: str1421        :param instance_is: The ID of the VPC to which the instance is linked.1422        :type dry_run: bool1423        :param dry_run: Set to True if the operation should not actually run.1424        :rtype: bool1425        :return: True if successful1426        """1427        params = {'VpcId': vpc_id, 'InstanceId': instance_id}1428        if dry_run:1429            params['DryRun'] = 'true'1430        return self.get_status('DetachClassicLinkVpc', params)1431    def disable_vpc_classic_link(self, vpc_id, dry_run=False):1432        """1433        Disables  ClassicLink  for  a VPC. You cannot disable ClassicLink for a1434        VPC that has EC2-Classic instances linked to it.1435        :type vpc_id: str1436        :param vpc_id: The ID of the VPC.1437        :type dry_run: bool1438        :param dry_run: Set to True if the operation should not actually run.1439        :rtype: bool1440        :return: True if successful1441        """1442        params = {'VpcId': vpc_id}1443        if dry_run:1444            params['DryRun'] = 'true'1445        return self.get_status('DisableVpcClassicLink', params)1446    def enable_vpc_classic_link(self, vpc_id, dry_run=False):1447        """1448        Enables a VPC for ClassicLink. You can then link EC2-Classic instances1449        to your ClassicLink-enabled VPC to allow communication over private IP1450        addresses. You cannot enable your VPC for ClassicLink if any of your1451        VPC's route tables have existing routes for address ranges within the1452        10.0.0.0/8 IP address range, excluding local routes for VPCs in the1453        10.0.0.0/16 and 10.1.0.0/16 IP address ranges.1454        :type vpc_id: str1455        :param vpc_id: The ID of the VPC.1456        :type dry_run: bool1457        :param dry_run: Set to True if the operation should not actually run.1458        :rtype: bool1459        :return: True if successful1460        """1461        params = {'VpcId': vpc_id}1462        if dry_run:1463            params['DryRun'] = 'true'...shell.py
Source:shell.py  
...30    quote_command(args) -> str31    Quote the command for passing to a shell.32    """33    return ' '.join([_quote(a) for a in args])34def _coerce_dry_run(dry_run_override):35    if dry_run_override is None:36        return dry_run37    else:38        return dry_run_override39def _echo_command(dry_run, command, env=None, prompt="+ "):40    output = []41    if env is not None:42        output += ['env'] + [_quote("%s=%s" % (k, v))43                             for (k, v) in sorted(env.items())]44    output += [_quote(arg) for arg in command]45    file = sys.stderr46    if dry_run:47        file = sys.stdout48    print(prompt + ' '.join(output), file=file)49    file.flush()50def call(command, stderr=None, env=None, dry_run=None, echo=True):51    """52    call(command, ...) -> str53    Execute the given command.54    This function will raise an exception on any command failure.55    """56    dry_run = _coerce_dry_run(dry_run)57    if dry_run or echo:58        _echo_command(dry_run, command, env=env)59    if dry_run:60        return61    _env = None62    if env is not None:63        _env = dict(os.environ)64        _env.update(env)65    try:66        subprocess.check_call(command, env=_env, stderr=stderr)67    except subprocess.CalledProcessError as e:68        diagnostics.fatal(69            "command terminated with a non-zero exit status " +70            str(e.returncode) + ", aborting")71    except OSError as e:72        diagnostics.fatal(73            "could not execute '" + quote_command(command) +74            "': " + e.strerror)75def capture(command, stderr=None, env=None, dry_run=None, echo=True,76            optional=False, allow_non_zero_exit=False):77    """78    capture(command, ...) -> str79    Execute the given command and return the standard output.80    This function will raise an exception on any command failure.81    """82    dry_run = _coerce_dry_run(dry_run)83    if dry_run or echo:84        _echo_command(dry_run, command, env=env)85    if dry_run:86        return87    _env = None88    if env is not None:89        _env = dict(os.environ)90        _env.update(env)91    try:92        out = subprocess.check_output(command, env=_env, stderr=stderr)93        # Coerce to `str` hack. not py3 `byte`, not py2 `unicode`.94        return str(out.decode())95    except subprocess.CalledProcessError as e:96        if allow_non_zero_exit:97            return e.output98        if optional:99            return None100        diagnostics.fatal(101            "command terminated with a non-zero exit status " +102            str(e.returncode) + ", aborting")103    except OSError as e:104        if optional:105            return None106        diagnostics.fatal(107            "could not execute '" + quote_command(command) +108            "': " + e.strerror)109@contextmanager110def pushd(path, dry_run=None, echo=True):111    dry_run = _coerce_dry_run(dry_run)112    old_dir = os.getcwd()113    if dry_run or echo:114        _echo_command(dry_run, ["pushd", path])115    if not dry_run:116        os.chdir(path)117    yield118    if dry_run or echo:119        _echo_command(dry_run, ["popd"])120    if not dry_run:121        os.chdir(old_dir)122def makedirs(path, dry_run=None, echo=True):123    dry_run = _coerce_dry_run(dry_run)124    if dry_run or echo:125        _echo_command(dry_run, ['mkdir', '-p', path])126    if dry_run:127        return128    if not os.path.isdir(path):129        os.makedirs(path)130def rmtree(path, dry_run=None, echo=True):131    dry_run = _coerce_dry_run(dry_run)132    if dry_run or echo:133        _echo_command(dry_run, ['rm', '-rf', path])134    if dry_run:135        return136    if os.path.exists(path):137        shutil.rmtree(path)138def copytree(src, dest, dry_run=None, echo=True):139    dry_run = _coerce_dry_run(dry_run)140    if dry_run or echo:141        _echo_command(dry_run, ['cp', '-r', src, dest])142    if dry_run:143        return144    shutil.copytree(src, dest)145# Initialized later146lock = None147def run(*args, **kwargs):148    repo_path = os.getcwd()149    echo_output = kwargs.pop('echo', False)150    dry_run = kwargs.pop('dry_run', False)151    env = kwargs.pop('env', None)152    if dry_run:153        _echo_command(dry_run, *args, env=env)...jnsgit.py
Source:jnsgit.py  
1import shlex2import subprocess3_DIM = '\033[2m'4_PLAIN = '\033[0m'5def branch_name(cwd='.', dry_run=False, print_cmd=False) -> str:6    return _check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd)7def checkout(branch_name, cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:8    return _call(['git', 'checkout', branch_name], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)9def commit(msg=None, cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:10    cmd = ['git', 'commit']11    if msg:12        cmd.append('--message')13        cmd.append(msg)14    return _call(cmd, cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)15def commit_count_between(branch1, branch2, cwd='.', dry_run=False, print_cmd=False) -> int:16    count = _check_output(['git', 'rev-list', '--count', '{}...{}'.format(branch1, branch2)],17                          cwd=cwd, dry_run=dry_run, print_cmd=print_cmd)18    if not dry_run:19        count = int(count)20    return count21def last_commit_msg(cwd='.', dry_run=False, print_cmd=False) -> str:22    return _check_output(['git', 'log', '--format=%s', '-1'], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd)23def rebase(upstream, branch=None, interactive=False, cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:24    cmd = ['git', 'rebase']25    if interactive:26        cmd.append('--interactive')27    cmd.append(upstream)28    if branch:29        cmd.append(branch)30    return _call(cmd, cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)31def status(cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:32    return _call(['git', 'status'], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)33def stage_all(cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:34    return _call(['git', 'add', '--all'], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)35def pull(cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:36    return _call(['git', 'pull'], cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)37def push(repository=None, branch=None, set_upstream=False, force=False, cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:38    cmd = ['git', 'push']39    if force:40        cmd.append('--force')41    if set_upstream:42        cmd.append('--set-upstream')43    if repository:44        cmd.append(repository)45    if branch:46        cmd.append(branch)47    return _call(cmd, cwd=cwd, dry_run=dry_run, print_cmd=print_cmd, strict=strict)48def _call(cmd, cwd='.', dry_run=False, print_cmd=False, strict=True) -> int:49    exit_code = 050    if print_cmd:51        _print_command(cmd)52    if not dry_run:53        if strict:54            exit_code = subprocess.check_call(cmd, cwd=cwd)55        else:56            exit_code = subprocess.call(cmd, cwd=cwd)57    return exit_code58def _check_output(cmd, cwd='.', dry_run=False, print_cmd=False) -> str:59    output = ''60    if print_cmd:61        _print_command(cmd)62    if not dry_run:63        output = subprocess.check_output(cmd, cwd=cwd).decode('utf-8').strip()64    return output65def _print_command(cmd) -> None:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
