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


Python session.Session方法代码示例

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


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

示例1: get_zun_client_from_env

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def get_zun_client_from_env():
    # We should catch KeyError exception with the purpose of
    # source or configure openrc file.
    auth_url = os.environ['OS_AUTH_URL']
    username = os.environ['OS_USERNAME']
    password = os.environ['OS_PASSWORD']
    project_name = os.environ['OS_PROJECT_NAME']

    # Either project(user)_domain_name or project(user)_domain_id
    # would be acceptable.
    project_domain_name = os.environ.get("OS_PROJECT_DOMAIN_NAME")
    project_domain_id = os.environ.get("OS_PROJECT_DOMAIN_ID")
    user_domain_name = os.environ.get("OS_USER_DOMAIN_NAME")
    user_domain_id = os.environ.get("OS_USER_DOMAIN_ID")

    auth = identity.Password(auth_url=auth_url,
                             username=username,
                             password=password,
                             project_name=project_name,
                             project_domain_id=project_domain_id,
                             project_domain_name=project_domain_name,
                             user_domain_id=user_domain_id,
                             user_domain_name=user_domain_name)
    session = ks.Session(auth=auth)
    return client.Client(ZUN_API_VERSION, session=session) 
开发者ID:openstack,项目名称:zun,代码行数:27,代码来源:utils.py

示例2: get_inspector_client

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def get_inspector_client(self):
        os_auth_url, os_tenant_name, os_username, os_password, \
            os_user_domain_name, os_project_domain_name = \
            CredentialHelper.get_undercloud_creds()
        auth_url = os_auth_url + "v3"

        kwargs = {
                'username': os_username,
                'password': os_password,
                'auth_url': os_auth_url,
                'project_id': os_tenant_name,
                'user_domain_name': os_user_domain_name,
                'project_domain_name': os_project_domain_name
                }
        auth = v3.Password(
            auth_url=auth_url,
            username=os_username,
            password=os_password,
            project_name=os_tenant_name,
            user_domain_name=os_user_domain_name,
            project_domain_name=os_project_domain_name
            )
        sess = session.Session(auth=auth)
        self.inspector = ironic_inspector_client.ClientV1(session=sess) 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:26,代码来源:nfv_parameters.py

示例3: get_context

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def get_context(self):
        username = CONF.identity.username
        password = CONF.identity.password
        project_name = CONF.identity.project_name
        auth_url = CONF.identity.auth_url
        user_domain_name = CONF.identity.user_domain_name
        project_domain_name = CONF.identity.project_domain_name

        auth = identity.V3Password(auth_url=auth_url,
                                   username=username,
                                   password=password,
                                   project_name=project_name,
                                   user_domain_name=user_domain_name,
                                   project_domain_name=project_domain_name)
        sess = session.Session(auth=auth)

        return context.RequestContext(auth_token=auth.get_token(sess),
                                      tenant=auth.get_project_id(sess)) 
开发者ID:openstack,项目名称:castellan,代码行数:20,代码来源:test_barbican_key_manager.py

示例4: get_barbican_client_user_auth

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def get_barbican_client_user_auth(cls, context):
        # get a normal session
        ksession = keystone.KeystoneSession()
        service_auth = ksession.get_auth()

        # make our own auth and swap it in
        user_auth = token.Token(auth_url=service_auth.auth_url,
                                token=context.auth_token,
                                project_id=context.project_id)
        user_session = session.Session(
            auth=user_auth,
            verify=CONF.certificates.ca_certificates_file)

        # create a special barbican client with our user's session
        return barbican_client.Client(
            session=user_session,
            region_name=CONF.certificates.region_name,
            interface=CONF.certificates.endpoint_type) 
开发者ID:openstack,项目名称:octavia,代码行数:20,代码来源:barbican_acl.py

示例5: _get_client

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _get_client(self):
        if self._client is not None:
            return self._client

        auth = v3_auth.Password(
            auth_url=self.auth_url,
            username=self.username,
            password=self.password,
            project_name=self.project_name,
            project_domain_name=self.project_domain_name,
            user_domain_name=self.user_domain_name,
        )

        session = ks_session.Session(auth=auth)
        self._client = client.Client(
            session=session,
            service_type=self.service_type,
            region_name=self.region_name,
        )
        return self._client 
开发者ID:openstack,项目名称:designate,代码行数:22,代码来源:impl_designate.py

示例6: _get_pdk_container

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _get_pdk_container(self, context, instance, pdk_reference):
        """Retrieves the barbican container containing the pdk file.
        """

        auth = context.get_auth_plugin()
        sess = session.Session(auth=auth)
        brb_client = barbican_client.Client(session=sess)

        try:
            pdk_container = brb_client.containers.get(pdk_reference)
        except Exception as e:
            err_msg = _("Retrieving barbican container with reference "
                        "%(pdk_reference)s failed with error: %(error)s") % {
                        'pdk_reference': pdk_reference,
                        'error': e}
            raise exception.InvalidMetadata(instance_id=instance.uuid,
                                            reason=err_msg)
        return pdk_container 
开发者ID:openstack,项目名称:compute-hyperv,代码行数:20,代码来源:pdk.py

示例7: _connect_keystone

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _connect_keystone(self):
        """Get an OpenStack Keystone (identity) client object."""
        if self._keystone_version == 3:
            return keystone_client.Client(session=self._keystone_session,
                                          auth_url=self.auth_url)
        else:
            # Wow, the internal keystoneV2 implementation is terribly buggy. It
            # needs both a separate Session object and the username, password
            # again for things to work correctly. Plus, a manual call to
            # authenticate() is also required if the service catalog needs
            # to be queried.
            keystone = keystone_client.Client(
                session=self._keystone_session,
                auth_url=self.auth_url,
                username=self.username,
                password=self.password,
                project_name=self.project_name,
                region_name=self.region_name)
            keystone.authenticate()
            return keystone 
开发者ID:CloudVE,项目名称:cloudbridge,代码行数:22,代码来源:provider.py

示例8: __init__

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def __init__(
        self,
        session=None,
        endpoint=None,
        **kwargs
    ):
        """Base object that contains some common API objects and methods

        :param Session session:
            The default session to be used for making the HTTP API calls.
        :param string endpoint:
            The URL from the Service Catalog to be used as the base for API
            requests on this API.
        """

        super(KeystoneSession, self).__init__()

        # a requests.Session-style interface
        self.session = session
        self.endpoint = endpoint 
开发者ID:nttcom,项目名称:eclcli,代码行数:22,代码来源:api.py

示例9: create

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def create(
        self,
        url,
        session=None,
        method=None,
        **params
    ):
        """Create a new resource

        :param string url:
            The API-specific portion of the URL path
        :param Session session:
            HTTP client session
        :param string method:
            HTTP method (default POST)
        """

        if not method:
            method = 'POST'
        ret = self._request(method, url, session=session, **params)
        # Should this move into _requests()?
        try:
            return ret.json()
        except json.JSONDecodeError:
            return ret 
开发者ID:nttcom,项目名称:eclcli,代码行数:27,代码来源:api.py

示例10: _get_keystone_session

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _get_keystone_session(self, **kwargs):
        # first create a Keystone session
        cacert = kwargs.pop('cacert', None)
        cert = kwargs.pop('cert', None)
        key = kwargs.pop('key', None)
        insecure = kwargs.pop('insecure', False)
        timeout = kwargs.pop('timeout', None)
        verify = kwargs.pop('verify', None)

        # FIXME(gyee): this code should come from keystoneclient
        if verify is None:
            if insecure:
                verify = False
            else:
                # TODO(gyee): should we do
                # heatclient.common.http.get_system_ca_fle()?
                verify = cacert or True
        if cert and key:
            # passing cert and key together is deprecated in favour of the
            # requests lib form of having the cert and key as a tuple
            cert = (cert, key)

        return kssession.Session(verify=verify, cert=cert, timeout=timeout) 
开发者ID:nttcom,项目名称:eclcli,代码行数:25,代码来源:shell.py

示例11: tearDown

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def tearDown(self):
        auth = v3.Password(auth_url=self.auth_url,
                           username=self.username,
                           password=self.password,
                           project_name=self.project_name,
                           user_domain_id=self.user_domain_id,
                           project_domain_id=self.project_domain_id)
        sess = session.Session(auth=auth)
        swift = swiftclient.client.Connection(session=sess)

        for x in range(1, 4):
            time.sleep(x)
            try:
                _, objects = swift.get_container(self.container)
                for obj in objects:
                    swift.delete_object(self.container, obj.get('name'))
                swift.delete_container(self.container)
            except Exception:
                if x < 3:
                    pass
                else:
                    raise
            else:
                break
        super(TestSwift, self).tearDown() 
开发者ID:openstack,项目名称:glance_store,代码行数:27,代码来源:test_functional_swift.py

示例12: _session

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _session(kwargs):
    """Returns or reuses session.

    Method takes care of providing instance of
    session object for the client.

    :param kwargs: all params (without api_version) client was initialized with
    :type kwargs: dict

    :returns: session object
    :rtype keystoneauth1.session.Session

    """
    if 'session' in kwargs:
        LOG.debug('Reusing session')
        sess = kwargs.get('session')
        if not isinstance(sess, k_session.Session):
            msg = ('session should be an instance of %s' % k_session.Session)
            LOG.error(msg)
            raise RuntimeError(msg)
    else:
        LOG.debug('Initializing new session')
        auth = _get_auth_handler(kwargs)
        sess = _get_session(auth, kwargs)
    return sess 
开发者ID:openstack,项目名称:python-monascaclient,代码行数:27,代码来源:client.py

示例13: test_should_reuse_the_session_if_initialized_with_one

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def test_should_reuse_the_session_if_initialized_with_one(self,
                                                              get_session,
                                                              get_auth,
                                                              _):
        from keystoneauth1 import session as k_session

        api_version = mock.Mock()
        session = mock.Mock(spec=k_session.Session)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            client.Client(api_version, session=session)
            self.assertEqual(0, len(w))

        get_auth.assert_not_called()
        get_session.assert_not_called() 
开发者ID:openstack,项目名称:python-monascaclient,代码行数:18,代码来源:test_client.py

示例14: __init__

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def __init__(self):
        os_auth_url = os.getenv('OS_AUTH_URL')
        os_auth_url = os_auth_url.replace('v2.0', 'v3')
        if not os_auth_url.endswith('v3'):
            os_auth_url += '/v3'

        os_username = os.getenv('OS_USERNAME')
        os_password = os.getenv('OS_PASSWORD')
        os_tenant_name = os.getenv('OS_TENANT_NAME')
        os_region_name = os.getenv('OS_REGION_NAME')

        self.glance_endpoint = os_auth_url.replace('keystone/v3', 'glance')
        sys.stdout.write('Using glance endpoint: ' + self.glance_endpoint)

        v3_auth = v3.Password(auth_url = os_auth_url, username = os_username,
                              password = os_password, project_name = os_tenant_name,
                              project_domain_name = 'default', user_domain_name = 'default')
        self.sess = session.Session(auth=v3_auth, verify=False) # verify=True 
开发者ID:platform9,项目名称:openstack-omni,代码行数:20,代码来源:create-glance-images.py

示例15: _get_auth_session

# 需要导入模块: from keystoneauth1 import session [as 别名]
# 或者: from keystoneauth1.session import Session [as 别名]
def _get_auth_session(cls, username, password, project_name,
                          project_domain_id, user_domain_id, auth_url,
                          insecure):
        """Return a `keystoneauth1.session.Session` from auth parameters."""
        # create v3Password auth plugin
        _auth = ksa_v3.Password(username=username,
                                password=password,
                                project_name=project_name,
                                project_domain_id=project_domain_id,
                                user_domain_id=user_domain_id,
                                auth_url=auth_url)

        # `insecure` is being replaced by `verify`. Please note they have
        # opposite meanings.
        verify = False if insecure else True

        # create a `keystoneauth1.session.Session`
        _session = ksa_session.Session(auth=_auth, verify=verify)

        return _session 
开发者ID:openstack,项目名称:magnum,代码行数:22,代码来源:python_client_base.py


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