當前位置: 首頁>>代碼示例>>Python>>正文


Python connection.from_config方法代碼示例

本文整理匯總了Python中openstack.connection.from_config方法的典型用法代碼示例。如果您正苦於以下問題:Python connection.from_config方法的具體用法?Python connection.from_config怎麽用?Python connection.from_config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在openstack.connection的用法示例。


在下文中一共展示了connection.from_config方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def setUp(self):
        super(TestZone, self).setUp()
        self.require_service('dns')

        self.conn = connection.from_config(cloud_name=base.TEST_CLOUD_NAME)

        # Note: zone deletion is not an immediate operation, so each time
        # chose a new zone name for a test
        # getUniqueString is not guaranteed to return unique string between
        # different tests of the same class.
        self.ZONE_NAME = 'example-{0}.org.'.format(random.randint(1, 10000))

        self.zone = self.conn.dns.create_zone(
            name=self.ZONE_NAME,
            email='joe@example.org',
            type='PRIMARY',
            ttl=7200,
            description='example zone'
        )
        self.addCleanup(self.conn.dns.delete_zone, self.zone) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:22,代碼來源:test_zone.py

示例2: setUp

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def setUp(self):
        super(TestImage, self).setUp()
        opts = self.ImageOpts()
        self.conn = connection.from_config(
            cloud_name=base.TEST_CLOUD_NAME, options=opts)

        self.img = self.conn.image.upload_image(
            name=TEST_IMAGE_NAME,
            disk_format='raw',
            container_format='bare',
            # TODO(mordred): This is not doing what people think it is doing.
            # This is EPICLY broken. However, rather than fixing it as it is,
            # we need to just replace the image upload code with the stuff
            # from shade. Figuring out mapping the crap-tastic arbitrary
            # extra key-value pairs into Resource is going to be fun.
            properties='{"description": "This is not an image"}',
            data=open('CONTRIBUTING.rst', 'r')
        )
        self.addCleanup(self.conn.image.delete_image, self.img) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:21,代碼來源:test_image.py

示例3: get_openstack_connection

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def get_openstack_connection(region_name):
    """
    Get the OpenStack Connection object.

    This is the new, all-powerful Python API for OpenStack. It should be used
    instead of the service-specific APIs such as the Nova API below.

    The returned Connection object has an attribute for each available service,
    e.g. "compute", "network", etc.

    """

    loader = occ.OpenStackConfig(
        load_yaml_config=False,
        app_name='opencraft-im',
        app_version='1.0')
    cloud_region = loader.get_one_cloud(
        region_name=region_name,
        auth_type='password',
        auth=dict(
            auth_url=settings.OPENSTACK_AUTH_URL,
            username=settings.OPENSTACK_USER,
            project_name=settings.OPENSTACK_TENANT,
            password=settings.OPENSTACK_PASSWORD,
            user_domain_id="default",
            user_domain_name="Default",
            project_domain_id="default",
            project_domain_name="Default",
        ))
    conn = connection.from_config(cloud_config=cloud_region)
    conn.session.user_agent = "opencraft-im"

    # API queries via the nova client occasionally get connection errors from the OpenStack provider.
    # To gracefully recover when the unavailability is short-lived, ensure safe requests (as per
    # urllib3's definition) are retried before giving up.
    adapter = requests.adapters.HTTPAdapter(max_retries=get_requests_retry())
    conn.session.session.mount('http://', adapter)
    conn.session.session.mount('https://', adapter)

    return conn 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:42,代碼來源:openstack_utils.py

示例4: create_connection_from_config

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def create_connection_from_config(name=None):
    """ Creates a new open stack connection """
    occ = config.OpenStackConfig()
    cloud = occ.get_one_cloud(name)
    return connection.from_config(cloud_config=cloud) 
開發者ID:bloomberg,項目名稱:powerfulseal,代碼行數:7,代碼來源:open_stack_driver.py

示例5: hypervisors

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def hypervisors():
    global HYPERVISORS
    if HYPERVISORS:
        return True
    HYPERVISORS = connection.Connection.list_hypervisors(
        connection.from_config(cloud_name=base.TEST_CLOUD_NAME))
    return bool(HYPERVISORS) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:9,代碼來源:test_host.py

示例6: test_from_config_given_config

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def test_from_config_given_config(self):
        cloud_region = (openstack.config.OpenStackConfig().
                        get_one("sample-cloud"))

        sot = connection.from_config(config=cloud_region)

        self.assertEqual(CONFIG_USERNAME,
                         sot.config.config['auth']['username'])
        self.assertEqual(CONFIG_PASSWORD,
                         sot.config.config['auth']['password'])
        self.assertEqual(CONFIG_AUTH_URL,
                         sot.config.config['auth']['auth_url'])
        self.assertEqual(CONFIG_PROJECT,
                         sot.config.config['auth']['project_name']) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:16,代碼來源:test_connection.py

示例7: test_from_config_given_cloud

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def test_from_config_given_cloud(self):
        sot = connection.from_config(cloud="sample-cloud")

        self.assertEqual(CONFIG_USERNAME,
                         sot.config.config['auth']['username'])
        self.assertEqual(CONFIG_PASSWORD,
                         sot.config.config['auth']['password'])
        self.assertEqual(CONFIG_AUTH_URL,
                         sot.config.config['auth']['auth_url'])
        self.assertEqual(CONFIG_PROJECT,
                         sot.config.config['auth']['project_name']) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:13,代碼來源:test_connection.py

示例8: test_from_config_given_cloud_name

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def test_from_config_given_cloud_name(self):
        sot = connection.from_config(cloud_name="sample-cloud")

        self.assertEqual(CONFIG_USERNAME,
                         sot.config.config['auth']['username'])
        self.assertEqual(CONFIG_PASSWORD,
                         sot.config.config['auth']['password'])
        self.assertEqual(CONFIG_AUTH_URL,
                         sot.config.config['auth']['auth_url'])
        self.assertEqual(CONFIG_PROJECT,
                         sot.config.config['auth']['project_name']) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:13,代碼來源:test_connection.py

示例9: test_from_config_verify

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def test_from_config_verify(self):
        sot = connection.from_config(cloud="insecure-cloud")
        self.assertFalse(sot.session.verify)

        sot = connection.from_config(cloud="cacert-cloud")
        self.assertEqual(CONFIG_CACERT, sot.session.verify) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:8,代碼來源:test_connection.py

示例10: test_from_config_insecure

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def test_from_config_insecure(self):
        # Ensure that the "insecure=True" flag implies "verify=False"
        sot = connection.from_config("insecure-cloud-alternative-format")
        self.assertFalse(sot.session.verify) 
開發者ID:openstack,項目名稱:openstacksdk,代碼行數:6,代碼來源:test_connection.py

示例11: _hypervisors

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def _hypervisors(self):
        hypervisors = connection.Connection.list_hypervisors(
            connection.from_config(cloud_name=TEST_CLOUD_NAME))
        return hypervisors 
開發者ID:openstack,項目名稱:masakari,代碼行數:6,代碼來源:base.py

示例12: make_sdk

# 需要導入模塊: from openstack import connection [as 別名]
# 或者: from openstack.connection import from_config [as 別名]
def make_sdk(options=None, **kwargs):
    """Simple wrapper for getting an OpenStack SDK Connection.

    For completeness, provide a mechanism that matches make_client and
    make_rest_client. The heavy lifting here is done in openstacksdk.

    :rtype: :class:`~openstack.connection.Connection`
    """
    from openstack import connection
    cloud = get_config(options=options, **kwargs)
    return connection.from_config(cloud_config=cloud, options=options) 
開發者ID:openstack,項目名稱:os-client-config,代碼行數:13,代碼來源:__init__.py


注:本文中的openstack.connection.from_config方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。