Esempio n. 1
0
    def __init__(self,
                 cloud=None,
                 config=None,
                 session=None,
                 app_name=None,
                 app_version=None,
                 extra_services=None,
                 strict=False,
                 use_direct_get=False,
                 task_manager=None,
                 rate_limit=None,
                 oslo_conf=None,
                 service_types=None,
                 global_request_id=None,
                 strict_proxies=False,
                 **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param bool use_direct_get:
            For get methods, make specific REST calls for server-side
            filtering instead of making list calls and filtering client-side.
            Default false.
        :param task_manager:
            Ignored. Exists for backwards compat during transition. Rate limit
            parameters should be passed directly to the `rate_limit` parameter.
        :param rate_limit:
            Client-side rate limit, expressed in calls per second. The
            parameter can either be a single float, or it can be a dict with
            keys as service-type and values as floats expressing the calls
            per second for that service. Defaults to None, which means no
            rate-limiting is performed.
        :param oslo_conf: An oslo.config CONF object.
        :type oslo_conf: :class:`~oslo_config.cfg.ConfigOpts`
            An oslo.config ``CONF`` object that has been populated with
            ``keystoneauth1.loading.register_adapter_conf_options`` in
            groups named by the OpenStack service's project name.
        :param service_types:
            A list/set of service types this Connection should support. All
            other service types will be disabled (will error if used).
            **Currently only supported in conjunction with the ``oslo_conf``
            kwarg.**
        :param global_request_id: A Request-id to send with all interactions.
        :param strict_proxies:
            If True, check proxies on creation and raise
            ServiceDiscoveryException if the service is unavailable.
        :type strict_proxies: bool
            Throw an ``openstack.exceptions.ServiceDiscoveryException`` if the
            endpoint for a given service doesn't work. This is useful for
            OpenStack services using sdk to talk to other OpenStack services
            where it can be expected that the deployer config is correct and
            errors should be reported immediately.
            Default false.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion constructor.
        """
        self.config = config
        self._extra_services = {}
        self._strict_proxies = strict_proxies
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if oslo_conf:
                self.config = cloud_region.from_conf(
                    oslo_conf,
                    session=session,
                    app_name=app_name,
                    app_version=app_version,
                    service_types=service_types)
            elif session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name,
                    app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    rate_limit=rate_limit,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(cloud=cloud,
                                                       app_name=app_name,
                                                       app_version=app_version,
                                                       load_yaml_config=cloud
                                                       is not None,
                                                       load_envvars=cloud
                                                       is not None,
                                                       rate_limit=rate_limit,
                                                       **kwargs)

        self._session = None
        self._proxies = {}
        self.__pool_executor = None
        self._global_request_id = global_request_id
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the _*CloudMixin constructors while we work on
        # integrating things better.
        _cloud._OpenStackCloudMixin.__init__(self)
        _baremetal.BaremetalCloudMixin.__init__(self)
        _block_storage.BlockStorageCloudMixin.__init__(self)
        _clustering.ClusteringCloudMixin.__init__(self)
        _coe.CoeCloudMixin.__init__(self)
        _compute.ComputeCloudMixin.__init__(self)
        _dns.DnsCloudMixin.__init__(self)
        _floating_ip.FloatingIPCloudMixin.__init__(self)
        _identity.IdentityCloudMixin.__init__(self)
        _image.ImageCloudMixin.__init__(self)
        _network_common.NetworkCommonCloudMixin.__init__(self)
        _network.NetworkCloudMixin.__init__(self)
        _object_store.ObjectStoreCloudMixin.__init__(self)
        _orchestration.OrchestrationCloudMixin.__init__(self)
        _security_group.SecurityGroupCloudMixin.__init__(self)

        # Allow vendors to provide hooks. They will normally only receive a
        # connection object and a responsible to register additional services
        vendor_hook = kwargs.get('vendor_hook')
        if not vendor_hook and 'vendor_hook' in self.config.config:
            # Get the one from profile
            vendor_hook = self.config.config.get('vendor_hook')
        if vendor_hook:
            try:
                # NOTE(gtema): no class name in the hook, plain module:function
                # Split string hook into module and function
                try:
                    (package_name, function) = vendor_hook.rsplit(':')

                    if package_name and function:
                        import pkg_resources
                        ep = pkg_resources.EntryPoint('vendor_hook',
                                                      package_name,
                                                      attrs=(function, ))
                        hook = ep.resolve()
                        hook(self)
                except ValueError:
                    self.log.warning('Hook should be in the entrypoint '
                                     'module:attribute format')
            except (ImportError, TypeError) as e:
                self.log.warning('Configured hook %s cannot be executed: %s',
                                 vendor_hook, e)
Esempio n. 2
0
    def __init__(
            self,
            cloud=None,
            config=None,
            session=None,
            app_name=None,
            app_version=None,
            # TODO(shade) Remove these once we've shifted
            # python-openstackclient to not use the profile interface.
            authenticator=None,
            profile=None,
            extra_services=None,
            strict=False,
            use_direct_get=False,
            **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param authenticator: DEPRECATED. Only exists for short-term backwards
                              compatibility for python-openstackclient while we
                              transition. See :doc:`transition_from_profile`
                              for details.
        :param profile: DEPRECATED. Only exists for short-term backwards
                        compatibility for python-openstackclient while we
                        transition. See :doc:`transition_from_profile`
                        for details.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion contructor.
        """
        self.config = config
        self._extra_services = {}
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if profile:
                import openstack.profile
                # TODO(shade) Remove this once we've shifted
                # python-openstackclient to not use the profile interface.
                self.config = openstack.profile._get_config_from_profile(
                    profile, authenticator, **kwargs)
            elif session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name,
                    app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(cloud=cloud,
                                                       app_name=app_name,
                                                       app_version=app_version,
                                                       load_yaml_config=cloud
                                                       is not None,
                                                       load_envvars=cloud
                                                       is not None,
                                                       **kwargs)

        self.task_manager = task_manager.TaskManager(self.config.full_name)

        self._session = None
        self._proxies = {}
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the OpenStackCloud constructor while we work on integrating
        # things better.
        _cloud.OpenStackCloud.__init__(self)
Esempio n. 3
0
    def __init__(self, cloud=None, config=None, session=None,
                 app_name=None, app_version=None,
                 extra_services=None,
                 strict=False,
                 use_direct_get=False,
                 task_manager=None,
                 rate_limit=None,
                 **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param bool use_direct_get:
            For get methods, make specific REST calls for server-side
            filtering instead of making list calls and filtering client-side.
            Default false.
        :param task_manager:
            Task Manager to handle the execution of remote REST calls.
            Defaults to None which causes a direct-action Task Manager to be
            used.
        :type manager: :class:`~openstack.task_manager.TaskManager`
        :param rate_limit:
            Client-side rate limit, expressed in calls per second. The
            parameter can either be a single float, or it can be a dict with
            keys as service-type and values as floats expressing the calls
            per second for that service. Defaults to None, which means no
            rate-limiting is performed.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion constructor.
        """
        self.config = config
        self._extra_services = {}
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(
                    cloud=cloud,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=cloud is not None,
                    load_envvars=cloud is not None,
                    **kwargs)

        if task_manager:
            # If a TaskManager was passed in, don't start it, assume it's
            # under the control of the calling context.
            self.task_manager = task_manager
        else:
            self.task_manager = _task_manager.TaskManager(
                self.config.full_name,
                rate=rate_limit)
            self.task_manager.start()

        self._session = None
        self._proxies = {}
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the _OpenStackCloudMixin constructor while we work on
        # integrating things better.
        _cloud._OpenStackCloudMixin.__init__(self)
    def __init__(self, cloud=None, config=None, session=None,
                 app_name=None, app_version=None,
                 extra_services=None,
                 strict=False,
                 use_direct_get=False,
                 task_manager=None,
                 rate_limit=None,
                 **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param bool use_direct_get:
            For get methods, make specific REST calls for server-side
            filtering instead of making list calls and filtering client-side.
            Default false.
        :param task_manager:
            Ignored. Exists for backwards compat during transition. Rate limit
            parameters should be passed directly to the `rate_limit` parameter.
        :param rate_limit:
            Client-side rate limit, expressed in calls per second. The
            parameter can either be a single float, or it can be a dict with
            keys as service-type and values as floats expressing the calls
            per second for that service. Defaults to None, which means no
            rate-limiting is performed.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion constructor.
        """
        self.config = config
        self._extra_services = {}
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    rate_limit=rate_limit,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(
                    cloud=cloud,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=cloud is not None,
                    load_envvars=cloud is not None,
                    rate_limit=rate_limit,
                    **kwargs)

        self._session = None
        self._proxies = {}
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the _*CloudMixin constructors while we work on
        # integrating things better.
        _cloud._OpenStackCloudMixin.__init__(self)
        _baremetal.BaremetalCloudMixin.__init__(self)
        _block_storage.BlockStorageCloudMixin.__init__(self)
        _clustering.ClusteringCloudMixin.__init__(self)
        _coe.CoeCloudMixin.__init__(self)
        _compute.ComputeCloudMixin.__init__(self)
        _dns.DnsCloudMixin.__init__(self)
        _floating_ip.FloatingIPCloudMixin.__init__(self)
        _identity.IdentityCloudMixin.__init__(self)
        _image.ImageCloudMixin.__init__(self)
        _network_common.NetworkCommonCloudMixin.__init__(self)
        _network.NetworkCloudMixin.__init__(self)
        _object_store.ObjectStoreCloudMixin.__init__(self)
        _orchestration.OrchestrationCloudMixin.__init__(self)
        _security_group.SecurityGroupCloudMixin.__init__(self)

        # Allow vendors to provide hooks. They will normally only receive a
        # connection object and a responsible to register additional services
        vendor_hook = kwargs.get('vendor_hook')
        if not vendor_hook and 'vendor_hook' in self.config.config:
            # Get the one from profile
            vendor_hook = self.config.config.get('vendor_hook')
        if vendor_hook:
            try:
                # NOTE(gtema): no class name in the hook, plain module:function
                # Split string hook into module and function
                try:
                    (package_name, function) = vendor_hook.rsplit(':')

                    if package_name and function:
                        import pkg_resources
                        ep = pkg_resources.EntryPoint(
                            'vendor_hook', package_name, attrs=(function,))
                        hook = ep.resolve()
                        hook(self)
                except ValueError:
                    self.log.warning('Hook should be in the entrypoint '
                                     'module:attribute format')
            except (ImportError, TypeError) as e:
                self.log.warning('Configured hook %s cannot be executed: %s',
                                 vendor_hook, e)
Esempio n. 5
0
    'neutron-linuxbridge-agent', 'neutron-dhcp-agent', 'neutron-l3-agent',
    'neutron-metadata-agent', 'neutron-metering-agent'
]
NOVA_SERVICE_TYPE_LIST = [
    'nova-cert', 'nova-compute', 'nova-conductor', 'nova-consoleauth',
    'nova-scheduler'
]

cloud = 'default'
# (NOTE:tonytan4ever): for OSP cloud, cloud parameter needs to be None
if os.getenv('OS_CLOUDNAME') is not None:
    cloud = None

if os.path.exists(OPENRC) or os.path.exists(STACKRC):
    try:
        OSC_CONFIG = get_cloud_region(cloud=cloud)
    except ConfigException as e:
        # (NOTE:tonytan4ever) Liberty cloud does not have 'default' config
        if 'Cloud default was not found' in str(e):
            OSC_CONFIG = get_cloud_region(cloud=None)
        else:
            raise e
    OSC_CLIENT = Connection(config=OSC_CONFIG, verify=False)


def get_os_component_major_api_version(component_name):
    supported_os_component_osc_mapping = {
        'nova': 'compute',
        'neutron': 'network',
        'cinder': 'volume',
        'glance': 'image',
Esempio n. 6
0
    def __init__(self,
                 cloud=None,
                 config=None,
                 session=None,
                 app_name=None,
                 app_version=None,
                 extra_services=None,
                 strict=False,
                 use_direct_get=False,
                 task_manager=None,
                 rate_limit=None,
                 **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param bool use_direct_get:
            For get methods, make specific REST calls for server-side
            filtering instead of making list calls and filtering client-side.
            Default false.
        :param task_manager:
            Ignored. Exists for backwards compat during transition. Rate limit
            parameters should be passed directly to the `rate_limit` parameter.
        :param rate_limit:
            Client-side rate limit, expressed in calls per second. The
            parameter can either be a single float, or it can be a dict with
            keys as service-type and values as floats expressing the calls
            per second for that service. Defaults to None, which means no
            rate-limiting is performed.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion constructor.
        """
        self.config = config
        self._extra_services = {}
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name,
                    app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    rate_limit=rate_limit,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(cloud=cloud,
                                                       app_name=app_name,
                                                       app_version=app_version,
                                                       load_yaml_config=cloud
                                                       is not None,
                                                       load_envvars=cloud
                                                       is not None,
                                                       rate_limit=rate_limit,
                                                       **kwargs)

        self._session = None
        self._proxies = {}
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the _*CloudMixin constructors while we work on
        # integrating things better.
        _cloud._OpenStackCloudMixin.__init__(self)
        _baremetal.BaremetalCloudMixin.__init__(self)
        _block_storage.BlockStorageCloudMixin.__init__(self)
        _clustering.ClusteringCloudMixin.__init__(self)
        _coe.CoeCloudMixin.__init__(self)
        _compute.ComputeCloudMixin.__init__(self)
        _dns.DnsCloudMixin.__init__(self)
        _floating_ip.FloatingIPCloudMixin.__init__(self)
        _identity.IdentityCloudMixin.__init__(self)
        _image.ImageCloudMixin.__init__(self)
        _network_common.NetworkCommonCloudMixin.__init__(self)
        _network.NetworkCloudMixin.__init__(self)
        _object_store.ObjectStoreCloudMixin.__init__(self)
        _orchestration.OrchestrationCloudMixin.__init__(self)
        _security_group.SecurityGroupCloudMixin.__init__(self)
Esempio n. 7
0
def get_client(api_version,
               auth_type=None,
               os_ironic_api_version=None,
               max_retries=None,
               retry_interval=None,
               session=None,
               valid_interfaces=None,
               interface=None,
               service_type=None,
               region_name=None,
               additional_headers=None,
               global_request_id=None,
               **kwargs):
    """Get an authenticated client, based on the credentials.

    :param api_version: the API version to use. Valid value: '1'.
    :param auth_type: type of keystoneauth auth plugin loader to use.
    :param os_ironic_api_version: ironic API version to use.
    :param max_retries: Maximum number of retries in case of conflict error
    :param retry_interval: Amount of time (in seconds) between retries in case
        of conflict error.
    :param session: An existing keystoneauth session. Will be created from
        kwargs if not provided.
    :param valid_interfaces: List of valid endpoint interfaces to use if
        the bare metal endpoint is not provided.
    :param interface: An alias for valid_interfaces.
    :param service_type: Bare metal endpoint service type.
    :param region_name: Name of the region to use when searching the bare metal
        endpoint.
    :param additional_headers: Additional headers that should be attached
        to every request passing through the client. Headers of the same name
        specified per request will take priority.
    :param global_request_id: A header (in the form of ``req-$uuid``) that will
        be passed on all requests. Enables cross project request id tracking.
    :param kwargs: all the other params that are passed to keystoneauth for
        session construction.
    """
    # TODO(TheJulia): At some point, we should consider possibly noting
    # the "latest" flag for os_ironic_api_version to cause the client to
    # auto-negotiate to the greatest available version, however we do not
    # have the ability yet for a caller to cap the version, and will hold
    # off doing so until then.
    if auth_type is None:
        if 'endpoint' in kwargs:
            if 'token' in kwargs:
                auth_type = 'admin_token'
            else:
                auth_type = 'none'
        elif 'token' in kwargs and 'auth_url' in kwargs:
            auth_type = 'token'
        else:
            auth_type = 'password'

    if not session:
        # TODO(dtantsur): consider flipping load_yaml_config to True to support
        # the clouds.yaml format.
        region = config.get_cloud_region(load_yaml_config=False,
                                         load_envvars=False,
                                         auth_type=auth_type,
                                         **kwargs)
        session = region.get_session()

    # Make sure we also pass the endpoint interface to the HTTP client.
    # NOTE(gyee/efried): 'interface' in ksa config is deprecated in favor of
    # 'valid_interfaces'. So, since the caller may be deriving kwargs from
    # conf, accept 'valid_interfaces' first. But keep support for 'interface',
    # in case the caller is deriving kwargs from, say, an existing Adapter.
    interface = valid_interfaces or interface

    endpoint = kwargs.get('endpoint')
    if not endpoint:
        try:
            # endpoint will be used to get hostname
            # and port that will be used for API version caching.
            # NOTE(gyee): KSA defaults interface to 'public' if it is
            # empty or None so there's no need to set it to publicURL
            # explicitly.
            endpoint = session.get_endpoint(
                service_type=service_type or 'baremetal',
                interface=interface,
                region_name=region_name,
            )
        except Exception as e:
            raise exc.AmbiguousAuthSystem(
                _('Must provide Keystone credentials or user-defined '
                  'endpoint, error was: %s') % e)

    ironicclient_kwargs = {
        'os_ironic_api_version': os_ironic_api_version,
        'additional_headers': additional_headers,
        'global_request_id': global_request_id,
        'max_retries': max_retries,
        'retry_interval': retry_interval,
        'session': session,
        'endpoint_override': endpoint,
        'interface': interface
    }

    return Client(api_version, **ironicclient_kwargs)
Esempio n. 8
0
    def __init__(self, cloud=None, config=None, session=None,
                 app_name=None, app_version=None,
                 # TODO(shade) Remove these once we've shifted
                 # python-openstackclient to not use the profile interface.
                 authenticator=None, profile=None,
                 extra_services=None,
                 strict=False,
                 use_direct_get=False,
                 **kwargs):
        """Create a connection to a cloud.

        A connection needs information about how to connect, how to
        authenticate and how to select the appropriate services to use.

        The recommended way to provide this information is by referencing
        a named cloud config from an existing `clouds.yaml` file. The cloud
        name ``envvars`` may be used to consume a cloud configured via ``OS_``
        environment variables.

        A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`
        object can be passed in lieu of a cloud name, for cases where the user
        already has a fully formed CloudRegion and just wants to use it.

        Similarly, if for some reason the user already has a
        :class:`~keystoneauth1.session.Session` and wants to use it, it may be
        passed in.

        :param str cloud: Name of the cloud from config to use.
        :param config: CloudRegion object representing the config for the
            region of the cloud in question.
        :type config: :class:`~openstack.config.cloud_region.CloudRegion`
        :param session: A session object compatible with
            :class:`~keystoneauth1.session.Session`.
        :type session: :class:`~keystoneauth1.session.Session`
        :param str app_name: Name of the application to be added to User Agent.
        :param str app_version: Version of the application to be added to
            User Agent.
        :param authenticator: DEPRECATED. Only exists for short-term backwards
                              compatibility for python-openstackclient while we
                              transition. See :doc:`transition_from_profile`
                              for details.
        :param profile: DEPRECATED. Only exists for short-term backwards
                        compatibility for python-openstackclient while we
                        transition. See :doc:`transition_from_profile`
                        for details.
        :param extra_services: List of
            :class:`~openstack.service_description.ServiceDescription`
            objects describing services that openstacksdk otherwise does not
            know about.
        :param kwargs: If a config is not provided, the rest of the parameters
            provided are assumed to be arguments to be passed to the
            CloudRegion contructor.
        """
        self.config = config
        self._extra_services = {}
        if extra_services:
            for service in extra_services:
                self._extra_services[service.service_type] = service

        if not self.config:
            if profile:
                import openstack.profile
                # TODO(shade) Remove this once we've shifted
                # python-openstackclient to not use the profile interface.
                self.config = openstack.profile._get_config_from_profile(
                    profile, authenticator, **kwargs)
            elif session:
                self.config = cloud_region.from_session(
                    session=session,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=False,
                    load_envvars=False,
                    **kwargs)
            else:
                self.config = _config.get_cloud_region(
                    cloud=cloud,
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=cloud is not None,
                    load_envvars=cloud is not None,
                    **kwargs)

        self.task_manager = task_manager.TaskManager(self.config.full_name)

        self._session = None
        self._proxies = {}
        self.use_direct_get = use_direct_get
        self.strict_mode = strict
        # Call the OpenStackCloud constructor while we work on integrating
        # things better.
        _cloud.OpenStackCloud.__init__(self)