Beispiel #1
0
def get_devices():
    devices = []
    if config('osd-devices'):
        for path in config('osd-devices').split(' '):
            path = path.strip()
            # Ensure that only block devices
            # are considered for evaluation as block devices.
            # This avoids issues with relative directories
            # being passed via configuration, and ensures that
            # the path to a block device provided by the user
            # is used, rather than its target which may change
            # between reboots in the case of bcache devices.
            if is_block_device(path):
                devices.append(path)
            # Make sure its a device which is specified using an
            # absolute path so that the current working directory
            # or any relative path under this directory is not used
            elif os.path.isabs(path):
                devices.append(os.path.realpath(path))

    # List storage instances for the 'osd-devices'
    # store declared for this charm too, and add
    # their block device paths to the list.
    storage_ids = storage_list('osd-devices')
    devices.extend((storage_get('location', s) for s in storage_ids))

    # Filter out any devices in the action managed unit-local device blacklist
    _blacklist = get_blacklist()
    return [device for device in devices if device not in _blacklist]
def get_devices():
    devices = []
    if config('osd-devices'):
        for path in config('osd-devices').split(' '):
            path = path.strip()
            # Ensure that only block devices
            # are considered for evaluation as block devices.
            # This avoids issues with relative directories
            # being passed via configuration, and ensures that
            # the path to a block device provided by the user
            # is used, rather than its target which may change
            # between reboots in the case of bcache devices.
            if is_block_device(path):
                devices.append(path)
            # Make sure its a device which is specified using an
            # absolute path so that the current working directory
            # or any relative path under this directory is not used
            elif os.path.isabs(path):
                devices.append(os.path.realpath(path))

    # List storage instances for the 'osd-devices'
    # store declared for this charm too, and add
    # their block device paths to the list.
    storage_ids = storage_list('osd-devices')
    devices.extend((storage_get('location', s) for s in storage_ids))

    # Filter out any devices in the action managed unit-local device blacklist
    _blacklist = get_blacklist()
    return [device for device in devices if device not in _blacklist]
Beispiel #3
0
def _init_pool(media_type, profile_id=None, providers=None):
    pool = provider_pool()
    return pool(
        providers=providers or get_providers(),
        provider_configs=get_providers_auth(),
        blacklist=get_blacklist(media_type),
        throttle_callback=provider_throttle,
        ban_list=get_ban_list(profile_id),
        language_hook=None,
    )
def get_journal_devices():
    if config('osd-journal'):
        devices = [l.strip() for l in config('osd-journal').split(' ')]
    else:
        devices = []
    storage_ids = storage_list('osd-journals')
    devices.extend((storage_get('location', s) for s in storage_ids))

    # Filter out any devices in the action managed unit-local device blacklist
    _blacklist = get_blacklist()
    return set(device for device in devices
               if device not in _blacklist and os.path.exists(device))
Beispiel #5
0
def _update_pool(media_type, profile_id=None):
    pool_key = f'{media_type}_{profile_id or ""}'
    logging.debug("BAZARR updating pool: %s", pool_key)

    # Init a new pool if not present
    if pool_key not in _pools:
        logging.debug("BAZARR pool not initialized: %s. Initializing", pool_key)
        _pools[pool_key] = _init_pool(media_type, profile_id)

    pool = _pools[pool_key]
    if pool is None:
        return False

    return pool.update(
        get_providers(),
        get_providers_auth(),
        get_blacklist(media_type),
        get_ban_list(profile_id),
    )
Beispiel #6
0
def get_devices():
    devices = []
    if config('osd-devices'):
        for path in config('osd-devices').split(' '):
            path = path.strip()
            # Make sure its a device which is specified using an
            # absolute path so that the current working directory
            # or any relative path under this directory is not used
            if os.path.isabs(path):
                devices.append(os.path.realpath(path))

    # List storage instances for the 'osd-devices'
    # store declared for this charm too, and add
    # their block device paths to the list.
    storage_ids = storage_list('osd-devices')
    devices.extend((storage_get('location', s) for s in storage_ids))

    # Filter out any devices in the action managed unit-local device blacklist
    _blacklist = get_blacklist()
    return [device for device in devices if device not in _blacklist]
Beispiel #7
0
def export_plugins(from_lang, plugin_list, plugin_selection=None):
    field_blacklist = get_blacklist()
    plugin_data = []
    for plugin in plugin_list:
        try:
            instance = plugin.get_plugin_instance()[0]
        except KeyError as e:
            # Nasty fix for StackPlugins still straying around
            if str(e) != "u'StackPlugin'":
                raise KeyError(str(e))
            continue

        if instance is None:
            continue
        elif plugin_selection and str(type(instance)) not in plugin_selection:
            continue

        if getattr(instance, "language") == from_lang:  # TODO: check: could this break at some point?
            plugin_contents = plugin.get_plugin_instance()[0].get_translatable_content()
            if plugin_contents:
                if not isinstance(plugin_contents, list):
                    plugin_contents = [plugin_contents]

                for item in plugin_contents:
                    plugin_dict = {
                        'plugin_pk': getattr(plugin, "pk"),
                        'plugin_type': "%s%s" % (instance.__class__.__name__,  " (%s)" % str(type(instance)) or ""),
                        'fields': {}
                    }

                    for key, value in item.items():
                        if not key in field_blacklist:
                            plugin_dict['fields'][key] = value

                    plugin_data.append(plugin_dict)

    if log_to_file_enabled():
        log_to_file(plugin_data)

    return plugin_data