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


Python v3.Token方法代码示例

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


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

示例1: _get_auth

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_auth(self):
        if self.context.auth_token_info:
            access_info = ka_access.create(body=self.context.auth_token_info,
                                           auth_token=self.context.auth_token)
            auth = ka_access_plugin.AccessInfoPlugin(access_info)
        elif self.context.auth_token:
            auth = ka_v3.Token(auth_url=self.auth_url,
                               token=self.context.auth_token)
        elif self.context.is_admin:
            auth = ka_loading.load_auth_from_conf_options(CONF,
                                                          ksconf.CFG_GROUP)
        else:
            msg = ('Keystone API connection failed: no password, '
                   'trust_id or token found.')
            LOG.error(msg)
            raise exception.AuthorizationFailure(client='keystone',
                                                 message='reason %s' % msg)

        return auth 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:keystone.py

示例2: _create_client

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _create_client(self, context):
        LOG.debug("Gnocchi action security context: %s", context)

        gnocchi_endpoint = keystone_utils.get_endpoint_for_project(
            service_type="metric")
        keystone_endpoint = keystone_utils.get_keystone_endpoint()

        auth = ks_identity_v3.Token(
            auth_url=keystone_endpoint.url,
            tenant_name=context.user_name,
            token=context.auth_token,
            tenant_id=context.project_id
        )

        return self._get_client_class()(
            adapter_options={"region_name": gnocchi_endpoint.region,
                             "project_id": context.project_id,
                             "endpoint": gnocchi_endpoint.url,
                             "insecure": context.insecure},
            session_options={"auth": auth}
        ) 
开发者ID:openstack,项目名称:mistral-extra,代码行数:23,代码来源:actions.py

示例3: get_resp

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def get_resp(self, url, query_params=None):
        """ Thin wrapper of requests get """
        if not query_params:
            query_params = {}
        try:
            headers = {
                'X-Context-Marker': self.context.context_marker,
                'X-Auth-Token': self.get_token()
            }
            query_params['verbosity'] = self.context.verbosity
            self.debug('url: ' + url)
            self.debug('Query Params: ' + str(query_params))
            response = requests.get(url, params=query_params, headers=headers)
            # handle some cases where the response code is sufficient to know
            # what needs to be done
            if response.status_code == 401:
                raise UnauthenticatedClientError()
            if response.status_code == 403:
                raise UnauthorizedClientError()
            return response
        except requests.exceptions.RequestException as e:
            self.error(str(e))
            raise ClientError(str(e)) 
开发者ID:airshipit,项目名称:shipyard,代码行数:25,代码来源:base_client.py

示例4: cloudkittyclient

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def cloudkittyclient(request):
    """Initialization of Cloudkitty client."""
    cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    auth_url = getattr(settings, 'OPENSTACK_KEYSTONE_URL', None)
    auth = Token(
        auth_url,
        token=request.user.token.id,
        project_id=request.user.project_id,
        domain_id=request.user.domain_id,
    )

    adapter_options = {
        'region_name': request.user.services_region,
    }

    return ck_client.Client(
        '1',
        auth=auth,
        cacert=cacert,
        insecure=insecure,
        adapter_options=adapter_options,
    ) 
开发者ID:openstack,项目名称:cloudkitty-dashboard,代码行数:25,代码来源:cloudkitty.py

示例5: _get_keystone_token

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_keystone_token(self, ks_version, auth_url, auth_token, tenant_id):
        if int(ks_version) == 2:
            auth = v2.Token(auth_url=auth_url, token=auth_token, tenant_id=tenant_id)
        elif int(ks_version) == 3:
            auth = v3.Token(auth_url=auth_url, token=auth_token, project_id=tenant_id)
        else:
            raise a10_ex.InvalidConfig('keystone version must be protocol version 2 or 3')

        return self._get_keystone_stuff(ks_version, auth) 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:11,代码来源:keystone.py

示例6: _get_keystone_v3_auth

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_keystone_v3_auth(self, v3_auth_url, **kwargs):
        auth_token = kwargs.pop('auth_token', None)
        if auth_token:
            return v3_auth.Token(v3_auth_url, auth_token)
        else:
            return v3_auth.Password(v3_auth_url, **kwargs) 
开发者ID:nttcom,项目名称:eclcli,代码行数:8,代码来源:shell.py

示例7: _get_keystone_v2_auth

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_keystone_v2_auth(self, v2_auth_url, **kwargs):
        auth_token = kwargs.pop('auth_token', None)
        tenant_id = kwargs.pop('project_id', None)
        tenant_name = kwargs.pop('project_name', None)
        if auth_token:
            return v2_auth.Token(v2_auth_url, auth_token,
                                 tenant_id=tenant_id,
                                 tenant_name=tenant_name)
        else:
            return v2_auth.Password(v2_auth_url,
                                    username=kwargs.pop('username', None),
                                    password=kwargs.pop('password', None),
                                    tenant_id=tenant_id,
                                    tenant_name=tenant_name) 
开发者ID:nttcom,项目名称:eclcli,代码行数:16,代码来源:shell.py

示例8: _get_auth

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_auth(self):
        if self.context.auth_token_info:
            access_info = ka_access.create(body=self.context.auth_token_info,
                                           auth_token=self.context.auth_token)
            auth = ka_access_plugin.AccessInfoPlugin(access_info)
        elif self.context.auth_token:
            auth = ka_v3.Token(auth_url=self.auth_url,
                               token=self.context.auth_token)
        elif self.context.trust_id:
            auth_info = {
                'auth_url': self.auth_url,
                'username': self.context.user_name,
                'password': self.context.password,
                'user_domain_id': self.context.user_domain_id,
                'user_domain_name': self.context.user_domain_name,
                'trust_id': self.context.trust_id
            }

            auth = ka_v3.Password(**auth_info)
        elif self.context.is_admin:
            try:
                auth = ka_loading.load_auth_from_conf_options(
                    CONF, ksconf.CFG_GROUP)
            except ka_exception.MissingRequiredOptions:
                auth = self._get_legacy_auth()
        else:
            msg = ('Keystone API connection failed: no password, '
                   'trust_id or token found.')
            LOG.error(msg)
            raise exception.AuthorizationFailure(client='keystone',
                                                 message='reason %s' % msg)

        return auth 
开发者ID:openstack,项目名称:magnum,代码行数:35,代码来源:keystone.py

示例9: _get_user_keystone_session

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_user_keystone_session():
    ctx = context.get_ctx()

    auth = v3.Token(
        auth_url=CONF.keystone_authtoken.www_authenticate_uri,
        token=ctx.auth_token,
        project_domain_name=ctx.project_domain_name,
        project_name=ctx.project_name
    )

    return session.Session(auth=auth, verify=False) 
开发者ID:openstack,项目名称:qinling,代码行数:13,代码来源:keystone.py

示例10: post_resp

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def post_resp(self,
                  url,
                  query_params=None,
                  data=None,
                  content_type='application/x-yaml'):
        """ Thin wrapper of requests post """
        if not query_params:
            query_params = {}
        if not data:
            data = {}
        try:
            headers = {
                'X-Context-Marker': self.context.context_marker,
                'content-type': content_type,
                'X-Auth-Token': self.get_token()
            }
            query_params['verbosity'] = self.context.verbosity
            self.debug('Post request url: ' + url)
            self.debug('Query Params: ' + str(query_params))
            # This could use keystoneauth1 session, but that library handles
            # responses strangely (wraps all 400/500 in a keystone exception)
            response = requests.post(
                url, data=data, params=query_params, headers=headers)
            # handle some cases where the response code is sufficient to know
            # what needs to be done
            if response.status_code == 401:
                raise UnauthenticatedClientError()
            if response.status_code == 403:
                raise UnauthorizedClientError()
            if response.status_code == 400:
                raise InvalidCollectionError(response.text)
            if response.status_code == 409:
                raise ShipyardBufferError(response.text)
            return response
        except requests.exceptions.RequestException as e:
            self.error(str(e))
            raise ClientError(str(e)) 
开发者ID:airshipit,项目名称:shipyard,代码行数:39,代码来源:base_client.py

示例11: get_token

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def get_token(self):
        """Returns the simple token string for a token

        Attempt to read token from environment variable, if present use it.
        If not, return the token obtained from Keystone.
        """
        token = os.environ.get('OS_AUTH_TOKEN')
        if token:
            return token
        else:
            return self._get_ks_session().get_auth_headers().get('X-Auth-Token') 
开发者ID:airshipit,项目名称:shipyard,代码行数:13,代码来源:base_client.py

示例12: _get_ks_session

# 需要导入模块: from keystoneauth1.identity import v3 [as 别名]
# 或者: from keystoneauth1.identity.v3 import Token [as 别名]
def _get_ks_session(self):
        self.logger.debug('Accessing keystone for keystone session')
        try:
            if self.context.keystone_auth.get("token"):
                auth = v3.Token(**self.context.keystone_auth)
            else:
                auth = v3.Password(**self.context.keystone_auth)
            return session.Session(auth=auth)
        except AuthorizationFailure as e:
            self.logger.error('Could not authorize against keystone: %s',
                              str(e))
            raise ClientError(str(e)) 
开发者ID:airshipit,项目名称:shipyard,代码行数:14,代码来源:base_client.py


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