def test_correct_arguments_passed_to_client_constructor_noauth_mode(
         self, mock_ks_session, mock_client):
     kwargs = {
         'ironic_url': 'http://ironic.example.org:6385/',
         'os_auth_token': 'USER_AUTH_TOKEN',
         'os_ironic_api_version': 'latest',
         'insecure': True,
         'max_retries': 10,
         'retry_interval': 10,
         'os_cacert': 'data'
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', 'http://ironic.example.org:6385/',
         **{
             'os_ironic_api_version': 'latest',
             'max_retries': 10,
             'retry_interval': 10,
             'token': 'USER_AUTH_TOKEN',
             'insecure': True,
             'ca_file': 'data',
             'cert_file': None,
             'key_file': None,
             'timeout': None,
             'session': None
         }
     )
     self.assertFalse(mock_ks_session.called)
 def test_get_client_only_session_passed(self):
     session = mock.Mock()
     session.get_endpoint.return_value = 'http://localhost:35357/v2.0'
     kwargs = {
         'session': session,
     }
     iroclient.get_client('1', **kwargs)
     session.get_endpoint.assert_called_once_with(service_type='baremetal',
                                                  interface=None,
                                                  region_name=None)
 def test_correct_arguments_passed_to_client_constructor_session_passed(
         self, mock_ks_session, mock_client):
     session = mock.Mock()
     kwargs = {
         'session': session,
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', **{'os_ironic_api_version': None,
                 'max_retries': None,
                 'retry_interval': None,
                 'session': session,
                 'endpoint_override': session.get_endpoint.return_value,
                 'interface': None}
     )
     self.assertFalse(mock_ks_session.called)
Exemple #4
0
    def __init__(self, name='', keys='', inbox=None, datapath=None, args=None):
        super(IronicDriver, self).__init__(name, keys, inbox, datapath, args)
        datasource_driver.ExecutionDriver.__init__(self)
        self.creds = self.get_ironic_credentials(args)
        self.ironic_client = client.get_client(**self.creds)

        self.initialized = True
def get_ironic_client():
    LOG.debug('Creating ironic client.')
    kwargs = {'os_username': os.environ['OS_USERNAME'],
              'os_password': os.environ['OS_PASSWORD'],
              'os_auth_url': os.environ['OS_AUTH_URL'],
              'os_tenant_name': os.environ['OS_TENANT_NAME']}
    return ironicclient.get_client(1, **kwargs)
Exemple #6
0
def get_client(token=None,
               api_version=DEFAULT_IRONIC_API_VERSION):  # pragma: no cover
    """Get Ironic client instance."""
    # NOTE: To support standalone ironic without keystone
    if CONF.ironic.auth_strategy == 'noauth':
        args = {'os_auth_token': 'noauth',
                'ironic_url': CONF.ironic.ironic_url}
    elif token is None:
        args = {'os_password': CONF.ironic.os_password,
                'os_username': CONF.ironic.os_username,
                'os_auth_url': CONF.ironic.os_auth_url,
                'os_tenant_name': CONF.ironic.os_tenant_name,
                'os_service_type': CONF.ironic.os_service_type,
                'os_endpoint_type': CONF.ironic.os_endpoint_type}
    else:
        keystone_creds = {'password': CONF.ironic.os_password,
                          'username': CONF.ironic.os_username,
                          'auth_url': CONF.ironic.os_auth_url,
                          'tenant_name': CONF.ironic.os_tenant_name}
        keystone = keystone_client.Client(**keystone_creds)
        ironic_url = keystone.service_catalog.url_for(
            service_type=CONF.ironic.os_service_type,
            endpoint_type=CONF.ironic.os_endpoint_type)
        args = {'os_auth_token': token,
                'ironic_url': ironic_url}
    args['os_ironic_api_version'] = api_version
    args['max_retries'] = CONF.ironic.max_retries
    args['retry_interval'] = CONF.ironic.retry_interval
    return client.get_client(1, **args)
    def _test_get_client(self, mock_ks_loader, mock_ks_session,
                         mock_retrieve_data, version=None,
                         auth='password', **kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:6385/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'
        mock_retrieve_data.return_value = version

        client = iroclient.get_client('1', **kwargs)

        mock_ks_loader.assert_called_once_with(auth)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=kwargs.get('timeout'),
            insecure=kwargs.get('insecure'), cert=kwargs.get('cert'),
            cacert=kwargs.get('cacert'), key=kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=kwargs.get('os_service_type') or 'baremetal',
            interface=kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=kwargs.get('os_region_name'))
        if 'os_ironic_api_version' in kwargs:
            self.assertEqual(0, mock_retrieve_data.call_count)
        else:
            mock_retrieve_data.assert_called_once_with(
                host='localhost',
                port='6385')
            self.assertEqual(version or v1.DEFAULT_VER,
                             client.http_client.os_ironic_api_version)
def get_ironic_client(username, password, auth_url, tenant_name):
    kwargs = {'os_username': username,
              'os_password': password,
              'os_auth_url': auth_url,
              'os_tenant_name': tenant_name }

    return client.get_client(1, **kwargs)
Exemple #9
0
def get_ironic_client(username, password, tenant_name, auth_url):
    LOG.debug('Creating ironic client.')
    kwargs = {'os_username': username,
              'os_password': password,
              'os_auth_url': auth_url,
              'os_tenant_name': tenant_name}
    return ironicclient.get_client(1, **kwargs)
    def run(self, terms, variables=None, **kwargs):
        """Returns Ironic Inspector introspection data.

        Access swift and return introspection data for all nodes.

        :returns a list of tuples, one for each node.
        """

        session = get_auth_session({
            'auth_url': kwargs.get('auth_url'),
            'password': kwargs.get('password'),
            'username': '******',
            'project_name': 'service',
            })
        ironic = client.get_client(1, session=session)
        ironic_inspector = ClientV1(session=session)

        ret = []
        for node in ironic.node.list():
            try:
                ret.append((node.name, ironic_inspector.get_data(node.uuid)))
            except ClientError:
                pass

        return ret
Exemple #11
0
def get_client():  # pragma: no cover
    """Get Ironic client instance."""
    args = dict({'os_password': CONF.discoverd.os_password,
                 'os_username': CONF.discoverd.os_username,
                 'os_auth_url': CONF.discoverd.os_auth_url,
                 'os_tenant_name': CONF.discoverd.os_tenant_name})
    return client.get_client(1, **args)
Exemple #12
0
    def create_client(self, version=None, service_type=None):
        """Return Ironic client."""
        from ironicclient import client as ironic

        client = ironic.get_client(self.choose_version(version),
                                   session=self.keystone.get_session()[0],
                                   endpoint=self._get_endpoint(service_type))
        return client
Exemple #13
0
 def __init__(self, name='', keys='', inbox=None, datapath=None, args=None):
     super(IronicDriver, self).__init__(name, keys, inbox, datapath, args)
     datasource_driver.ExecutionDriver.__init__(self)
     self.creds = self.get_ironic_credentials(args)
     self.ironic_client = client.get_client(**self.creds)
     self.add_executable_client_methods(self.ironic_client,
                                        'ironicclient.v1.')
     self._init_end_start_poll()
Exemple #14
0
    def _get_api_ironic_client(version, is_api):
        if version == '1':
            if is_api:
                return api_clients.NodeApiClientV1(session=get_session())
            else:
                return client_v1.get_client(session=get_session())

        raise ValueError("Unexpected ironic version: {!r}".format(version))
def get_ironic_client(auth_variables):
    session = get_auth_session(auth_variables)
    ironic_url = session.get_endpoint(service_type='baremetal',
                                      interface='public')
    return ironic_client.get_client(
        1,
        ironic_url=ironic_url,
        os_auth_token=auth_variables.get('os_auth_token')
    )
 def test_correct_arguments_passed_to_client_constructor_noauth_mode(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'ironic_url': 'http://ironic.example.org:6385/',
         'os_auth_token': 'USER_AUTH_TOKEN',
         'os_ironic_api_version': 'latest',
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', **{'os_ironic_api_version': 'latest',
                 'max_retries': None,
                 'retry_interval': None,
                 'session': session,
                 'endpoint_override': 'http://ironic.example.org:6385/',
                 'interface': None}
     )
     self.assertFalse(session.get_endpoint.called)
    def _test_get_client(self, mock_ks_loader, mock_ks_session,
                         mock_retrieve_data, warn_mock, version=None,
                         auth='password', warn_mock_call_count=0,
                         expected_interface=None, **kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:6385/v1/f14b4123'

        class Opt(object):
            def __init__(self, name):
                self.dest = name

        session_loader_options = [
            Opt('insecure'), Opt('cafile'), Opt('certfile'), Opt('keyfile'),
            Opt('timeout')]
        mock_ks_session.return_value.get_conf_options.return_value = (
            session_loader_options)
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'
        mock_retrieve_data.return_value = version

        client = iroclient.get_client('1', **kwargs)
        self.assertEqual(warn_mock_call_count, warn_mock.call_count)
        iroclient.convert_keystoneauth_opts(kwargs)

        mock_ks_loader.assert_called_once_with(auth)
        session_opts = {k: v for (k, v) in kwargs.items() if k in
                        [o.dest for o in session_loader_options]}
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', **session_opts)
        if not {'endpoint', 'ironic_url'}.intersection(kwargs):
            session.get_endpoint.assert_called_once_with(
                service_type=kwargs.get('service_type') or 'baremetal',
                interface=expected_interface,
                region_name=kwargs.get('region_name'))
        if 'os_ironic_api_version' in kwargs:
            # NOTE(TheJulia): This does not test the negotiation logic
            # as a request must be triggered in order for any version
            # negotiation actions to occur.
            self.assertEqual(0, mock_retrieve_data.call_count)
            self.assertEqual(kwargs['os_ironic_api_version'],
                             client.current_api_version)
            self.assertFalse(client.is_api_version_negotiated)
        else:
            mock_retrieve_data.assert_called_once_with(
                host='localhost',
                port='6385')
            self.assertEqual(version or v1.DEFAULT_VER,
                             client.http_client.os_ironic_api_version)

        # make sure the interface is conveyed to the client
        if expected_interface is not None:
            self.assertEqual(expected_interface,
                             client.http_client.interface)
        if kwargs.get('os_endpoint_type'):
            self.assertEqual(kwargs['os_endpoint_type'],
                             client.http_client.interface)

        return client
Exemple #18
0
    def create_client(self, version=None, service_type=None):
        """Return Ironic client."""
        from ironicclient import client as ironic

        client = ironic.get_client(
            self.choose_version(version),
            session=self.keystone.get_session()[0],
            endpoint=self._get_endpoint(service_type))
        return client
 def conn(self):
     """Connection to ironic api"""
     logger.debug("Ironic client is connecting to {0}".format(
         self.ironic_url))
     kwargs = {
         'os_auth_token': self.os_auth_token,
         'ironic_url': self.ironic_url
     }
     return client.get_client(1, **kwargs)
def get_ironic_client(username, password, tenant_name, auth_url):
    LOG.debug('Creating ironic client.')
    kwargs = {
        'os_username': username,
        'os_password': password,
        'os_auth_url': auth_url,
        'os_tenant_name': tenant_name
    }
    return ironicclient.get_client(1, **kwargs)
def get_client_handle():

    kwargs = {'os_username': os.environ['OS_USERNAME'],
              'os_password': os.environ['OS_PASSWORD'],
              'os_auth_url': os.environ['OS_AUTH_URL'],
              'os_tenant_name': os.environ['OS_TENANT_NAME']}

    ironic = irclient.get_client(1, **kwargs)
    return ironic
Exemple #22
0
def make_ironicclient():
    return client.get_client(
        "1",
        os_username="******",
        os_password="******",
        os_tenant_name="admin",
        os_auth_url="http://172.27.59.42:5000/v2.0/",
        os_region_name="RegionOne"
    )
Exemple #23
0
 def iapi(self):
     if not self._iapi:
         self._iapi = iclient.get_client(1,
                                         os_auth_url=self.auth_url,
                                         os_username=self.username,
                                         os_password=self.password,
                                         os_project_name=self.tenant,
                                         insecure=True)
     return self._iapi
Exemple #24
0
def get_ironic_client(username, password, auth_url, tenant_name):
    kwargs = {
        'os_username': username,
        'os_password': password,
        'os_auth_url': auth_url,
        'os_tenant_name': tenant_name
    }

    return client.get_client(1, **kwargs)
Exemple #25
0
 def test_correct_arguments_passed_to_client_constructor_noauth_mode(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'ironic_url': 'http://ironic.example.org:6385/',
         'os_auth_token': 'USER_AUTH_TOKEN',
         'os_ironic_api_version': 'latest',
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', **{
             'os_ironic_api_version': 'latest',
             'max_retries': None,
             'retry_interval': None,
             'session': session,
             'endpoint_override': 'http://ironic.example.org:6385/'
         })
     self.assertFalse(session.get_endpoint.called)
Exemple #26
0
def get_ironic_client(auth_variables):
    session = get_auth_session(auth_variables)
    ironic_url = session.get_endpoint(service_type='baremetal',
                                      interface='public')
    return ironic_client.get_client(
        1,
        ironic_url=ironic_url,
        os_auth_token=auth_variables.get('os_auth_token')
    )
Exemple #27
0
    def test_get_client_with_auth_token_ironic_url(self):
        kwargs = {
            'ironic_url': 'http://ironic.example.org:6385/',
            'os_auth_token': 'USER_AUTH_TOKEN',
        }
        client = iroclient.get_client('1', **kwargs)

        self.assertEqual('USER_AUTH_TOKEN', client.http_client.auth_token)
        self.assertEqual('http://ironic.example.org:6385/',
                         client.http_client.endpoint)
Exemple #28
0
 def get_client(self, config):
     version = int(config.get('ironic', 'api_version'))
     kwargs = {'os_username': config.get('ironic', 'admin_username'),
               'os_password': config.get('ironic', 'admin_password'),
               'os_auth_url': config.get('ironic', 'admin_url'),
               'os_tenant_name': config.get('ironic', 'admin_tenant_name'),
               'os_service_type': 'baremetal',
               'os_endpoint_type': 'public',
               'ironic_url': config.get('ironic', 'api_endpoint')}
     return ironic_client.get_client(version, **kwargs)
Exemple #29
0
    def ironic(self):
        if self._ironic:
            return self._ironic

        ironicclient_version = self._get_client_option('ironic', 'api_version')
        endpoint_type = self._get_client_option('ironic', 'endpoint_type')
        self._ironic = irclient.get_client(ironicclient_version,
                                           os_endpoint_type=endpoint_type,
                                           session=self.session)
        return self._ironic
def get_client():
    ironic = client.get_client(
        api_version=1,
        os_auth_url=CONF.openstack.auth_url,
        os_region_name=CONF.openstack.region,
        os_username=CONF.openstack.username,
        os_password=CONF.openstack.password,
        os_tenant_name=CONF.openstack.project,
        insecure=CONF.openstack.insecure)
    return ironic
    def test_get_client_with_auth_token_ironic_url(self):
        kwargs = {
            'ironic_url': 'http://ironic.example.org:6385/',
            'os_auth_token': 'USER_AUTH_TOKEN',
        }
        client = iroclient.get_client('1', **kwargs)

        self.assertEqual('USER_AUTH_TOKEN', client.http_client.auth_token)
        self.assertEqual('http://ironic.example.org:6385/',
                         client.http_client.endpoint)
Exemple #32
0
    def main(self, argv):
        # Parse args once to find version
        parser = self.get_base_parser()
        (options, args) = parser.parse_known_args(argv)
        self._setup_debugging(options.debug)

        # build available subcommands based on version
        api_version = options.ironic_api_version
        subcommand_parser = self.get_subcommand_parser(api_version)
        self.parser = subcommand_parser

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line
        if options.help or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with these commands right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion()
            return 0

        if not (args.os_auth_token and args.ironic_url):
            if not args.os_username:
                raise exc.CommandError(_("You must provide a username via "
                                         "either --os-username or via "
                                         "env[OS_USERNAME]"))

            if not args.os_password:
                raise exc.CommandError(_("You must provide a password via "
                                         "either --os-password or via "
                                         "env[OS_PASSWORD]"))

            if not (args.os_tenant_id or args.os_tenant_name):
                raise exc.CommandError(_("You must provide a tenant_id via "
                                         "either --os-tenant-id or via "
                                         "env[OS_TENANT_ID]"))

            if not args.os_auth_url:
                raise exc.CommandError(_("You must provide an auth url via "
                                         "either --os-auth-url or via "
                                         "env[OS_AUTH_URL]"))

        client = iroclient.get_client(api_version, **(args.__dict__))

        try:
            args.func(client, args)
        except exc.Unauthorized:
            raise exc.CommandError(_("Invalid OpenStack Identity credentials"))
    def _test_loader_arguments_passed_correctly(
            self, mock_ks_loader, mock_ks_session,
            passed_kwargs, expected_kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:6385/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        iroclient.get_client('1', **passed_kwargs)

        mock_ks_loader.return_value.load_from_options.assert_called_once_with(
            **expected_kwargs)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=passed_kwargs.get('timeout'),
            insecure=passed_kwargs.get('insecure'),
            cert=passed_kwargs.get('cert'),
            cacert=passed_kwargs.get('cacert'), key=passed_kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=passed_kwargs.get('os_service_type') or 'baremetal',
            interface=passed_kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=passed_kwargs.get('os_region_name'))
    def _test_loader_arguments_passed_correctly(
            self, mock_ks_loader, mock_ks_session,
            passed_kwargs, expected_kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:6385/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        iroclient.get_client('1', **passed_kwargs)

        mock_ks_loader.return_value.load_from_options.assert_called_once_with(
            **expected_kwargs)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=passed_kwargs.get('timeout'),
            insecure=passed_kwargs.get('insecure'),
            cert=passed_kwargs.get('cert'),
            cacert=passed_kwargs.get('cacert'), key=passed_kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=passed_kwargs.get('os_service_type') or 'baremetal',
            interface=passed_kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=passed_kwargs.get('os_region_name'))
Exemple #35
0
def get_ironicclient():
    session = _get_session()
    try:
        return ironic_client.get_client(
            '1',
            session=session,
            os_region_name=CONF.service_credentials.os_region_name,
            os_endpoint_type=CONF.service_credentials.os_endpoint_type,
            os_ironic_api_version=IRONIC_API_VERSION)
    except ironic_exceptions.AmbiguousAuthSystem:
        raise keystone_exceptions.EndpointNotFound()
Exemple #36
0
 def __init__(self, name='', args=None):
     super(IronicDriver, self).__init__(name, args)
     datasource_driver.ExecutionDriver.__init__(self)
     self.creds = self.get_ironic_credentials(args)
     session = ds_utils.get_keystone_session(self.creds)
     self.ironic_client = client.get_client(
         api_version=self.creds.get('api_version', '1'), session=session)
     self.add_executable_client_methods(self.ironic_client,
                                        'ironicclient.v1.')
     self.initialize_update_methods()
     self._init_end_start_poll()
Exemple #37
0
 def test_correct_arguments_passed_to_client_constructor_session_created(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'os_auth_url': 'http://localhost:35357/v3',
         'os_region_name': 'REGIONONE',
         'os_project_id': '1000',
         'os_username': '******',
         'os_password': '******',
         'os_project_domain_name': 'domain1',
         'os_user_domain_name': 'domain1'
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', session.get_endpoint.return_value, **{
             'os_ironic_api_version': None,
             'max_retries': None,
             'retry_interval': None,
             'session': session,
         })
Exemple #38
0
    def test_get_client_with_auth_token_ironic_url(self):
        self.useFixture(fixtures.MonkeyPatch(
            'ironicclient.client._get_ksclient', fake_get_ksclient))
        kwargs = {
            'ironic_url': 'http://ironic.example.org:6385/',
            'os_auth_token': 'USER_AUTH_TOKEN',
        }
        client = get_client('1', **kwargs)

        self.assertEqual('USER_AUTH_TOKEN', client.http_client.auth_token)
        self.assertEqual('http://ironic.example.org:6385/',
                         client.http_client.endpoint)
Exemple #39
0
 def __init__(self, name='', args=None):
     super(IronicDriver, self).__init__(name, args)
     datasource_driver.ExecutionDriver.__init__(self)
     self.creds = self.get_ironic_credentials(args)
     session = ds_utils.get_keystone_session(self.creds)
     self.ironic_client = client.get_client(api_version=self.creds.get(
         'api_version', '1'),
                                            session=session)
     self.add_executable_client_methods(self.ironic_client,
                                        'ironicclient.v1.')
     self.initialize_update_methods()
     self._init_end_start_poll()
Exemple #40
0
    def create_client(self, version=None, service_type=None):
        """Return Ironic client."""
        from ironicclient import client as ironic

        kc = self.keystone()
        client = ironic.get_client(self.choose_version(version),
                                   os_auth_token=kc.auth_token,
                                   ironic_url=self._get_endpoint(service_type),
                                   timeout=CONF.openstack_client_http_timeout,
                                   insecure=self.credential.insecure,
                                   cacert=self.credential.cacert)
        return client
Exemple #41
0
    def ironic(self):
        if self._ironic:
            return self._ironic

        ironicclient_version = self._get_client_option('ironic', 'api_version')
        endpoint_type = self._get_client_option('ironic', 'endpoint_type')
        ironic_region_name = self._get_client_option('ironic', 'region_name')
        self._ironic = irclient.get_client(ironicclient_version,
                                           interface=endpoint_type,
                                           region_name=ironic_region_name,
                                           session=self.session)
        return self._ironic
Exemple #42
0
    def create_client(self, version=None, service_type=None):
        """Return Ironic client."""
        from ironicclient import client as ironic

        kc = self.keystone()
        client = ironic.get_client(self.choose_version(version),
                                   os_auth_token=kc.auth_token,
                                   ironic_url=self._get_endpoint(service_type),
                                   timeout=CONF.openstack_client_http_timeout,
                                   insecure=self.credential.insecure,
                                   cacert=self.credential.cacert)
        return client
Exemple #43
0
    def test_get_client_with_auth_token(self):
        self.useFixture(fixtures.MonkeyPatch("ironicclient.client._get_ksclient", fake_get_ksclient))
        kwargs = {
            "os_tenant_name": "TENANT_NAME",
            "os_username": "******",
            "os_password": "******",
            "os_auth_url": "http://localhost:35357/v2.0",
            "os_auth_token": "USER_AUTH_TOKEN",
        }
        client = get_client("1", **kwargs)

        self.assertEqual("USER_AUTH_TOKEN", client.http_client.auth_token)
 def test_correct_arguments_passed_to_client_constructor_session_created(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'os_auth_url': 'http://localhost:35357/v3',
         'os_region_name': 'REGIONONE',
         'os_project_id': '1000',
         'os_username': '******',
         'os_password': '******',
         'os_project_domain_name': 'domain1',
         'os_user_domain_name': 'domain1'
     }
     iroclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', **{'os_ironic_api_version': None,
                 'max_retries': None,
                 'retry_interval': None,
                 'session': session,
                 'endpoint_override': session.get_endpoint.return_value,
                 'interface': None}
     )
def get_ironicclient():
    session = _get_session()
    try:
        return ironic_client.get_client(
            '1',
            session=session,
            os_region_name=CONF.service_credentials.os_region_name,
            os_endpoint_type=CONF.service_credentials.os_endpoint_type,
            os_ironic_api_version=IRONIC_API_VERSION
        )
    except ironic_exceptions.AmbiguousAuthSystem:
        raise keystone_exceptions.EndpointNotFound()
Exemple #46
0
    def __init__(self, auth):
        LOG.debug('Creating a session')
        self._auth = auth
        self.session = session.Session(auth=auth)

        LOG.debug('Creating service clients')
        self.glance = glanceclient.Client(self.GLANCE_VERSION,
                                          session=self.session)
        self.neutron = neu_client.Client(session=self.session)
        self.ironic = ir_client.get_client(
            self.IRONIC_VERSION,
            session=self.session,
            os_ironic_api_version=self.IRONIC_MICRO_VERSION)
def get_ironic_client():
    """Method for getting python client by service name."""
    from ironicclient import client
    return client.get_client(
        1,
        os_ironic_api_version=environ.get('OS_IRONIC_API_VERSION'),
        os_region_name=environ['OS_REGION_NAME'],
        os_username=environ['OS_USERNAME'],
        os_password=environ['OS_PASSWORD'],
        os_auth_url=environ['OS_AUTH_URL'],
        os_project_name=environ['OS_PROJECT_NAME'],
        os_user_domain_name=environ['OS_USER_DOMAIN_NAME'],
        os_project_domain_name=environ['OS_PROJECT_DOMAIN_NAME'])
Exemple #48
0
 def ironic(self, version='1.0'):
     """Return Ironic client."""
     kc = self.keystone()
     baremetal_api_url = kc.service_catalog.url_for(
         service_type='baremetal', endpoint_type='public',
         region_name=self.endpoint.region_name)
     client = ironic.get_client(version,
                                os_auth_token=kc.auth_token,
                                ironic_url=baremetal_api_url,
                                timeout=CONF.openstack_client_http_timeout,
                                insecure=CONF.https_insecure,
                                cacert=CONF.https_cacert)
     return client
Exemple #49
0
def get_node_info(request, uuid):
    auth_url=base.url_for(request, 'identity'),
    kwargs = {
        'os_auth_token': request.user.token.id,
        'ironic_url':'http://223.3.73.169:6385/',
        #'ironic_url':auth_url,
        # 'timeout': args.timeout,
        # 'ca_file': args.ca_file,
        # 'cert_file': args.cert_file,
        # 'key_file': args.key_file,
    }
    client = ironic_client.get_client(1,**kwargs)
    return client.node.get(uuid)
Exemple #50
0
def getIronicNodes(**kwargs):
    uuids = []
    ironic = iclient.get_client(1, **kwargs)
    nodes = ironic.node.list(detail=True)
    for node in nodes:
        try:
            if node.extra['hardware_swift_object']:
                uuids.append(node.uuid)
        except KeyError:
            print "WARNING: could not find introspection data for node " \
            "{node}.".format(node=node.uuid)
            pass
    return uuids
Exemple #51
0
    def test_ensure_auth_ref_propagated(self):
        ksclient = fake_get_ksclient
        self.useFixture(fixtures.MonkeyPatch("ironicclient.client._get_ksclient", ksclient))
        kwargs = {
            "os_tenant_name": "TENANT_NAME",
            "os_username": "******",
            "os_password": "******",
            "os_auth_url": "http://localhost:35357/v2.0",
            "os_auth_token": "",
        }
        client = get_client("1", **kwargs)

        self.assertEqual(ksclient().auth_ref, client.http_client.auth_ref)
Exemple #52
0
    def _get_ironic_client(self):
        conf_client = ConfClient()
        keystone_conf = conf_client.keystone
        kwargs = {
            'os_username': keystone_conf.get_admin_user(),
            'os_password': keystone_conf.get_admin_password(),
            'os_auth_url': keystone_conf.get_auth_uri(),
            'os_tenant_name': keystone_conf.get_admin_tenant_name()
        }

        LOG.debug("Using OpenStack credentials specified in synch.conf to get"
                  " an Ironic Client")
        ironic = ironic_client.get_client(1, **kwargs)
        return ironic
def get_nodes(sess, node_id_or_names):
    token = sess.get_token()
    try:
        ironic_url = sess.get_endpoint(service_type='baremetal',
                                       interface='public')
    except Exception:
        traceback.print_exc(file=sys.stdout)
    ironic = ironic_client.get_client(1, token=token, endpoint=ironic_url)

    nodes = []
    for node_id_or_name in node_id_or_names:
        nodes.append(ironic.node.get(node_id_or_name))

    return nodes
Exemple #54
0
 def ironic(self, version="1.0"):
     """Return Ironic client."""
     kc = self.keystone()
     baremetal_api_url = kc.service_catalog.url_for(
         service_type="baremetal",
         endpoint_type=self.endpoint.endpoint_type,
         region_name=self.endpoint.region_name)
     client = ironic.get_client(version,
                                os_auth_token=kc.auth_token,
                                ironic_url=baremetal_api_url,
                                timeout=CONF.openstack_client_http_timeout,
                                insecure=CONF.https_insecure,
                                cacert=CONF.https_cacert)
     return client
Exemple #55
0
    def test_ensure_auth_ref_propagated(self):
        ksclient = fake_get_ksclient
        self.useFixture(fixtures.MonkeyPatch(
            'ironicclient.client._get_ksclient', ksclient))
        kwargs = {
            'os_tenant_name': 'TENANT_NAME',
            'os_username': '******',
            'os_password': '******',
            'os_auth_url': 'http://localhost:35357/v2.0',
            'os_auth_token': '',
        }
        client = get_client('1', **kwargs)

        self.assertEqual(ksclient().auth_ref, client.http_client.auth_ref)
    def _test_get_client(self, mock_cloud_region, mock_retrieve_data,
                         version=None, auth='password',
                         expected_interface=None, additional_headers=None,
                         global_request_id=None, **kwargs):
        session = mock_cloud_region.return_value.get_session.return_value
        session.get_endpoint.return_value = 'http://localhost:6385/v1/f14b4123'
        mock_retrieve_data.return_value = version

        client = iroclient.get_client(
            '1', additional_headers=additional_headers,
            global_request_id=global_request_id, **kwargs)

        expected_version = kwargs.pop('os_ironic_api_version', None)
        kwargs.pop('interface', None)
        kwargs.pop('valid_interfaces', None)

        get_endpoint_call = mock.call(
            service_type=kwargs.pop('service_type', None) or 'baremetal',
            interface=expected_interface,
            region_name=kwargs.pop('region_name', None))
        mock_cloud_region.assert_called_once_with(load_yaml_config=False,
                                                  load_envvars=False,
                                                  auth_type=auth, **kwargs)
        if 'endpoint' not in kwargs:
            self.assertEqual([get_endpoint_call],
                             session.get_endpoint.call_args_list)
        else:
            # we use adaper.get_endpoint instead of session.get_endpoint
            self.assertFalse(session.get_endpoint.called)
        if expected_version is not None:
            # NOTE(TheJulia): This does not test the negotiation logic
            # as a request must be triggered in order for any version
            # negotiation actions to occur.
            self.assertEqual(0, mock_retrieve_data.call_count)
            self.assertEqual(expected_version, client.current_api_version)
            self.assertFalse(client.is_api_version_negotiated)
        else:
            mock_retrieve_data.assert_called_once_with(
                host='localhost',
                port='6385')
            self.assertEqual(version or v1.DEFAULT_VER,
                             client.http_client.os_ironic_api_version)

        # make sure the interface is conveyed to the client
        if expected_interface is not None:
            self.assertEqual(expected_interface,
                             client.http_client.interface)

        return client