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