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


Python Provider.EC2属性代码示例

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


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

示例1: save

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def save(self, master_key: PKey) -> None:
        public_key = format_openssh_pubkey(master_key)
        driver = self.driver
        try:
            key_pair = driver.get_key_pair(self.key_pair_name)
        except KeyPairDoesNotExistError:
            pass
        except MalformedResponseError as e:
            # FIXME: EC2 driver seems to raise MalformedResponseError
            # instead of KeyPairDoesNotExistError.
            if not issubclass(e.driver, EC2NodeDriver):
                raise
            tree = xml.etree.ElementTree.fromstring(e.body)
            if not (tree.tag == 'Response' and
                    getattr(tree.find('Errors/Error/Code'), 'text', None) ==
                    'InvalidKeyPair.NotFound'):
                raise
        else:
            driver.delete_key_pair(key_pair)
        driver.import_key_pair_from_string(self.key_pair_name, public_key)
        self.master_key_store.save(master_key) 
开发者ID:spoqa,项目名称:geofront,代码行数:23,代码来源:cloud.py

示例2: __init__

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def __init__(self, region=None):
        """
        Initialize an EC2 driver factory for a certain AWS region

        :param region: The AWS region to operate within
        :type region: string
        """
        self.log = logging.getLogger(__name__)
        self.IAM_METADATA_URL = "http://169.254.169.254/latest/meta-data/iam/security-credentials"

        # First check if AWS_IAM_ROLE is defined
        aws_iam_role = os.environ.get("AWS_IAM_ROLE", None)
        if aws_iam_role is not None:
            # Get credentials from IAM role
            self.aws_ak, self.aws_sk, self.token = \
                self._get_aws_credentials_from_iam_role(aws_iam_role)
        else:
            # Get credentials from environment variables
            self.log.debug('getting AWS credentials from environment variables AWS_ACCESS_KEY_ID, '
                           'AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION')
            self.aws_ak = os.environ.get('AWS_ACCESS_KEY_ID')
            self.aws_sk = os.environ.get('AWS_SECRET_ACCESS_KEY')
            self.region = region if region is not None else os.environ.get("AWS_DEFAULT_REGION") 
开发者ID:BBVA,项目名称:chaos-monkey-engine,代码行数:25,代码来源:ec2_driver.py

示例3: get_libcloud_driver

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def get_libcloud_driver():
    """
    Return Libcloud driver instance.
    """
    cls = get_driver(Provider.EC2)
    driver = cls(ACCESS_KEY, SECRET_KEY, region=REGION)
    return driver 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:9,代码来源:packages_sanity_tests.py

示例4: get_driver

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def get_driver(self):
        """
        Return a Libcloud driver for AWS EC2 Provider

        :return: Compute driver
        :type driver: Libcloud compute driver
        """
        return (get_driver(Provider.EC2))(self.aws_ak, self.aws_sk, region=self.region) 
开发者ID:BBVA,项目名称:chaos-monkey-engine,代码行数:10,代码来源:ec2_driver.py

示例5: destroy

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def destroy(self):
        print("Now trying to destroy the EC2 node.")
        if self.node.destroy():
            print("Successfully destroyed.")
        else:
            print("There was in issue in destorying the node.") 
开发者ID:kushaldas,项目名称:tunir,代码行数:8,代码来源:tuniraws.py

示例6: aws_and_run

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def aws_and_run(config):
    """Takes a config object, starts a new EC2 instance, and then returns it.

    :param config: Dictionary

    :returns: EC2Node object
    """
    node = EC2Node(config['access_key'], config['secret_key'],
                   config['image'], config['size_id'], config.get('region', 'us-west-1'),
                   config.get('aki', None), config.get('keyname', 'ssh'), config.get('security_group', 'ssh'),
                   config.get('virt_type', 'paravirtual'))
    if not node.failed:  # Means we have an ip
        config['host_string'] = node.ip
        config['ip'] = node.ip
    return node, config 
开发者ID:kushaldas,项目名称:tunir,代码行数:17,代码来源:tuniraws.py

示例7: get_node_data_aws

# 需要导入模块: from libcloud.compute.types import Provider [as 别名]
# 或者: from libcloud.compute.types.Provider import EC2 [as 别名]
def get_node_data_aws():
    """
    Retrieve bootstrap public IP and master node private IPs running in aws

    Raises:
        NodeNotFoundError: If we are unable to find the bootstrap node or IP

    Returns:
        dict: bootstrap and master node IP data

    """
    session = boto3.Session()
    credentials = session.get_credentials().get_frozen_credentials()
    ec2_driver = get_driver(Provider.EC2)
    driver = ec2_driver(
        credentials.access_key, credentials.secret_key,
        region=config.ENV_DATA['region']
    )
    cluster_path = config.ENV_DATA['cluster_path']
    infra_id = get_infra_id(cluster_path)
    bootstrap_name = f"{infra_id}-bootstrap"
    master_pattern = f"{infra_id}-master"
    data = dict()
    try:
        bootstrap_node = [
            node for node in driver.list_nodes()
            if bootstrap_name == node.name
        ][0]
        bootstrap_ip = bootstrap_node.public_ips[0]
        logger.info(
            "Found bootstrap node %s with IP %s", bootstrap_name, bootstrap_ip
        )
        data['bootstrap_ip'] = bootstrap_ip

    except IndexError:
        raise NodeNotFoundError(
            f"Unable to find bootstrap node with name {bootstrap_name}"
        )
    master_nodes = [
        node for node in driver.list_nodes()
        if master_pattern in node.name
    ]
    master_ips = [master.private_ips[0] for master in master_nodes]
    data['master_ips'] = [ip for ip in master_ips if ip is not None]
    if len(data['master_ips']) < config.ENV_DATA['master_replicas']:
        logger.warning('IP data was not found for all master nodes')
    logger.debug(data)
    return data 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:50,代码来源:bootstrap.py


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