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