當前位置: 首頁>>代碼示例>>Python>>正文


Python session.Session方法代碼示例

本文整理匯總了Python中keystoneclient.session.Session方法的典型用法代碼示例。如果您正苦於以下問題:Python session.Session方法的具體用法?Python session.Session怎麽用?Python session.Session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keystoneclient.session的用法示例。


在下文中一共展示了session.Session方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: authenticate_keystone_admin

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def authenticate_keystone_admin(self, keystone_sentry, user, password,
                                    tenant=None, api_version=None,
                                    keystone_ip=None):
        """Authenticates admin user with the keystone admin endpoint."""
        self.log.debug('Authenticating keystone admin...')
        unit = keystone_sentry
        if not keystone_ip:
            keystone_ip = unit.relation('shared-db',
                                        'mysql:shared-db')['private-address']
        base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            return keystone_client.Client(username=user, password=password,
                                          tenant_name=tenant, auth_url=ep)
        else:
            ep = base_ep + "/v3"
            auth = keystone_id_v3.Password(
                user_domain_name='admin_domain',
                username=user,
                password=password,
                domain_name='admin_domain',
                auth_url=ep,
            )
            sess = keystone_session.Session(auth=auth)
            return keystone_client_v3.Client(session=sess) 
開發者ID:openstack,項目名稱:charm-plumgrid-gateway,代碼行數:27,代碼來源:utils.py

示例2: _get_endpoint_from_keystone

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def _get_endpoint_from_keystone(self, cxt):
        auth = token_endpoint.Token(cfg.CONF.client.identity_url,
                                    cxt.auth_token)
        sess = session.Session(auth=auth)
        cli = keystone_client.Client(session=sess)

        service_id_name_map = {}
        for service in cli.services.list():
            service_dict = service.to_dict()
            service_id_name_map[service_dict['id']] = service_dict['name']

        region_service_endpoint_map = {}
        for endpoint in cli.endpoints.list():
            endpoint_dict = endpoint.to_dict()
            if endpoint_dict['interface'] != 'public':
                continue
            region_id = endpoint_dict['region']
            service_id = endpoint_dict['service_id']
            url = endpoint_dict['url']
            service_name = service_id_name_map[service_id]
            if region_id not in region_service_endpoint_map:
                region_service_endpoint_map[region_id] = {}
            region_service_endpoint_map[region_id][service_name] = url
        return region_service_endpoint_map 
開發者ID:openstack,項目名稱:trio2o,代碼行數:26,代碼來源:client.py

示例3: users_on_tenant

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def users_on_tenant(self, tenant):
        """List user per project."""
        auth_session = session.Session(auth=self.auth_session.auth,
                                       verify=self.verify)
        keystone = keystoneclient.Client(session=auth_session,
                                         endpoint_type=self.endpoint_type,
                                         interface='internal',
                                         insecure=self.insecure)
        users = []
        try:
            users = keystone.users.list(default_project=tenant)
        except Exception as e:
            print(e)
        users_list = []
        for user in users:
            users_list.append(user.to_dict())

        return users_list 
開發者ID:openstack,項目名稱:freezer-dr,代碼行數:20,代碼來源:osclient.py

示例4: _get_keystone_session

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.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

示例5: _get_keystone_client

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def _get_keystone_client(self):
        """returns a keystone client instance"""

        if self._keystone_client is None:
            '''
            self._keystone_client = keystoneclient.v2_0.client.Client(
            auth_url=os.environ.get('OS_AUTH_URL'),
            username=os.environ.get('OS_USERNAME'),
            password=os.environ.get('OS_PASSWORD'),
            tenant_name=os.environ.get('OS_TENANT_NAME'))
            '''
            auth = v2.Password(auth_url=os.environ.get('OS_AUTH_URL'),
                               username=os.environ.get('OS_USERNAME'),
                               password=os.environ.get('OS_PASSWORD'),
                               tenant_name=os.environ.get('OS_TENANT_NAME'))

            sess = session.Session(auth=auth)
        else:
            return self._keystone_client

        return sess 
開發者ID:opnfv,項目名稱:qtip,代碼行數:23,代碼來源:create_zones.py

示例6: get_keystone_client

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def get_keystone_client(self):

        username = cfg.CONF.keystone_authtoken.username
        password = cfg.CONF.keystone_authtoken.password
        project_name = cfg.CONF.keystone_authtoken.project_name
        auth_url = cfg.CONF.keystone_authtoken.auth_url
        if not auth_url.endswith('/v3'):
            auth_url += '/v3'
        user_domain_name = cfg.CONF.keystone_authtoken.user_domain_name
        project_domain_name = cfg.CONF.keystone_authtoken.project_domain_name
        auth = v3.Password(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)
        keystone_client = k_client.Client(session=sess)

        return keystone_client 
開發者ID:openstack,項目名稱:networking-h3c,代碼行數:22,代碼來源:mechanism_h3c.py

示例7: authenticate_keystone_admin

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def authenticate_keystone_admin(self, keystone_sentry, user, password,
                                    tenant=None, api_version=None,
                                    keystone_ip=None):
        """Authenticates admin user with the keystone admin endpoint."""
        self.log.debug('Authenticating keystone admin...')
        if not keystone_ip:
            keystone_ip = keystone_sentry.info['public-address']

        base_ep = "http://{}:35357".format(keystone_ip.strip().decode('utf-8'))
        if not api_version or api_version == 2:
            ep = base_ep + "/v2.0"
            return keystone_client.Client(username=user, password=password,
                                          tenant_name=tenant, auth_url=ep)
        else:
            ep = base_ep + "/v3"
            auth = keystone_id_v3.Password(
                user_domain_name='admin_domain',
                username=user,
                password=password,
                domain_name='admin_domain',
                auth_url=ep,
            )
            sess = keystone_session.Session(auth=auth)
            return keystone_client_v3.Client(session=sess) 
開發者ID:openstack,項目名稱:charm-neutron-api-plumgrid,代碼行數:26,代碼來源:utils.py

示例8: get_servers

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def get_servers(host):
  creds = get_keystone_creds()
  auth = identity.v3.Password(**creds)
  sess = session.Session(auth=auth)
  nova = client.Client('2',session=sess)
  servers = {}
  for server in nova.servers.list():
    try:
      if server.to_dict()['OS-EXT-SRV-ATTR:host'] == host:
        # NOTE: network name should not be statically assigned
        servers[server.to_dict()['addresses']['external-flat'][0]['addr']] = server.name
    except Exception as e:
      print 'problem with getting info for server: ' + str(server.to_dict()['id'])
      print str(e)
      pass
  return servers 
開發者ID:osic,項目名稱:benchmarking_live-migration,代碼行數:18,代碼來源:test_ping_vms.py

示例9: __init__

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def __init__(self, endpoint, **kwargs):
        try:
            from keystoneclient.v2_0 import client
            from keystoneclient.auth.identity import v2
            from keystoneclient import session
        except ImportError:
            if six.PY2:
                apt_install(["python-keystoneclient"], fatal=True)
            else:
                apt_install(["python3-keystoneclient"], fatal=True)

            from keystoneclient.v2_0 import client
            from keystoneclient.auth.identity import v2
            from keystoneclient import session

        self.api_version = 2

        token = kwargs.get("token", None)
        if token:
            api = client.Client(endpoint=endpoint, token=token)
        else:
            auth = v2.Password(username=kwargs.get("username"),
                               password=kwargs.get("password"),
                               tenant_name=kwargs.get("tenant_name"),
                               auth_url=endpoint)
            sess = session.Session(auth=auth)
            api = client.Client(session=sess)

        self.api = api 
開發者ID:openstack,項目名稱:charm-swift-proxy,代碼行數:31,代碼來源:keystone.py

示例10: __init__

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def __init__(self, endpoint, token):
        self.api_version = 3
        keystone_auth_v3 = token_endpoint.Token(endpoint=endpoint, token=token)
        keystone_session_v3 = session.Session(auth=keystone_auth_v3)
        self.api = keystoneclient_v3.Client(session=keystone_session_v3) 
開發者ID:openstack,項目名稱:charm-keystone,代碼行數:7,代碼來源:manager.py

示例11: __init__

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def __init__(self, endpoint, **kwargs):
        try:
            from keystoneclient.v3 import client
            from keystoneclient.auth import token_endpoint
            from keystoneclient import session
            from keystoneclient.auth.identity import v3
        except ImportError:
            if six.PY2:
                apt_install(["python-keystoneclient"], fatal=True)
            else:
                apt_install(["python3-keystoneclient"], fatal=True)

            from keystoneclient.v3 import client
            from keystoneclient.auth import token_endpoint
            from keystoneclient import session
            from keystoneclient.auth.identity import v3

        self.api_version = 3

        token = kwargs.get("token", None)
        if token:
            auth = token_endpoint.Token(endpoint=endpoint,
                                        token=token)
            sess = session.Session(auth=auth)
        else:
            auth = v3.Password(auth_url=endpoint,
                               user_id=kwargs.get("username"),
                               password=kwargs.get("password"),
                               project_id=kwargs.get("tenant_name"))
            sess = session.Session(auth=auth)

        self.api = client.Client(session=sess) 
開發者ID:openstack,項目名稱:charm-keystone,代碼行數:34,代碼來源:keystone.py

示例12: _get_keystone_session

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def _get_keystone_session(self):
        auth = auth_identity.Password(
            auth_url=cfg.CONF.client.identity_url,
            username=cfg.CONF.client.admin_username,
            password=cfg.CONF.client.admin_password,
            project_name=cfg.CONF.client.admin_tenant,
            user_domain_name=cfg.CONF.client.admin_user_domain_name,
            project_domain_name=cfg.CONF.client.admin_tenant_domain_name)
        return session.Session(auth=auth) 
開發者ID:openstack,項目名稱:trio2o,代碼行數:11,代碼來源:client.py

示例13: _create_session_client

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def _create_session_client(self):
        auth = token_endpoint.Token(self.endpoint, self.token)
        sess = session.Session(auth=auth)
        return http.SessionClient(sess) 
開發者ID:openstack,項目名稱:python-bileanclient,代碼行數:6,代碼來源:test_http.py

示例14: _initialize_tests

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def _initialize_tests(self):
        """Perform final initialization before tests get run."""
        # Access the sentries for inspecting service units
        self.murano_sentry = self.d.sentry['murano'][0]
        self.pxc_sentry = self.d.sentry['percona-cluster'][0]
        self.keystone_sentry = self.d.sentry['keystone'][0]
        self.rabbitmq_sentry = self.d.sentry['rabbitmq-server'][0]
        u.log.debug('openstack release val: {}'.format(
            self._get_openstack_release()))
        u.log.debug('openstack release str: {}'.format(
            self._get_openstack_release_string()))

        # Authenticate admin with keystone endpoint
        self.keystone = u.authenticate_keystone_admin(self.keystone_sentry,
                                                      user='admin',
                                                      password='openstack',
                                                      tenant='admin')

        # Authenticate admin with murano endpoint
        murano_ep = self.keystone.service_catalog.url_for(
            service_type='application-catalog',
            endpoint_type='publicURL')

        keystone_ep = self.keystone.service_catalog.url_for(
            service_type='identity',
            endpoint_type='publicURL')

        auth = keystone_identity.V2Token(auth_url=keystone_ep,
                                         token=self.keystone.auth_token)
        sess = keystone_session.Session(auth=auth)
        self.murano = murano_client.Client(version=1, session=sess,
                                           endpoint_override=murano_ep) 
開發者ID:openstack,項目名稱:charm-murano,代碼行數:34,代碼來源:basic_deployment.py

示例15: auth

# 需要導入模塊: from keystoneclient import session [as 別名]
# 或者: from keystoneclient.session import Session [as 別名]
def auth(self):
        """Create a session."""
        auth = v3.Password(auth_url=self.authurl, reauthenticate=True,
                           **self.kwargs)
        self.auth_session = session.Session(auth=auth, verify=self.verify) 
開發者ID:openstack,項目名稱:freezer-dr,代碼行數:7,代碼來源:osclient.py


注:本文中的keystoneclient.session.Session方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。