当前位置: 首页>>代码示例>>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;未经允许,请勿转载。