示例#1
0
def get_client(token=None,
               api_version=DEFAULT_IRONIC_API_VERSION):  # pragma: no cover
    """Get Ironic client instance."""
    global IRONIC_SESSION

    if not IRONIC_SESSION:
        IRONIC_SESSION = keystone.get_session('ironic')

    args = {
        'session': IRONIC_SESSION,
        'os_ironic_api_version': api_version,
        'max_retries': CONF.ironic.max_retries,
        'retry_interval': CONF.ironic.retry_interval
    }

    if token is not None:
        args['token'] = token

    endpoint = keystone.get_adapter('ironic',
                                    session=IRONIC_SESSION).get_endpoint()
    if not endpoint:
        raise utils.Error(
            _('Cannot find the bare metal endpoint either in Keystone or '
              'in the configuration'), code=500)
    return client.get_client(1, endpoint=endpoint, **args)
示例#2
0
    def __init__(self):
        """Constructor for creating a SwiftAPI object.

        Authentification is loaded from config file.
        """
        global SWIFT_SESSION

        adapter_opts = dict()
        # TODO(pas-ha): remove handling deprecated options in Rocky
        if CONF.swift.os_region and not CONF.swift.region_name:
            adapter_opts['region_name'] = CONF.swift.os_region

        try:
            if not SWIFT_SESSION:
                SWIFT_SESSION = keystone.get_session('swift')

            adapter = keystone.get_adapter('swift',
                                           session=SWIFT_SESSION,
                                           **adapter_opts)
        except Exception as exc:
            raise utils.Error(
                _("Could not create an adapter to connect to "
                  "the object storage service: %s") % exc)

        # TODO(pas-ha) reverse-construct SSL-related session options here
        params = {'os_options': {'object_storage_url': adapter.get_endpoint()}}

        try:
            self.connection = swift_client.Connection(session=SWIFT_SESSION,
                                                      **params)
        except Exception as exc:
            raise utils.Error(
                _("Could not connect to the object storage "
                  "service: %s") % exc)
示例#3
0
文件: ironic.py 项目: tyws/inspector
def get_client(token=None,
               api_version=DEFAULT_IRONIC_API_VERSION):  # pragma: no cover
    """Get Ironic client instance."""
    global IRONIC_SESSION

    # NOTE: To support standalone ironic without keystone
    # TODO(pas-ha) remove handling of deprecated opts in Rocky
    # TODO(pas-ha) rewrite when ironicclient natively supports 'none' auth
    # via sessions https://review.openstack.org/#/c/359061/
    if CONF.ironic.auth_strategy == 'noauth':
        CONF.set_override('auth_type', 'none', group='ironic')

    if not IRONIC_SESSION:
        IRONIC_SESSION = keystone.get_session('ironic')

    args = {
        'os_ironic_api_version': api_version,
        'max_retries': CONF.ironic.max_retries,
        'retry_interval': CONF.ironic.retry_interval
    }

    adapter_opts = dict()

    # TODO(pas-ha) use service auth with incoming token
    if CONF.ironic.auth_type != 'none':
        if token is None:
            args['session'] = IRONIC_SESSION
        else:
            args['token'] = token

    # TODO(pas-ha): remove handling of deprecated options in Rocky
    if CONF.ironic.os_region and not CONF.ironic.region_name:
        adapter_opts['region_name'] = CONF.ironic.os_region
    if (CONF.ironic.auth_type == 'none' and not CONF.ironic.endpoint_override
            and CONF.ironic.ironic_url):
        adapter_opts['endpoint_override'] = CONF.ironic.ironic_url

    adapter = keystone.get_adapter('ironic',
                                   session=IRONIC_SESSION,
                                   **adapter_opts)
    endpoint = adapter.get_endpoint()
    return client.Client(1, endpoint, **args)
示例#4
0
def get_client(token=None,
               api_version=DEFAULT_IRONIC_API_VERSION):  # pragma: no cover
    """Get Ironic client instance."""
    global IRONIC_SESSION

    # NOTE: To support standalone ironic without keystone
    # TODO(pas-ha) remove handling of deprecated opts in Rocky
    # TODO(pas-ha) rewrite when ironicclient natively supports 'none' auth
    # via sessions https://review.openstack.org/#/c/359061/
    if CONF.ironic.auth_strategy == 'noauth':
        CONF.set_override('auth_type', 'none', group='ironic')

    if not IRONIC_SESSION:
        IRONIC_SESSION = keystone.get_session('ironic')

    args = {
        'os_ironic_api_version': api_version,
        'max_retries': CONF.ironic.max_retries,
        'retry_interval': CONF.ironic.retry_interval}

    adapter_opts = dict()

    # TODO(pas-ha) use service auth with incoming token
    if CONF.ironic.auth_type != 'none':
        if token is None:
            args['session'] = IRONIC_SESSION
        else:
            args['token'] = token

    # TODO(pas-ha): remove handling of deprecated options in Rocky
    if CONF.ironic.os_region and not CONF.ironic.region_name:
        adapter_opts['region_name'] = CONF.ironic.os_region
    if (CONF.ironic.auth_type == 'none' and
            not CONF.ironic.endpoint_override and
            CONF.ironic.ironic_url):
        adapter_opts['endpoint_override'] = CONF.ironic.ironic_url

    adapter = keystone.get_adapter('ironic', session=IRONIC_SESSION,
                                   **adapter_opts)
    endpoint = adapter.get_endpoint()
    return client.Client(1, endpoint, **args)
示例#5
0
    def __init__(self):
        """Constructor for creating a SwiftAPI object.

        Authentification is loaded from config file.
        """
        global SWIFT_SESSION
        if not SWIFT_SESSION:
            SWIFT_SESSION = keystone.get_session('swift')

        adapter_opts = dict()
        # TODO(pas-ha): remove handling deprecated options in Rocky
        if CONF.swift.os_region and not CONF.swift.region_name:
            adapter_opts['region_name'] = CONF.swift.os_region

        adapter = keystone.get_adapter('swift',
                                       session=SWIFT_SESSION,
                                       **adapter_opts)

        # TODO(pas-ha) reverse-construct SSL-related session options here
        params = {'os_options': {'object_storage_url': adapter.get_endpoint()}}

        self.connection = swift_client.Connection(session=SWIFT_SESSION,
                                                  **params)
示例#6
0
    def __init__(self):
        """Constructor for creating a SwiftAPI object.

        Authentification is loaded from config file.
        """
        global SWIFT_SESSION
        if not SWIFT_SESSION:
            SWIFT_SESSION = keystone.get_session('swift')

        adapter_opts = dict()
        # TODO(pas-ha): remove handling deprecated options in Rocky
        if CONF.swift.os_region and not CONF.swift.region_name:
            adapter_opts['region_name'] = CONF.swift.os_region

        adapter = keystone.get_adapter('swift', session=SWIFT_SESSION,
                                       **adapter_opts)

        # TODO(pas-ha) reverse-construct SSL-related session options here
        params = {
            'os_options': {
                'object_storage_url': adapter.get_endpoint()}}

        self.connection = swift_client.Connection(session=SWIFT_SESSION,
                                                  **params)