Exemplo n.º 1
0
    def __init__(self, session=None, task_manager=None, *args, **kwargs):
        super(OpenStackSDKAdapter, self).__init__(session=session,
                                                  *args,
                                                  **kwargs)
        if not task_manager:
            task_manager = _task_manager.TaskManager(name=self.service_type)

        self.task_manager = task_manager
Exemplo n.º 2
0
 def test_rate_parameter_dict(self):
     manager = task_manager.TaskManager(name='test',
                                        rate={
                                            'compute': 20,
                                            'network': 10,
                                        })
     self.assertEqual(1.0 / 20, manager._get_wait('compute'))
     self.assertEqual(1.0 / 10, manager._get_wait('network'))
     self.assertIsNone(manager._get_wait('object-store'))
Exemplo n.º 3
0
    def __init__(self,
                 session=None,
                 task_manager=None,
                 rate_limit=None,
                 concurrency=None,
                 *args,
                 **kwargs):
        super(OpenStackSDKAdapter, self).__init__(session=session,
                                                  *args,
                                                  **kwargs)
        if not task_manager:
            task_manager = _task_manager.TaskManager(name=self.service_type,
                                                     rate=rate_limit,
                                                     workers=concurrency)
            task_manager.start()

        self.task_manager = task_manager
Exemplo n.º 4
0
 def setUp(self):
     super(TestTaskManager, self).setUp()
     self.manager = task_manager.TaskManager(name='test')
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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,
                 **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 `Transition from Profile`_ for
                              details.
        :param profile: DEPRECATED. Only exists for short-term backwards
                        compatibility for python-openstackclient while we
                        transition. See `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)
            else:
                openstack_config = _config.OpenStackConfig(
                    app_name=app_name, app_version=app_version,
                    load_yaml_config=profile is None)
                self.config = openstack_config.get_one(
                    cloud=cloud, validate=session is None, **kwargs)

        if self.config.name:
            tm_name = ':'.join([
                self.config.name,
                self.config.region_name or 'unknown'])
        else:
            tm_name = self.config.region_name or 'unknown'

        self.task_manager = task_manager.TaskManager(name=tm_name)

        if session:
            # TODO(mordred) Expose constructor option for this in OCC
            self.config._keystone_session = session

        self.session = self.config.get_session()

        service_type_manager = os_service_types.ServiceTypes()
        for service in service_type_manager.services:
            self.add_service(
                service_description.OpenStackServiceDescription(
                    service, self.config))
Exemplo n.º 8
0
 def test_rate_parameter_scalar(self):
     manager = task_manager.TaskManager(name='test', rate=0.1234)
     self.assertEqual(1 / 0.1234, manager._get_wait('compute'))
     self.assertEqual(1 / 0.1234, manager._get_wait(None))