Esempio n. 1
0
def get_provider(platform_name, provider_type, event_handler):
    for provider in CONF.providers:
        cls = utils.load_class(provider)
        if (cls.platform == platform_name
                and issubclass(cls, PROVIDER_TYPE_MAP[provider_type])):
            return cls(event_handler)

    raise exception.NotFound(
        "Provider not found for: %(platform_name)s, %(provider_type)s" % {
            "platform_name": platform_name,
            "provider_type": provider_type
        })
Esempio n. 2
0
def get_available_providers():
    providers = {}
    for provider in CONF.providers:
        cls = utils.load_class(provider)
        for provider_type, provider_class in PROVIDER_TYPE_MAP.items():
            provider_data = providers.get(cls.platform, {})

            provider_types = provider_data.get("types", [])
            if (provider_class in cls.__bases__
                    and provider_type not in provider_types):
                provider_types.append(provider_type)

            provider_data["types"] = sorted(provider_types)
            providers[cls.platform] = provider_data
    return providers
Esempio n. 3
0
def get_provider(
        platform_name, provider_type, event_handler, raise_if_not_found=True):
    for provider in CONF.providers:
        cls = utils.load_class(provider)
        parent = PROVIDER_TYPE_MAP.get(provider_type)
        if not parent:
            continue
        if (cls.platform == platform_name and issubclass(cls, parent)):
            return cls(event_handler)

    if raise_if_not_found:
        raise exception.NotFound(
            "Provider not found for: %(platform_name)s, %(provider_type)s" %
            {"platform_name": platform_name, "provider_type": provider_type})

    return None