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


Python providers.get_driver方法代码示例

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


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

示例1: concrete_system

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def concrete_system(self, radl_system, str_url, auth_data):
        url = urlparse(str_url)
        protocol = url[0]
        src_host = url[1].split(':')[0]

        if protocol == "cst" and self.cloud.server == src_host:
            driver = self.get_driver(auth_data)

            res_system = radl_system.clone()
            instance_type = self.get_instance_type(driver.list_sizes(), res_system)
            self.update_system_info_from_instance(res_system, instance_type)

            username = res_system.getValue('disk.0.os.credentials.username')
            if not username:
                res_system.setValue('disk.0.os.credentials.username', self.DEFAULT_USER)

            return res_system
        else:
            return None 
开发者ID:grycap,项目名称:im,代码行数:21,代码来源:CloudStack.py

示例2: get_node_with_id

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_node_with_id(self, node_id, auth_data):
        """
        Get the node with the specified ID

        Arguments:
           - node_id(str): ID of the node to get
           - auth(Authentication): parsed authentication tokens.
        Returns: a :py:class:`libcloud.compute.base.Node` with the node info
        """
        driver = self.get_driver(auth_data)
        nodes = driver.list_nodes()

        res = None
        for node in nodes:
            if node.id == node_id:
                res = node
        return res 
开发者ID:grycap,项目名称:im,代码行数:19,代码来源:LibCloud.py

示例3: __init__

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def __init__(self, infra, spec, provider_name=None):
        """
        :param dict infra: Dict of infrastructure information
        :param dict spec: Dict of a parsed specification
        :param str provider_name: Name of provider, if not in "provider" key
        """
        super(LibcloudInterface, self).__init__(infra=infra, spec=spec)
        self._log = logging.getLogger(str(self.__class__))
        self._log.debug("Initializing %s", self.__class__)

        # Used for interfaces such as libvirt
        if provider_name is None:
            self.provider_name = self.infra["provider"]
        else:
            self.provider_name = provider_name
        self.driver = get_driver(getattr(Provider, self.provider_name))

        # TODO: temporary for testing
        self.username = "test"
        self.api_key = "key"
        self.provider = self.driver(user_id=self.username, key=self.api_key) 
开发者ID:GhostofGoes,项目名称:ADLES,代码行数:23,代码来源:libcloud_interface.py

示例4: get_openstack_driver

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_openstack_driver(yaml):
    OpenStack = get_driver(Provider.OPENSTACK)
    glbs = yaml.get('globals')
    os_cred = glbs.get('openstack-credentials')
    username = os_cred['username']
    password = os_cred['password']
    auth_url = os_cred['auth-url']
    auth_version = os_cred['auth-version']
    tenant_name = os_cred['tenant-name']
    service_region = os_cred['service-region']
    driver = OpenStack(
        username,
        password,
        ex_force_auth_url=auth_url,
        ex_force_auth_version=auth_version,
        ex_tenant_name=tenant_name,
        ex_force_service_region=service_region,
        ex_domain_name='redhat.com'
    )
    return driver 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:22,代码来源:utils.py

示例5: get_driver

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_driver(self, auth_data):
        """
        Get the driver from the auth data

        Arguments:
                - auth(Authentication): parsed authentication tokens.

        Returns: a :py:class:`libcloud.compute.base.NodeDriver` or None in case of error
        """
        auths = auth_data.getAuthInfo(self.type, self.cloud.server)
        if not auths:
            raise Exception("No auth data has been specified to CloudStack.")
        else:
            auth = auths[0]

        if self.driver and self.auth.compare(auth_data, self.type, self.cloud.server):
            return self.driver
        else:
            self.auth = auth_data
            if 'username' in auth and 'password' in auth:
                apikey = auth['username']
                secretkey = auth['password']

                protocol = self.cloud.protocol
                if not protocol:
                    protocol = "http"
                port = "" if self.cloud.port == -1 else ":" % self.cloud.port
                url = protocol + "://" + self.cloud.server + port + self.cloud.path

                Driver = get_driver(Provider.CLOUDSTACK)
                driver = Driver(key=apikey, secret=secretkey, url=url)
                self.driver = driver

                return driver
            else:
                self.log_error("Incorrect auth data")
                return None 
开发者ID:grycap,项目名称:im,代码行数:39,代码来源:CloudStack.py

示例6: concrete_system

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def concrete_system(self, radl_system, str_url, auth_data):
        url = urlparse(str_url)
        protocol = url[0]
        PROTOCOL_MAP = {"Amazon EC2": "aws", "OpenNebula": "one", "OpenStack": "ost", "LibVirt": "file"}

        driver = self.get_driver(auth_data)
        req_protocol = PROTOCOL_MAP.get(driver.name, None)

        if req_protocol is None or protocol == req_protocol:
            res_system = radl_system.clone()
            instance_type = self.get_instance_type(driver.list_sizes(), res_system)
            self.update_system_info_from_instance(res_system, instance_type)
            return res_system
        else:
            return None 
开发者ID:grycap,项目名称:im,代码行数:17,代码来源:LibCloud.py

示例7: get_node_with_id

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_node_with_id(self, node_id, auth_data):
        """
        Get the node with the specified ID

        Arguments:
           - node_id(str): ID of the node to get
           - auth(Authentication): parsed authentication tokens.
        Returns: a :py:class:`libcloud.compute.base.Node` with the node info
        """
        driver = self.get_driver(auth_data)
        node = driver.ex_get_node_details(node_id)
        return node 
开发者ID:grycap,项目名称:im,代码行数:14,代码来源:OpenStack.py

示例8: concrete_system

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def concrete_system(self, radl_system, str_url, auth_data):
        url = urlparse(str_url)
        protocol = url[0]
        src_host = url[1].split(':')[0]

        if protocol == "appdb":
            site_url, image_id, msg = AppDB.get_image_data(str_url, "openstack")
            if not image_id or not site_url:
                self.log_error(msg)
                return None

            protocol = "ost"
            url = urlparse(site_url)
            src_host = url[1].split(':')[0]

        if protocol == "ost" and self.cloud.server == src_host:
            driver = self.get_driver(auth_data)

            res_system = radl_system.clone()
            instance_type = self.get_instance_type(driver.list_sizes(), res_system)
            self.update_system_info_from_instance(res_system, instance_type)

            username = res_system.getValue('disk.0.os.credentials.username')
            if not username:
                res_system.setValue('disk.0.os.credentials.username', self.DEFAULT_USER)

            return res_system
        else:
            return None 
开发者ID:grycap,项目名称:im,代码行数:31,代码来源:OpenStack.py

示例9: delete_image

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def delete_image(self, image_url, auth_data):
        driver = self.get_driver(auth_data)
        image_id = os.path.basename(image_url)
        try:
            image = driver.get_image(image_id)
        except Exception as ex:
            self.log_exception("Error getting image.")
            return (False, "Error getting image %s: %s" % (image_id, get_ex_error(ex)))
        try:
            driver.delete_image(image)
            return True, ""
        except Exception as ex:
            self.log_exception("Error deleting image.")
            return (False, "Error deleting image.: %s" % get_ex_error(ex)) 
开发者ID:grycap,项目名称:im,代码行数:16,代码来源:OpenStack.py

示例10: get_rackspace_driver

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_rackspace_driver(rackspace):
    """
    Get a libcloud Rackspace driver given some credentials and other
    configuration.
    """
    rackspace = get_driver(Provider.RACKSPACE)(
        rackspace['username'], rackspace['key'],
        region=rackspace['region'],
    )
    return rackspace 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:12,代码来源:cleanup.py

示例11: get_ec2_driver

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def get_ec2_driver(aws):
    """
    Get a libcloud EC2 driver given some credentials and other configuration.
    """
    ec2 = get_driver(Provider.EC2)(
        aws['access_key'], aws['secret_access_token'],
        region=aws['region'],
    )
    return ec2 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:11,代码来源:cleanup.py

示例12: rackspace_provisioner

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def rackspace_provisioner(username, key, region, keyname):
    """
    Create a LibCloudProvisioner for provisioning nodes on rackspace.

    :param bytes username: The user to connect to rackspace with.
    :param bytes key: The API key associated with the user.
    :param bytes region: The rackspace region in which to launch the instance.
    :param bytes keyname: The name of an existing ssh public key configured in
       rackspace. The provision step assumes the corresponding private key is
       available from an agent.
    """
    # Import these here, so that this can be imported without
    # installng libcloud.
    from libcloud.compute.providers import get_driver, Provider

    driver = get_driver(Provider.RACKSPACE)(
        key=username,
        secret=key,
        region=region)

    provisioner = LibcloudProvisioner(
        driver=driver,
        keyname=keyname,
        image_names=IMAGE_NAMES,
        create_node_arguments=lambda **kwargs: {
            "ex_config_drive": "true",
        },
        provision=provision_rackspace,
        default_size="performance1-8",
        get_default_user=get_default_username,
    )

    return provisioner 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:35,代码来源:_rackspace.py

示例13: get_libcloud_driver

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [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

示例14: main

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def main():
    key_values = ['project', 'firewall_db', 'keyfile']
    if(len(sys.argv) != 2):
        sys.exit(1)

    # parse config.json
    config_file = sys.argv[1]
    config_content = json.load(open(config_file))
    projects = []

    for value in config_content:
        temp = []
        for key in key_values:
            temp.append(value[key])
        projects.append(temp)

    for project in projects:
        project_name = project[0]
        db_filename = project[1]
        key_file = project[2]
        key_content = json.load(open(key_file))

        ComputeEngine = get_driver(Provider.GCE)
        driver = ComputeEngine(
            key_content['client_email'],
            key_file,
            project=project_name)
        gcp_firewall_rules = driver.ex_list_firewalls()
        firewall_list = convert_to_list(gcp_firewall_rules, db_filename)

        with open(db_filename, 'w') as f:
            json.dump(firewall_list, f, indent=2)
    sys.exit(0) 
开发者ID:spotify,项目名称:gcp-firewall-enforcer,代码行数:35,代码来源:gcp_rule_parser.py

示例15: create_libcloud_session

# 需要导入模块: from libcloud.compute import providers [as 别名]
# 或者: from libcloud.compute.providers import get_driver [as 别名]
def create_libcloud_session():
    provider = config.profile.get('platform')['provider']
    cls = get_driver(getattr(Provider, provider))
    params = config.profile.get('platform')
    if not params:
        raise ValueError("Profile not configured with Platform Parameters")
    if provider == 'EC2':
        return cls(
                **{x: y for x, y in params.items() if x in ['key', 'secret', 'region']}
            )
    elif provider == 'AZURE_ARM':
        return cls(tenant_id=params['tenant'],
                   subscription_id=params['subscription'],
                   key=params['application'],
                   secret=params['secret'],
                   region=params['region'])
    elif provider == 'GCE':
        return cls(params['serviceaccount'],
                   params['apikeypath'],
                   project=params['project'])
    elif provider == 'OPENSTACK':
        # As this is accessible ONLY over VPN, I feel less concerned about MITM attacks
        # TODO: Get Proper certs for Openstack
        # https://buildmedia.readthedocs.org/media/pdf/libcloud/v2.4.0/libcloud.pdf
        # search 'libcloud.security
        libcloud.security.VERIFY_SSL_CERT = params['verify_ssl']
        if params['verify_ssl'] is True and 'cacert_path' in params and params['cacert_path']:
            libcloud.security.CA_CERTS_PATH = params['cacert_path']
        # This works for Openstack keystone v3
        return cls(
            params['username'],
            params['password'],
            ex_tenant_name=params['project'],
            ex_force_auth_url=params['auth_url'],
            ex_force_auth_version=params['auth_mode']
        )
    else:
        raise ValueError("Provider %s not Supported", provider) 
开发者ID:Chaffelson,项目名称:whoville,代码行数:40,代码来源:infra.py


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