Python keystoneauth1.identity.v3.Password() Examples

The following are 30 code examples of keystoneauth1.identity.v3.Password(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module keystoneauth1.identity.v3 , or try the search function .
Example #1
Source File: impl_designate.py    From designate with Apache License 2.0 8 votes vote down vote up
def _get_client(self):
        if self._client is not None:
            return self._client

        auth = v3_auth.Password(
            auth_url=self.auth_url,
            username=self.username,
            password=self.password,
            project_name=self.project_name,
            project_domain_name=self.project_domain_name,
            user_domain_name=self.user_domain_name,
        )

        session = ks_session.Session(auth=auth)
        self._client = client.Client(
            session=session,
            service_type=self.service_type,
            region_name=self.region_name,
        )
        return self._client 
Example #2
Source File: keystone.py    From quay with Apache License 2.0 7 votes vote down vote up
def _get_client(self, username, password, tenant_name=None):
        if tenant_name:
            auth = keystone_v2_auth.Password(
                auth_url=self.auth_url,
                username=username,
                password=password,
                tenant_name=tenant_name,
            )
        else:
            auth = keystone_v2_auth.Password(
                auth_url=self.auth_url, username=username, password=password
            )

        sess = session.Session(auth=auth)
        client = client_v2.Client(session=sess, timeout=self.timeout, debug=self.debug)
        return client, sess 
Example #3
Source File: keystone.py    From magnum with Apache License 2.0 7 votes vote down vote up
def domain_admin_auth(self):
        user_domain_id = (
            CONF.trust.trustee_domain_admin_domain_id or
            CONF.trust.trustee_domain_id
        )
        user_domain_name = (
            CONF.trust.trustee_domain_admin_domain_name or
            CONF.trust.trustee_domain_name
        )
        if not self._domain_admin_auth:
            self._domain_admin_auth = ka_v3.Password(
                auth_url=self.auth_url,
                user_id=CONF.trust.trustee_domain_admin_id,
                username=CONF.trust.trustee_domain_admin_name,
                user_domain_id=user_domain_id,
                user_domain_name=user_domain_name,
                domain_id=CONF.trust.trustee_domain_id,
                domain_name=CONF.trust.trustee_domain_name,
                password=CONF.trust.trustee_domain_admin_password)
        return self._domain_admin_auth 
Example #4
Source File: keystone.py    From magnum with Apache License 2.0 7 votes vote down vote up
def _get_legacy_auth(self):
        LOG.warning('Auth plugin and its options for service user '
                    'must be provided in [%(new)s] section. '
                    'Using values from [%(old)s] section is '
                    'deprecated.', {'new': ksconf.CFG_GROUP,
                                    'old': ksconf.CFG_LEGACY_GROUP})

        conf = getattr(CONF, ksconf.CFG_LEGACY_GROUP)

        # FIXME(htruta, pauloewerton): Conductor layer does not have
        # new v3 variables, such as project_name and project_domain_id.
        # The use of admin_* variables is related to Identity API v2.0,
        # which is now deprecated. We should also stop using hard-coded
        # domain info, as well as variables that refer to `tenant`,
        # as they are also v2 related.
        auth = ka_v3.Password(auth_url=self.auth_url,
                              username=conf.admin_user,
                              password=conf.admin_password,
                              project_name=conf.admin_tenant_name,
                              project_domain_id='default',
                              user_domain_id='default')
        return auth 
Example #5
Source File: python_client_base.py    From magnum with Apache License 2.0 7 votes vote down vote up
def _get_auth_session(cls, username, password, project_name,
                          project_domain_id, user_domain_id, auth_url,
                          insecure):
        """Return a `keystoneauth1.session.Session` from auth parameters."""
        # create v3Password auth plugin
        _auth = ksa_v3.Password(username=username,
                                password=password,
                                project_name=project_name,
                                project_domain_id=project_domain_id,
                                user_domain_id=user_domain_id,
                                auth_url=auth_url)

        # `insecure` is being replaced by `verify`. Please note they have
        # opposite meanings.
        verify = False if insecure else True

        # create a `keystoneauth1.session.Session`
        _session = ksa_session.Session(auth=_auth, verify=verify)

        return _session 
Example #6
Source File: create-glance-images.py    From openstack-omni with Apache License 2.0 7 votes vote down vote up
def __init__(self):
        os_auth_url = os.getenv('OS_AUTH_URL')
        os_auth_url = os_auth_url.replace('v2.0', 'v3')
        if not os_auth_url.endswith('v3'):
            os_auth_url += '/v3'

        os_username = os.getenv('OS_USERNAME')
        os_password = os.getenv('OS_PASSWORD')
        os_tenant_name = os.getenv('OS_TENANT_NAME')
        os_region_name = os.getenv('OS_REGION_NAME')

        self.glance_endpoint = os_auth_url.replace('keystone/v3', 'glance')
        sys.stdout.write('Using glance endpoint: ' + self.glance_endpoint)

        v3_auth = v3.Password(auth_url = os_auth_url, username = os_username,
                              password = os_password, project_name = os_tenant_name,
                              project_domain_name = 'default', user_domain_name = 'default')
        self.sess = session.Session(auth=v3_auth, verify=False) # verify=True 
Example #7
Source File: nfv_parameters.py    From JetPack with Apache License 2.0 6 votes vote down vote up
def get_inspector_client(self):
        os_auth_url, os_tenant_name, os_username, os_password, \
            os_user_domain_name, os_project_domain_name = \
            CredentialHelper.get_undercloud_creds()
        auth_url = os_auth_url + "v3"

        kwargs = {
                'username': os_username,
                'password': os_password,
                'auth_url': os_auth_url,
                'project_id': os_tenant_name,
                'user_domain_name': os_user_domain_name,
                'project_domain_name': os_project_domain_name
                }
        auth = v3.Password(
            auth_url=auth_url,
            username=os_username,
            password=os_password,
            project_name=os_tenant_name,
            user_domain_name=os_user_domain_name,
            project_domain_name=os_project_domain_name
            )
        sess = session.Session(auth=auth)
        self.inspector = ironic_inspector_client.ClientV1(session=sess) 
Example #8
Source File: keystone.py    From quay with Apache License 2.0 6 votes vote down vote up
def _get_client(self, username, password, project_name=None):
        if project_name:
            auth = keystone_v3_auth.Password(
                auth_url=self.auth_url,
                username=username,
                password=password,
                project_name=project_name,
                project_domain_id=self.project_domain_id,
                user_domain_id=self.user_domain_id,
            )
        else:
            auth = keystone_v3_auth.Password(
                auth_url=self.auth_url,
                username=username,
                password=password,
                user_domain_id=self.user_domain_id,
            )

        sess = session.Session(auth=auth)
        client = client_v3.Client(session=sess, timeout=self.timeout, debug=self.debug)
        return client, sess 
Example #9
Source File: keystone.py    From qinling with Apache License 2.0 6 votes vote down vote up
def get_qinling_endpoint():
    '''Get Qinling service endpoint.'''
    if CONF.qinling_endpoint:
        return CONF.qinling_endpoint

    region = CONF.keystone_authtoken.region_name
    auth = v3.Password(
        auth_url=CONF.keystone_authtoken.www_authenticate_uri,
        username=CONF.keystone_authtoken.username,
        password=CONF.keystone_authtoken.password,
        project_name=CONF.keystone_authtoken.project_name,
        user_domain_name=CONF.keystone_authtoken.user_domain_name,
        project_domain_name=CONF.keystone_authtoken.project_domain_name,
    )
    sess = session.Session(auth=auth, verify=False)
    endpoint = sess.get_endpoint(service_type='function-engine',
                                 interface='public',
                                 region_name=region)

    return endpoint 
Example #10
Source File: test_functional_swift.py    From glance_store with Apache License 2.0 6 votes vote down vote up
def tearDown(self):
        auth = v3.Password(auth_url=self.auth_url,
                           username=self.username,
                           password=self.password,
                           project_name=self.project_name,
                           user_domain_id=self.user_domain_id,
                           project_domain_id=self.project_domain_id)
        sess = session.Session(auth=auth)
        swift = swiftclient.client.Connection(session=sess)

        for x in range(1, 4):
            time.sleep(x)
            try:
                _, objects = swift.get_container(self.container)
                for obj in objects:
                    swift.delete_object(self.container, obj.get('name'))
                swift.delete_container(self.container)
            except Exception:
                if x < 3:
                    pass
                else:
                    raise
            else:
                break
        super(TestSwift, self).tearDown() 
Example #11
Source File: base.py    From tacker with Apache License 2.0 5 votes vote down vote up
def get_auth_session(cls):
        vim_params = cls.get_credentials()
        auth = v3.Password(
            auth_url=vim_params['auth_url'],
            username=vim_params['username'],
            password=vim_params['password'],
            project_name=vim_params['project_name'],
            user_domain_name=vim_params['user_domain_name'],
            project_domain_name=vim_params['project_domain_name'])
        verify = 'True' == vim_params.pop('cert_verify', 'False')
        auth_ses = session.Session(auth=auth, verify=verify)
        return auth_ses 
Example #12
Source File: session.py    From drydock with Apache License 2.0 5 votes vote down vote up
def get_ks_session(**kwargs):
        # Establishes a keystone session
        if 'token' in kwargs:
            auth = v3.TokenMethod(token=kwargs.get('token'))
        else:
            auth = v3.Password(**kwargs)
        return session.Session(auth=auth) 
Example #13
Source File: openstack_driver.py    From tacker with Apache License 2.0 5 votes vote down vote up
def _get_auth_plugin(self, **kwargs):
        auth_plugin = v3.Password(**kwargs)

        return auth_plugin 
Example #14
Source File: openstack_driver.py    From tacker with Apache License 2.0 5 votes vote down vote up
def __init__(self, auth_attr):
        auth_cred = auth_attr.copy()
        verify = 'True' == auth_cred.pop('cert_verify', 'True') or False
        auth = identity.Password(**auth_cred)
        sess = session.Session(auth=auth, verify=verify)
        self.client = neutron_client.Client(session=sess) 
Example #15
Source File: token.py    From tacker with Apache License 2.0 5 votes vote down vote up
def create_token(self):
        auth = v3.Password(auth_url=self.auth_url,
                           username=self.username,
                           password=self.password,
                           project_name=self.project_name,
                           user_domain_name=self.user_domain_name,
                           project_domain_name=self.project_domain_name)
        sess = session.Session(auth=auth)
        token_id = sess.auth.get_token(sess)
        return token_id 
Example #16
Source File: keystone.py    From tacker with Apache License 2.0 5 votes vote down vote up
def initialize_client(self, **kwargs):
        verify = 'True' == kwargs.pop('cert_verify', 'False')
        auth_plugin = v3.Password(**kwargs)
        ses = self.get_session(auth_plugin=auth_plugin, verify=verify)
        cli = client.Client('v3', session=ses)
        return cli 
Example #17
Source File: client.py    From syntribos with Apache License 2.0 5 votes vote down vote up
def create_connection(auth_url=None,
                      project_name=None,
                      project_domain_name="default",
                      user_domain_name="default",
                      project_domain_id="default",
                      user_domain_id="default",
                      username=None,
                      password=None):
    """Method return a glance client."""

    if auth_url.endswith("/v3/"):
        auth_url = auth_url[-1]
    elif auth_url.endswith("/v3"):
        pass
    else:
        auth_url = "{}/v3".format(auth_url)
    auth = v3.Password(auth_url=auth_url,
                       project_name=project_name,
                       project_domain_name=project_domain_name,
                       user_domain_name=user_domain_name,
                       project_domain_id=project_domain_id,
                       user_domain_id=user_domain_id,
                       username=username,
                       password=password)
    return Client("2", auth_url=CONF.user.endpoint,
                  session=session.Session(auth=auth)) 
Example #18
Source File: base.py    From tacker with Apache License 2.0 5 votes vote down vote up
def neutronclient(cls):
        vim_params = cls.get_credentials()
        auth = v3.Password(auth_url=vim_params['auth_url'],
            username=vim_params['username'],
            password=vim_params['password'],
            project_name=vim_params['project_name'],
            user_domain_name=vim_params['user_domain_name'],
            project_domain_name=vim_params['project_domain_name'])
        verify = 'True' == vim_params.pop('cert_verify', 'False')
        auth_ses = session.Session(auth=auth, verify=verify)
        return neutron_client.Client(session=auth_ses) 
Example #19
Source File: base.py    From tacker with Apache License 2.0 5 votes vote down vote up
def glanceclient(cls):
        vim_params = cls.get_credentials()
        auth = v3.Password(auth_url=vim_params['auth_url'],
            username=vim_params['username'],
            password=vim_params['password'],
            project_name=vim_params['project_name'],
            user_domain_name=vim_params['user_domain_name'],
            project_domain_name=vim_params['project_domain_name'])
        verify = 'True' == vim_params.pop('cert_verify', 'False')
        auth_ses = session.Session(auth=auth, verify=verify)
        return glance_client.Client(session=auth_ses) 
Example #20
Source File: collectd_gnocchi_status.py    From browbeat with Apache License 2.0 5 votes vote down vote up
def create_keystone_session():
    if int(os_identity_api_version) == 3:
        from keystoneauth1.identity import v3
        auth = v3.Password(
            username=os_username, password=os_password, project_name=os_tenant,
            user_domain_name=os_user_domain_name, project_domain_name=os_project_domain_name,
            auth_url=os_auth_url)
    else:
        from keystoneauth1.identity import v2
        auth = v2.Password(
            username=os_username, password=os_password, tenant_name=os_tenant,
            auth_url=os_auth_url)
    return session.Session(auth=auth) 
Example #21
Source File: collectd_gnocchi_status.py    From browbeat with Apache License 2.0 5 votes vote down vote up
def create_keystone_session():
    if int(os_identity_api_version) == 3:
        from keystoneauth1.identity import v3
        auth = v3.Password(
            username=os_username, password=os_password, project_name=os_tenant,
            user_domain_name=os_user_domain_name, project_domain_name=os_project_domain_name,
            auth_url=os_auth_url)
    else:
        from keystoneauth1.identity import v2
        auth = v2.Password(
            username=os_username, password=os_password, tenant_name=os_tenant,
            auth_url=os_auth_url)
    return session.Session(auth=auth) 
Example #22
Source File: deploy_heat_stack.py    From cloudbolt-forge with Apache License 2.0 5 votes vote down vote up
def run():
    rh = OpenStackHandler.objects.first()
    auth = v3.Password(
        auth_url=AUTH_URL,
        username=rh.serviceaccount,
        password=rh.servicepasswd,
        project_name='admin',
        user_domain_id='default',
        project_domain_id='default')

    sess = session.Session(auth=auth, verify=False)
    heat = client.Client('1', session=sess)

    timestamp = str(time.time())
    timestamp, _ = timestamp.split('.')

    stack_name = "HEAT-{}-{}".format(project_id, timestamp)


    response = heat.stacks.create(
        stack_name=stack_name,
        template_url='https://s3.amazonaws.com/hot-template/heat-stack-sample.yml',
        param=None)

    logger.debug("Response: {}".format(response))


    resource = job.parent_job.resource_set.first()
    cf, _ = CustomField.objects.get_or_create(name="heat_stack_name", type="STR")
    cfv, _ = CustomFieldValue.objects.get_or_create(field=cf, value=stack_name)
    resource.attributes.add(cfv)
    return ("", "Stack installation initiated, the new stack has name {}".format(stack_name), "") 
Example #23
Source File: base_client.py    From shipyard with Apache License 2.0 5 votes vote down vote up
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)) 
Example #24
Source File: deckhand_client_factory.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def get_client(self, addl_headers=None):
        """Retrieve a deckhand client"""

        """
        Notes:
        TODO(bryan-strassner): If/when the airflow plugin modules move to using
            oslo config, consider using the example here:
            https://github.com/openstack/airship-deckhand/blob/cef3b52a104e620e88a24caf70ed2bb1297c268f/deckhand/barbican/client_wrapper.py#L53
            which will load the attributes from the config more flexibly.
            Keystoneauth1 also provides for a simpler solution with:
            https://docs.openstack.org/keystoneauth/latest/api/keystoneauth1.loading.html
            if oslo config is used.
        """
        keystone_auth = {}
        # Construct Session Argument
        for attr in ('auth_url', 'password', 'project_domain_name',
                     'project_name', 'username', 'user_domain_name'):
            keystone_auth[attr] = self.config.get('keystone_authtoken', attr)

        # Set up keystone session
        auth = keystone_v3.Password(**keystone_auth)
        sess = keystone_session.Session(auth=auth,
                                        additional_headers=addl_headers)

        LOG.info("Setting up Deckhand client with parameters")
        for attr in keystone_auth:
            if attr != 'password':
                LOG.debug('%s = %s', attr, keystone_auth[attr])
        return deckhand_client.Client(session=sess, endpoint_type='internal') 
Example #25
Source File: keystone.py    From ceph-lcm with Apache License 2.0 5 votes vote down vote up
def make_client(parameters):
    auth = identity.Password(**parameters)
    sess = session.Session(auth)

    return client.Client(session=sess) 
Example #26
Source File: keystone.py    From ceph-lcm with Apache License 2.0 5 votes vote down vote up
def make_auth(parameters, reauth=True):
    parameters = parameters.copy()
    parameters.pop("verify", None)
    parameters.pop("cert", None)
    parameters.pop("timeout", None)
    parameters["reauthenticate"] = bool(reauth)

    return identity.Password(**parameters) 
Example #27
Source File: os_glance.py    From see with Apache License 2.0 5 votes vote down vote up
def os_session(self):
        if self._os_session is None:
            from keystoneauth1.identity import v3
            from keystoneauth1.session import Session

            self._os_session = Session(
                auth=v3.Password(**self.configuration['os_auth']),
                verify=self.configuration['session'].get('cacert', False),
                cert=self.configuration['session'].get('cert'))
        return self._os_session 
Example #28
Source File: session.py    From drydock with Apache License 2.0 5 votes vote down vote up
def get_ks_session(**kwargs):
        # Establishes a keystone session
        if 'token' in kwargs:
            auth = v3.TokenMethod(token=kwargs.get('token'))
        else:
            auth = v3.Password(**kwargs)
        return session.Session(auth=auth) 
Example #29
Source File: preload.py    From monasca-docker with Apache License 2.0 5 votes vote down vote up
def _get_auth_plugin(auth_url, **kwargs):
    kwargs = {
        'username': kwargs.get('username'),
        'password': kwargs.get('password'),
        'project_name': kwargs.get('project_name'),
        'project_domain_id': kwargs.get('project_domain_id'),
        'user_domain_id': kwargs.get('user_domain_id'),
    }

    return v3.Password(auth_url=auth_url, **kwargs) 
Example #30
Source File: keystone.py    From a10-neutron-lbaas with Apache License 2.0 5 votes vote down vote up
def _get_keystone_pw(self, ks_version, auth_url, user, password, tenant_name):
        if int(ks_version) == 2:
            auth = v2.Password(
                auth_url=auth_url, username=user, password=password,
                tenant_name=tenant_name)
        elif int(ks_version) == 3:
            auth = v3.Password(
                auth_url=auth_url, username=user, password=password,
                project_name=tenant_name)
        else:
            raise a10_ex.InvalidConfig('keystone version must be protovol version 2 or 3')

        return self._get_keystone_stuff(ks_version, auth)