예제 #1
0
def format_target(device_type,
                  target_name,
                  device,
                  backfstype,
                  target_types=(),
                  mgsnode=(),
                  fsname=None,
                  failnode=(),
                  servicenode=(),
                  param={},
                  index=None,
                  comment=None,
                  mountfsoptions=None,
                  network=(),
                  device_size=None,
                  mkfsoptions=None,
                  reformat=False,
                  stripe_count_hint=None,
                  iam_dir=False,
                  dryrun=False,
                  verbose=False,
                  quiet=False):
    """Perform a mkfs.lustre operation on a target device.
       Device may be a number of devices, block"""

    # freeze a view of the namespace before we start messing with it
    args = dict(locals())
    options = []

    # Now remove the locals that are not parameters for mkfs.
    del args['device_type']
    del args['target_name']

    tuple_options = [
        "target_types", "mgsnode", "failnode", "servicenode", "network"
    ]
    for name in tuple_options:
        arg = args[name]
        # ensure that our tuple arguments are always tuples, and not strings
        if not hasattr(arg, "__iter__"):
            arg = (arg, )

        if name == "target_types":
            for type in arg:
                options.append("--%s" % type)
        elif name == 'mgsnode':
            for mgs_nids in arg:
                options.append("--%s=%s" % (name, ",".join(mgs_nids)))
        else:
            if len(arg) > 0:
                options.append("--%s=%s" % (name, ",".join(arg)))

    flag_options = {
        'dryrun': '--dryrun',
        'reformat': '--reformat',
        'iam_dir': '--iam-dir',
        'verbose': '--verbose',
        'quiet': '--quiet',
    }

    for arg in flag_options:
        if args[arg]:
            options.append("%s" % flag_options[arg])

    dict_options = ["param"]
    for name in dict_options:
        for key, value in args[name].items():
            if value is not None:
                options.extend(["--%s" % name, "%s=%s" % (key, value)])

    # everything else
    handled = set(flag_options.keys() + tuple_options + dict_options)
    for name in set(args.keys()) - handled:
        if name == "device":
            continue
        value = args[name]
        if value is not None:
            options.append("--%s=%s" % (name, value))

    # cache BlockDevice to store knowledge of the device_type at this path
    BlockDevice(device_type, device)
    filesystem = FileSystem(backfstype, device)

    return filesystem.mkfs(target_name, options)
예제 #2
0
def format_target(device_type,
                  target_name,
                  device,
                  backfstype,
                  target_types=(),
                  mgsnode=(),
                  fsname=None,
                  failnode=(),
                  servicenode=(),
                  param=None,
                  index=None,
                  comment=None,
                  mountfsoptions=None,
                  network=(),
                  device_size=None,
                  mkfsoptions=None,
                  reformat=False,
                  stripe_count_hint=None,
                  iam_dir=False,
                  dryrun=False,
                  verbose=False,
                  quiet=False):
    """Perform a mkfs.lustre operation on a target device.
       Device may be a number of devices, block"""

    # freeze a view of the namespace before we start messing with it
    args = dict(locals())
    options = []

    # Now remove the locals that are not parameters for mkfs.
    del args['device_type']
    del args['target_name']

    single = "--{}".format
    double = "--{}={}".format

    tuple_options = [
        "target_types", "mgsnode", "failnode", "servicenode", "network"
    ]
    for name in tuple_options:
        arg = args[name]
        # ensure that our tuple arguments are always tuples, and not strings
        if not hasattr(arg, "__iter__"):
            arg = (arg, )

        if name == "target_types":
            options += [single(target) for target in arg]
        elif name == 'mgsnode':
            options += [double(name, ",".join(mgs_nids)) for mgs_nids in arg]
        elif len(arg) > 0:
            options.append(double(name, ",".join(arg)))

    flag_options = {
        'dryrun': '--dryrun',
        'reformat': '--reformat',
        'iam_dir': '--iam-dir',
        'verbose': '--verbose',
        'quiet': '--quiet',
    }
    options += [flag_options[arg] for arg in flag_options if args[arg]]

    dict_options = ["param"]
    for name in dict_options:
        arg = args[name]
        if arg:
            options += [
                x for key in arg if arg[key] is not None
                for x in [single(name), "{}={}".format(key, arg[key])]
            ]

    # everything else
    handled = set(flag_options.keys() + tuple_options + dict_options)
    options += [
        double(name, args[name]) for name in set(args.keys()) - handled
        if name != "device" and args[name] is not None
    ]

    # cache BlockDevice to store knowledge of the device_type at this path
    BlockDevice(device_type, device)
    filesystem = FileSystem(backfstype, device)

    return filesystem.mkfs(target_name, options)