python类Session()的实例源码

utils.py 文件源码 项目:charm-swift-proxy 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
client.py 文件源码 项目:python-freezerclient 作者: openstack 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def session(self):
        if self._session:
            return self._session
        auth_plugin = get_auth_plugin(self.opts)
        return ksa_session.Session(auth=auth_plugin,
                                   verify=(self.cacert or
                                           not self.opts.insecure),
                                   cert=self.cert)
client.py 文件源码 项目:python-freezerclient 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def session(self):
        if self._session:
            return self._session
        auth_plugin = get_auth_plugin(self.opts)
        return ksa_session.Session(auth=auth_plugin,
                                   verify=(self.cacert or
                                           not self.opts.insecure),
                                   cert=self.cert)
utils.py 文件源码 项目:charm-heat 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
utils.py 文件源码 项目:charm-heat 作者: openstack 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
openstack_utils.py 文件源码 项目:functest 作者: opnfv 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def get_session(other_creds={}):
    auth = get_session_auth(other_creds)
    https_cacert = os.getenv('OS_CACERT', '')
    https_insecure = os.getenv('OS_INSECURE', '').lower() == 'true'
    return session.Session(auth=auth,
                           verify=(https_cacert or not https_insecure))


# *********************************************
#   CLIENTS
# *********************************************
utils.py 文件源码 项目:charm-keystone 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
utils.py 文件源码 项目:charm-keystone 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
utils.py 文件源码 项目:charm-keystone 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
utils.py 文件源码 项目:charm-keystone 作者: openstack 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
utils.py 文件源码 项目:charm-keystone 作者: openstack 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def authenticate_keystone(self, keystone_ip, username, password,
                              api_version=False, admin_port=False,
                              user_domain_name=None, domain_name=None,
                              project_domain_name=None, project_name=None):
        """Authenticate with Keystone"""
        self.log.debug('Authenticating with keystone...')
        port = 5000
        if admin_port:
            port = 35357
        base_ep = "http://{}:{}".format(keystone_ip.strip().decode('utf-8'),
                                        port)
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            auth = v2.Password(
                username=username,
                password=password,
                tenant_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
        else:
            ep = base_ep + "/v3"
            auth = v3.Password(
                user_domain_name=user_domain_name,
                username=username,
                password=password,
                domain_name=domain_name,
                project_domain_name=project_domain_name,
                project_name=project_name,
                auth_url=ep
            )
            sess = keystone_session.Session(auth=auth)
            client = keystone_client_v3.Client(session=sess)
            # This populates the client.service_catalog
            client.auth_ref = auth.get_access(sess)
            return client
keystone.py 文件源码 项目:vdi-broker 作者: cloudbase 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def create_trust(ctxt):
    LOG.debug("Creating Keystone trust")

    trusts_auth_plugin = _get_trusts_auth_plugin()

    loader = loading.get_plugin_loader("v3token")
    auth = loader.load_from_options(
        auth_url=trusts_auth_plugin.auth_url,
        token=ctxt.auth_token,
        project_name=ctxt.project_name,
        project_domain_name=ctxt.project_domain)
    session = ks_session.Session(
        auth=auth, verify=not CONF.keystone.allow_untrusted)

    try:
        trustee_user_id = trusts_auth_plugin.get_user_id(session)
    except ks_exceptions.Unauthorized as ex:
        LOG.exception(ex)
        raise exception.NotAuthorized("Trustee authentication failed")

    trustor_user_id = ctxt.user
    trustor_proj_id = ctxt.tenant
    roles = ctxt.roles

    LOG.debug("Granting Keystone trust. Trustor: %(trustor_user_id)s, trustee:"
              " %(trustee_user_id)s, project: %(trustor_proj_id)s, roles:"
              " %(roles)s",
              {"trustor_user_id": trustor_user_id,
               "trustee_user_id": trustee_user_id,
               "trustor_proj_id": trustor_proj_id,
               "roles": roles})

    # Trusts are not supported before Keystone v3
    client = kc_v3.Client(session=session)
    trust = client.trusts.create(trustor_user=trustor_user_id,
                                 trustee_user=trustee_user_id,
                                 project=trustor_proj_id,
                                 impersonation=True,
                                 role_names=roles)
    LOG.debug("Trust id: %s" % trust.id)
    return trust.id
keystone.py 文件源码 项目:vdi-broker 作者: cloudbase 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def delete_trust(trust_id):
    LOG.debug("Deleting trust id: %s", trust_id)

    auth = _get_trusts_auth_plugin(trust_id)
    session = ks_session.Session(
        auth=auth, verify=not CONF.keystone.allow_untrusted)
    client = kc_v3.Client(session=session)
    try:
        client.trusts.delete(trust_id)
    except ks_exceptions.NotFound:
        LOG.debug("Trust id not found: %s", trust_id)
keystone.py 文件源码 项目:vdi-broker 作者: cloudbase 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def create_keystone_session(trust_id):
    verify = not CONF.keystone.allow_untrusted
    auth = _get_trusts_auth_plugin(trust_id)
    return ks_session.Session(auth=auth, verify=verify)


问题


面经


文章

微信
公众号

扫码关注公众号