當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。