Esempio n. 1
0
def initialize_block_devices(report_processor, cmd_runner, device_list,
                             option_dict):
    """
    Initialize devices with specified options in option_dict.
    Raise LibraryError on failure.

    report_processor -- report processor
    cmd_runner -- CommandRunner
    device_list -- list of strings
    option_dict -- dictionary of options and their values
    """
    report_processor.process(
        reports.sbd_device_initialization_started(device_list))

    cmd = [settings.sbd_binary]
    for device in device_list:
        cmd += ["-d", device]

    for option, value in sorted(option_dict.items()):
        cmd += [DEVICE_INITIALIZATION_OPTIONS_MAPPING[option], str(value)]

    cmd.append("create")
    _, std_err, ret_val = cmd_runner.run(cmd)
    if ret_val != 0:
        raise LibraryError(
            reports.sbd_device_initialization_error(device_list, std_err))
    report_processor.process(
        reports.sbd_device_initialization_success(device_list))
Esempio n. 2
0
def initialize_block_devices(
    report_processor, cmd_runner, device_list, option_dict
):
    """
    Initialize devices with specified options in option_dict.
    Raise LibraryError on failure.

    report_processor -- report processor
    cmd_runner -- CommandRunner
    device_list -- list of strings
    option_dict -- dictionary of options and their values
    """
    report_processor.process(
        reports.sbd_device_initialization_started(device_list)
    )

    cmd = [settings.sbd_binary]
    for device in device_list:
        cmd += ["-d", device]

    for option, value in sorted(option_dict.items()):
        cmd += [DEVICE_INITIALIZATION_OPTIONS_MAPPING[option], str(value)]

    cmd.append("create")
    _, std_err, ret_val = cmd_runner.run(cmd)
    if ret_val != 0:
        raise LibraryError(
            reports.sbd_device_initialization_error(device_list, std_err)
        )
    report_processor.process(
        reports.sbd_device_initialization_success(device_list)
    )