当前位置: 首页>>代码示例>>Python>>正文


Python ec2.connect_to_region方法代码示例

本文整理汇总了Python中boto.ec2.connect_to_region方法的典型用法代码示例。如果您正苦于以下问题:Python ec2.connect_to_region方法的具体用法?Python ec2.connect_to_region怎么用?Python ec2.connect_to_region使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.ec2的用法示例。


在下文中一共展示了ec2.connect_to_region方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def delete(self, resource):
        if resource.wrapped.state in Instance.VALID_TARGET_STATES:
            raise Warning("state '{0}' is a valid target state, skipping".format(
                resource.wrapped.state))
        connection = ec2.connect_to_region(resource.region)
        if self.dry_run:
            try:
                connection.terminate_instances([resource.wrapped.id], dry_run=True)
            except EC2ResponseError as exc:
                if exc.status == 412:  # Precondition Failed
                    raise Warning("Termination {message}".format(**vars(exc)))
                raise
        else:
            instances = connection.terminate_instances([resource.wrapped.id], dry_run=False)
            self.logger.info("Initiating shutdown sequence for {0}".format(instances))
            return instances 
开发者ID:Scout24,项目名称:aws-monocyte,代码行数:18,代码来源:ec2.py

示例2: get_instance

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_instance(self, region, instance_id):
        ''' Gets details about a specific instance '''
        if self.eucalyptus:
            conn = boto.connect_euca(self.eucalyptus_host)
            conn.APIVersion = '2010-08-31'
        else:
            conn = ec2.connect_to_region(region)

        # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
        if conn is None:
            print("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
            sys.exit(1)

        reservations = conn.get_all_instances([instance_id])
        for reservation in reservations:
            for instance in reservation.instances:
                return instance 
开发者ID:d1vious,项目名称:splunk-ansible-advance,代码行数:19,代码来源:ec2.py

示例3: get_rds_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_rds_instances_by_region(self, region):
        ''' Makes an AWS API call to the list of RDS instances in a particular
        region '''

        try:
            conn = rds.connect_to_region(region)
            if conn:
                instances = conn.get_all_dbinstances()
                for instance in instances:
                    self.add_rds_instance(instance, region)
        except boto.exception.BotoServerError as e:
            error = e.reason
            
            if e.error_code == 'AuthFailure':
                error = self.get_auth_error_message()
            if not e.reason == "Forbidden":
                error = "Looks like AWS RDS is down:\n%s" % e.message
            self.fail_with_error(error) 
开发者ID:HighOps,项目名称:ansible_ec2_vpc_nat_asg,代码行数:20,代码来源:ec2.py

示例4: get_instance

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_instance(self, region, instance_id):
        ''' Gets details about a specific instance '''
        if self.eucalyptus:
            conn = boto.connect_euca(self.eucalyptus_host)
            conn.APIVersion = '2010-08-31'
        else:
            conn = ec2.connect_to_region(region)
 
        # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
        if conn is None:
            print("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
            sys.exit(1)
 
        reservations = conn.get_all_instances([instance_id])
        for reservation in reservations:
            for instance in reservation.instances:
                return instance 
开发者ID:geerlingguy,项目名称:ansible-for-devops,代码行数:19,代码来源:ec2.py

示例5: get_instance

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_instance(self, region, instance_id):
        """ Gets details about a specific instance """
        conn = ec2.connect_to_region(region)

        # connect_to_region will fail "silently" by returning None if the
        # region name is wrong or not supported
        if conn is None:
            sys.exit(
                "region name: %s likely not supported, or AWS is down. "
                "connection to region failed." % region
            )

        reservations = conn.get_all_instances([instance_id])
        for reservation in reservations:
            for instance in reservation.instances:
                return instance 
开发者ID:adobe,项目名称:ops-cli,代码行数:18,代码来源:ec2inventory.py

示例6: get_rds_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_rds_instances_by_region(self, region):
        ''' Makes an AWS API call to the list of RDS instances in a particular
        region '''

        try:
            conn = rds.connect_to_region(region)
            if conn:
                instances = conn.get_all_dbinstances()
                for instance in instances:
                    self.add_rds_instance(instance, region)
        except boto.exception.BotoServerError as e:
            error = e.reason

            if e.error_code == 'AuthFailure':
                error = self.get_auth_error_message()
            if not e.reason == "Forbidden":
                error = "Looks like AWS RDS is down:\n%s" % e.message
            self.fail_with_error(error, 'getting RDS instances') 
开发者ID:FairwindsOps,项目名称:pentagon,代码行数:20,代码来源:ec2.py

示例7: __init__

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def __init__(self, accessKeyId=None, accessKey=None):
        """ log - logger for the instance
        connection - EC2Connection object that stores the connection
        info to the EC2 network
        instance - Instance object that stores information about the
        VM created
        """
        self.ssh_flags = Ec2SSH._SSH_FLAGS
        if accessKeyId:
            self.connection = ec2.connect_to_region(config.Config.EC2_REGION,
                    aws_access_key_id=accessKeyId, aws_secret_access_key=accessKey)
            self.useDefaultKeyPair = False
        else:
            self.connection = ec2.connect_to_region(config.Config.EC2_REGION)
            self.useDefaultKeyPair = True
        self.log = logging.getLogger("Ec2SSH") 
开发者ID:autolab,项目名称:Tango,代码行数:18,代码来源:ec2SSH.py

示例8: aws_provisioner

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def aws_provisioner(
    access_key, secret_access_token, keyname, region, zone, security_groups,
    instance_type=b"m3.large", session_token=None,
):
    """
    Create an IProvisioner for provisioning nodes on AWS EC2.

    :param bytes access_key: The access_key to connect to AWS with.
    :param bytes secret_access_token: The corresponding secret token.
    :param bytes region: The AWS region in which to launch the instance.
    :param bytes zone: The AWS zone in which to launch the instance.
    :param bytes keyname: The name of an existing ssh public key configured in
       AWS. The provision step assumes the corresponding private key is
       available from an agent.
    :param list security_groups: List of security groups to put created nodes
        in.
    :param bytes instance_type: AWS instance type for cluster nodes.
    :param bytes session_token: The optional session token, if required
        for connection.
    """
    conn = connect_to_region(
        region,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_access_token,
        security_token=session_token,
    )
    if conn is None:
        raise ValueError("Invalid region: {}".format(region))
    return AWSProvisioner(
        _connection=conn,
        _keyname=keyname,
        _security_groups=security_groups,
        _zone=zone,
        _default_size=instance_type,
    ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:37,代码来源:_aws.py

示例9: fetch_unwanted_resources

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def fetch_unwanted_resources(self):
        for region_name in self.region_names:
            connection = ec2.connect_to_region(region_name)
            resources = connection.get_only_instances() or []
            for resource in resources:
                resource_wrapper = Resource(resource=resource,
                                            resource_type=self.resource_type,
                                            resource_id=resource.id,
                                            creation_date=resource.launch_time,
                                            region=region_name)
                if resource.id in self.ignored_resources:
                    self.logger.info('IGNORE ' + self.to_string(resource_wrapper))
                    continue
                yield resource_wrapper 
开发者ID:Scout24,项目名称:aws-monocyte,代码行数:16,代码来源:ec2.py

示例10: get_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_instances_by_region(self, region):
        ''' Makes an AWS EC2 API call to the list of instances in a particular
        region '''

        try:
            if self.eucalyptus:
                conn = boto.connect_euca(host=self.eucalyptus_host)
                conn.APIVersion = '2010-08-31'
            else:
                conn = ec2.connect_to_region(region)

            # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
            if conn is None:
                print("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
                sys.exit(1)
 
            reservations = conn.get_all_instances()
            for reservation in reservations:
                for instance in reservation.instances:
                    self.add_instance(instance, region)
        
        except boto.exception.BotoServerError, e:
            if  not self.eucalyptus:
                print "Looks like AWS is down again:"
            print e
            sys.exit(1) 
开发者ID:d1vious,项目名称:splunk-ansible-advance,代码行数:28,代码来源:ec2.py

示例11: get_rds_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_rds_instances_by_region(self, region):
	''' Makes an AWS API call to the list of RDS instances in a particular
        region '''

        try:
            conn = rds.connect_to_region(region)
            if conn:
                instances = conn.get_all_dbinstances()
                for instance in instances:
                    self.add_rds_instance(instance, region)
        except boto.exception.BotoServerError, e:
            if not e.reason == "Forbidden":
                print "Looks like AWS RDS is down: "
                print e
                sys.exit(1) 
开发者ID:d1vious,项目名称:splunk-ansible-advance,代码行数:17,代码来源:ec2.py

示例12: connect

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def connect(self, region):
        ''' create connection to api server'''
        if self.eucalyptus:
            conn = boto.connect_euca(host=self.eucalyptus_host)
            conn.APIVersion = '2010-08-31'
        else:
            conn = ec2.connect_to_region(region)
        # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
        if conn is None:
            self.fail_with_error("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
        return conn 
开发者ID:HighOps,项目名称:ansible_ec2_vpc_nat_asg,代码行数:13,代码来源:ec2.py

示例13: get_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_instances_by_region(self, region):
        ''' Makes an AWS EC2 API call to the list of instances in a particular
        region '''
 
        try:
            if self.eucalyptus:
                conn = boto.connect_euca(host=self.eucalyptus_host)
                conn.APIVersion = '2010-08-31'
            else:
                conn = ec2.connect_to_region(region)
 
            # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported
            if conn is None:
                print("region name: %s likely not supported, or AWS is down.  connection to region failed." % region)
                sys.exit(1)
 
            reservations = []
            if self.ec2_instance_filters:
                for filter_key, filter_values in self.ec2_instance_filters.iteritems():
                    reservations.extend(conn.get_all_instances(filters = { filter_key : filter_values }))
            else:
                reservations = conn.get_all_instances()
 
            for reservation in reservations:
                for instance in reservation.instances:
                    self.add_instance(instance, region)
 
        except boto.exception.BotoServerError, e:
            if  not self.eucalyptus:
                print "Looks like AWS is down again:"
            print e
            sys.exit(1) 
开发者ID:geerlingguy,项目名称:ansible-for-devops,代码行数:34,代码来源:ec2.py

示例14: get_rds_instances_by_region

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def get_rds_instances_by_region(self, region):
        ''' Makes an AWS API call to the list of RDS instances in a particular
        region '''
 
        try:
            conn = rds.connect_to_region(region)
            if conn:
                instances = conn.get_all_dbinstances()
                for instance in instances:
                    self.add_rds_instance(instance, region)
        except boto.exception.BotoServerError, e:
            if not e.reason == "Forbidden":
                print "Looks like AWS RDS is down: "
                print e
                sys.exit(1) 
开发者ID:geerlingguy,项目名称:ansible-for-devops,代码行数:17,代码来源:ec2.py

示例15: __init__

# 需要导入模块: from boto import ec2 [as 别名]
# 或者: from boto.ec2 import connect_to_region [as 别名]
def __init__(self):

        """
        Initialize the EC2 connection.
        """

        self.conn = ec2.connect_to_region(config['ec2']['region']) 
开发者ID:davidmcclure,项目名称:open-syllabus-project,代码行数:9,代码来源:client.py


注:本文中的boto.ec2.connect_to_region方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。