Ejemplo n.º 1
0
 def _get_all_exporter_units(self):
     exporter_map = {}
     for provider in get_providers():
         for unit in provider.unit_list:
             if unit.Meta.name == 'exporter':
                 exporter_map[unit.id] = ExporterUnitSupport(unit)
     return exporter_map
    def get_throwaway_manager(cls, provider_list=None):
        """
        Create a temporary session manager.

        :param provider_list:
            (optional) A list of providers to put into the session manager. By
            default all known providers are added. You can use this argument to
            customize the behaviour beyond defaults.
        :returns:
            A new SessionManager object that will be destroyed when the context
            manager is left.

        This method can be used to create a throw-away session manager which is
        not really meant for running jobs but can be useful to access exporters
        and other objects stored in providers.
        """
        with tempfile.TemporaryDirectory() as tmp:
            repo = SessionStorageRepository(tmp)
            if provider_list is None:
                provider_list = get_providers()
            try:
                manager = cls.create(repo=repo)
                manager.add_local_device_context()
                device_context = manager.default_device_context
                for provider in provider_list:
                    device_context.add_provider(provider)
                yield manager
            finally:
                manager.destroy()
Ejemplo n.º 3
0
    def get_throwaway_manager(cls, provider_list=None):
        """
        Create a temporary session manager.

        :param provider_list:
            (optional) A list of providers to put into the session manager. By
            default all known providers are added. You can use this argument to
            customize the behaviour beyond defaults.
        :returns:
            A new SessionManager object that will be destroyed when the context
            manager is left.

        This method can be used to create a throw-away session manager which is
        not really meant for running jobs but can be useful to access exporters
        and other objects stored in providers.
        """
        key = hash(frozenset(provider_list)) if provider_list else ''
        if not cls._throwaway_managers.get(key):
            # for safety let's create more persistent tempdir than
            # the TemporaryDirectory context_manager
            if provider_list is None:
                provider_list = get_providers()
            manager = cls.create(prefix="throwaway-")
            atexit.register(lambda: manager.destroy())
            manager.add_local_device_context()
            device_context = manager.default_device_context
            cls._throwaway_managers[key] = manager
            for provider in provider_list:
                device_context.add_provider(provider)
        yield cls._throwaway_managers[key]
Ejemplo n.º 4
0
def get_stack_version():
    """
    Generate version information of Checkbox stack components as understood
    by Checkbox.
    """
    info = OrderedDict()
    info['checkbox-ng'] = checkbox_ng.__version__
    try:
        support_ver = checkbox_support.__version__
    except AttributeError:
        import pkg_resources
        support_ver = pkg_resources.get_distribution(
            "checkbox-support").version
    info['checkbox-support'] = support_ver
    ignored_providers = [
        'com.canonical.plainbox:manifest',
        'com.canonical.plainbox:exporters',
        'com.canonical.plainbox:categories',
    ]
    # maybe filter-out the built-in providers (exporters, categories, etc.)
    for provider in get_providers():
        if provider.name not in ignored_providers:
            info[provider.name] = provider.version
    return info
 def _load_providers(self):
     logger.info("Loading all providers...")
     return get_providers()