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


Python connection.Connection方法代码示例

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


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

示例1: setup_openstacksdk

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def setup_openstacksdk():
    auth_plugin = utils.get_auth_plugin('neutron')
    session = utils.get_keystone_session('neutron', auth_plugin)
    # TODO(mdulko): To use Neutron's ability to do compare-and-swap updates we
    #               need to manually add support for inserting If-Match header
    #               into requests. At the moment we only need it for ports.
    #               Remove when lower-constraints openstacksdk supports this.
    os_port.Port.if_match = os_resource.Header('If-Match')
    # TODO(maysams): We need to manually insert allowed_cidrs option
    # as it's only supported from 0.41.0 version. Remove it once
    # lower-constraints supports it.
    os_listener.Listener.allowed_cidrs = os_resource.Body('allowed_cidrs',
                                                          type=list)
    conn = connection.Connection(
        session=session,
        region_name=getattr(config.CONF.neutron, 'region_name', None))
    conn.network.create_ports = partial(_create_ports, conn.network)
    conn.network.add_trunk_subports = partial(_add_trunk_subports,
                                              conn.network)
    conn.network.delete_trunk_subports = partial(_delete_trunk_subports,
                                                 conn.network)
    _clients[_OPENSTACKSDK] = conn 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:24,代码来源:clients.py

示例2: _connect_swift

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def _connect_swift(self, options=None):
        """
        Get an OpenStack Swift (object store) client connection.

        :param options: A dictionary of options from which values will be
            passed to the connection.
        :return: A Swift client connection using the auth credentials held by
            the OpenStackCloudProvider instance
        """
        clean_options = self._clean_options(
            options, swift_client.Connection.__init__)
        storage_url = self._get_config_value(
            'os_storage_url', get_env('OS_STORAGE_URL', None))
        auth_token = self._get_config_value(
            'os_auth_token', get_env('OS_AUTH_TOKEN', None))
        if storage_url and auth_token:
            clean_options['preauthurl'] = storage_url
            clean_options['preauthtoken'] = auth_token
        else:
            clean_options['authurl'] = self.auth_url
            clean_options['session'] = self._keystone_session
        return swift_client.Connection(**clean_options) 
开发者ID:CloudVE,项目名称:cloudbridge,代码行数:24,代码来源:provider.py

示例3: authorize

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def authorize(self):
        """Authorize this Connection

        .. note:: This method is optional. When an application makes a call
                  to any OpenStack service, this method allows you to request
                  a token manually before attempting to do anything else.

        :returns: A string token.

        :raises: :class:`~openstack.exceptions.HttpException` if the
                 authorization fails due to reasons like the credentials
                 provided are unable to be authorized or the `auth_type`
                 argument is missing, etc.
        """
        try:
            return self.session.get_token()
        except keystoneauth1.exceptions.ClientException as e:
            raise exceptions.SDKException(e) 
开发者ID:openstack,项目名称:openstacksdk,代码行数:20,代码来源:connection.py

示例4: setUp

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def setUp(self):
        super(BaseFunctionalTest, self).setUp()
        self.conn = connection.Connection(config=TEST_CLOUD_REGION)
        _disable_keep_alive(self.conn)

        self._demo_name = os.environ.get('OPENSTACKSDK_DEMO_CLOUD', 'devstack')
        self._demo_name_alt = os.environ.get('OPENSTACKSDK_DEMO_CLOUD_ALT',
                                             'devstack-alt')
        self._op_name = os.environ.get(
            'OPENSTACKSDK_OPERATOR_CLOUD', 'devstack-admin')

        self.config = openstack.config.OpenStackConfig()
        self._set_user_cloud()
        self._set_operator_cloud()

        self.identity_version = \
            self.operator_cloud.config.get_api_version('identity')

        # Defines default timeout for wait_for methods used
        # in the functional tests
        self._wait_for_timeout = int(
            os.getenv(self._wait_for_timeout_key, os.getenv(
                'OPENSTACKSDK_FUNC_TEST_TIMEOUT', 300))) 
开发者ID:openstack,项目名称:openstacksdk,代码行数:25,代码来源:base.py

示例5: test_create_session

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def test_create_session(self):
        conn = connection.Connection(cloud='sample-cloud')
        self.assertIsNotNone(conn)
        # TODO(mordred) Rework this - we need to provide requests-mock
        # entries for each of the proxies below
        # self.assertEqual('openstack.proxy',
        #                  conn.alarm.__class__.__module__)
        # self.assertEqual('openstack.clustering.v1._proxy',
        #                  conn.clustering.__class__.__module__)
        # self.assertEqual('openstack.compute.v2._proxy',
        #                  conn.compute.__class__.__module__)
        # self.assertEqual('openstack.database.v1._proxy',
        #                  conn.database.__class__.__module__)
        # self.assertEqual('openstack.identity.v2._proxy',
        #                  conn.identity.__class__.__module__)
        # self.assertEqual('openstack.image.v2._proxy',
        #                  conn.image.__class__.__module__)
        # self.assertEqual('openstack.object_store.v1._proxy',
        #                  conn.object_store.__class__.__module__)
        # self.assertEqual('openstack.load_balancer.v2._proxy',
        #                  conn.load_balancer.__class__.__module__)
        # self.assertEqual('openstack.orchestration.v1._proxy',
        #                  conn.orchestration.__class__.__module__)
        # self.assertEqual('openstack.workflow.v2._proxy',
        #                  conn.workflow.__class__.__module__) 
开发者ID:openstack,项目名称:openstacksdk,代码行数:27,代码来源:test_connection.py

示例6: test_from_session

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def test_from_session(self):
        config = cloud_region.from_session(
            self.cloud.session, region_name=self.test_region)
        self.assertEqual(config.name, 'identity.example.com')
        if not self.test_region:
            self.assertIsNone(config.region_name)
        else:
            self.assertEqual(config.region_name, self.test_region)

        server_id = str(uuid.uuid4())
        server_name = self.getUniqueString('name')
        fake_server = fakes.make_fake_server(server_id, server_name)
        self.register_uris([
            self.get_nova_discovery_mock_dict(),
            dict(method='GET',
                 uri=self.get_mock_url(
                     'compute', 'public', append=['servers', 'detail']),
                 json={'servers': [fake_server]}),
        ])

        conn = connection.Connection(config=config)
        s = next(conn.compute.servers())
        self.assertEqual(s.id, server_id)
        self.assertEqual(s.name, server_name)
        self.assert_calls() 
开发者ID:openstack,项目名称:openstacksdk,代码行数:27,代码来源:test_from_session.py

示例7: openstack_connection

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def openstack_connection(self, vim_connection_info, version):
        access_info = vim_connection_info.access_info
        auth = dict(auth_url=access_info['auth_url'],
          username=access_info['username'],
          password=access_info['password'],
          project_name=access_info['project_name'],
          user_domain_name=access_info['user_domain_name'],
          project_domain_name=access_info['project_domain_name'])

        session = self.keystone_plugin.initialize_client(**auth).session

        conn = connection.Connection(
            region_name=access_info.get('region'),
            session=session,
            identity_interface='internal',
            image_api_version=version)

        return conn 
开发者ID:openstack,项目名称:tacker,代码行数:20,代码来源:clients.py

示例8: create_connection

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def create_connection(params=None):
    if params is None:
        params = {}

    if 'token' in params:
        params['auth_type'] = 'token'
    params['app_name'] = USER_AGENT
    params['app_version'] = version.version_info.version_string()
    params.setdefault('region_name', cfg.CONF.default_region_name)
    params.setdefault('identity_api_version', '3')
    params.setdefault('messaging_api_version', '2')

    try:
        conn = connection.Connection(**params)
    except Exception as ex:
        raise parse_exception(ex)

    return conn 
开发者ID:openstack,项目名称:senlin,代码行数:20,代码来源:sdk.py

示例9: create_connection

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def create_connection(prof=None, cloud_region=None, **kwargs):
    version_key = _make_key(API_NAME, 'api_version')
    kwargs[version_key] = CURRENT_API_VERSION

    if not cloud_region:
        if prof:
            cloud_region = _get_config_from_profile(prof, **kwargs)
    else:
        # If we got the CloudRegion from python-openstackclient and it doesn't
        # already have a default microversion set, set it here.
        microversion_key = _make_key(API_NAME, 'default_microversion')
        cloud_region.config.setdefault(microversion_key, CURRENT_API_VERSION)

    user_agent = kwargs.pop('user_agent', None)
    app_name = kwargs.pop('app_name', None)
    app_version = kwargs.pop('app_version', None)
    if user_agent is not None and (not app_name and not app_version):
        app_name, app_version = user_agent.split('/', 1)

    return connection.Connection(
        config=cloud_region,
        app_name=app_name,
        app_version=app_version, **kwargs) 
开发者ID:openstack,项目名称:python-senlinclient,代码行数:25,代码来源:plugin.py

示例10: _get_bitstream_md_from_function_id

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def _get_bitstream_md_from_function_id(self, function_id):
        """Get bitstream metadata given a function id."""
        # TODO(Shaohe) parametrize this role in config file.
        conn = connection.Connection(cloud='devstack-admin')
        properties = {constants.ACCEL_FUNCTION_ID: function_id}
        resp = conn.image.get('/images', params=properties)
        if resp:
            image_list = resp.json()['images']
            if type(image_list) != list:
                raise exception.InvalidType(
                    obj='image', type=type(image_list),
                    expected='list')
            if len(image_list) != 1:
                raise exception.ExpectedOneObject(obj='image',
                                                  count=len(image_list))
            LOG.info('[arqs:objs] For function id (%s), got '
                     'bitstream id (%s)', function_id,
                     image_list[0]['id'])
            return image_list[0]
        else:
            LOG.warning('Failed to get image for function (%s)',
                        function_id)
            return None 
开发者ID:openstack,项目名称:cyborg,代码行数:25,代码来源:fpga_ext_arq.py

示例11: get_sdk_adapter

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def get_sdk_adapter(service_type, check_service=False):
    """Construct an openstacksdk-brokered Adapter for a given service type.
    We expect to find a conf group whose name corresponds to the service_type's
    project according to the service-types-authority.  That conf group must
    provide ksa auth, session, and adapter options.
    :param service_type: String name of the service type for which the Adapter
                         is to be constructed.
    :param check_service: If True, we will query the endpoint to make sure the
            service is alive, raising ServiceUnavailable if it is not.
    :return: An openstack.proxy.Proxy object for the specified service_type.
    :raise: ConfGroupForServiceTypeNotFound If no conf group name could be
            found for the specified service_type.
    :raise: ServiceUnavailable if check_service is True and the service is down
    """
    confgrp = _get_conf_group(service_type)
    sess = _get_auth_and_session(confgrp)
    try:
        conn = connection.Connection(
            session=sess, oslo_conf=CONF, service_types={service_type},
            strict_proxies=check_service)
    except sdk_exc.ServiceDiscoveryException as e:
        raise exception.ServiceUnavailable(
            _("The %(service_type)s service is unavailable: %(error)s") %
            {'service_type': service_type, 'error': six.text_type(e)})
    return getattr(conn, service_type) 
开发者ID:openstack,项目名称:cyborg,代码行数:27,代码来源:utils.py

示例12: get_openstack_client

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def get_openstack_client(vars, region):
    client = connection.Connection(auth_url=str.strip(vars.get('openstack_identity', '')),
                                   username=vars.get('openstack_username', None),
                                   password=vars.get('openstack_password', None),
                                   project_id=vars.get('openstack_projectId', None),
                                   user_domain_name=vars.get('openstack_domain_name', None),
                                   region_name=region)
    return client 
开发者ID:KubeOperator,项目名称:KubeOperator,代码行数:10,代码来源:openstack.py

示例13: _connect_openstack

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def _connect_openstack(self):
        return connection.Connection(
            region_name=self.region_name,
            user_agent='cloudbridge',
            auth_url=self.auth_url,
            project_name=self.project_name,
            username=self.username,
            password=self.password,
            user_domain_name=self.user_domain_name,
            project_domain_id=self.project_domain_id,
            project_domain_name=self.project_domain_name
        ) 
开发者ID:CloudVE,项目名称:cloudbridge,代码行数:14,代码来源:provider.py

示例14: mock_list_items

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def mock_list_items(conn=None, **kwargs):
    with patch('openstack.connection.Connection'):
        service = kwargs['service']
        generator = kwargs['generator']
        f = 'mock_list_%s'%generator

        return globals()[f](conn, **kwargs) 
开发者ID:Netflix-Skunkworks,项目名称:cloudaux,代码行数:9,代码来源:mock_utils.py

示例15: mock_list_networks

# 需要导入模块: from openstack import connection [as 别名]
# 或者: from openstack.connection import Connection [as 别名]
def mock_list_networks(conn=None, **kwargs):
    with patch('openstack.connection.Connection'):
         from openstack.network.v2.network import Network
         from openstack.tests.unit.network.v2.test_network import EXAMPLE

         conn = connection.Connection()
         conn.network.networks.side_effect = [ [Network(**EXAMPLE)] ]
         return [x for x in conn.network.networks()] 
开发者ID:Netflix-Skunkworks,项目名称:cloudaux,代码行数:10,代码来源:mock_utils.py


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