예제 #1
0
파일: utils.py 프로젝트: lcorreia/ginger
def delete_part(partname):
    """
    Deletes the specified partition
    :param partname: name of the partition to be deleted
    :return:
    """
    devname = ''.join(i for i in partname if not i.isdigit())
    majmin = _get_dev_major_min(devname)
    dev_path = _get_dev_node_path(majmin)
    partnum = ''.join(filter(lambda x: x.isdigit(), partname))
    device = PDevice(dev_path)
    disk = PDisk(device)
    parts = disk.partitions
    if len(parts) == 1:
        typ_str = '\nd\nw\n'
    elif len(parts) > 1:
        typ_str = '\nd\n' + partnum + '\n' + 'w\n'
    else:
        raise OperationFailed("GINPART00013E")
    d1_out = subprocess.Popen(["echo", "-e", "\'", typ_str, "\'"],
                              stdout=subprocess.PIPE)
    d2_out = subprocess.Popen(["fdisk", dev_path],
                              stdin=d1_out.stdout,
                              stderr=subprocess.PIPE,
                              stdout=subprocess.PIPE)
    d1_out.stdout.close()
    out, err = d2_out.communicate()
    if d2_out.returncode != 0:
        raise OperationFailed("GINPART00011E", err)
예제 #2
0
파일: utils.py 프로젝트: LiftedKilt/ginger
def delete_part(partname):
    """
    Deletes the specified partition
    :param partname: name of the partition to be deleted
    :return:
    """
    devname = ''.join(i for i in partname if not i.isdigit())
    majmin = _get_dev_major_min(devname)
    dev_path = _get_dev_node_path(majmin)
    partnum = ''.join(filter(lambda x: x.isdigit(), partname))
    device = PDevice(dev_path)
    disk = PDisk(device)
    parts = disk.partitions
    if len(parts) == 1:
        typ_str = '\nd\nw\n'
    elif len(parts) > 1:
        typ_str = '\nd\n' + partnum + '\n' + 'w\n'
    else:
        raise OperationFailed("GINPART00013E")
    d1_out = subprocess.Popen(["echo", "-e", "\'", typ_str, "\'"],
                              stdout=subprocess.PIPE)
    d2_out = subprocess.Popen(["fdisk", dev_path], stdin=d1_out.stdout,
                              stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    d1_out.stdout.close()
    out, err = d2_out.communicate()
    if d2_out.returncode != 0:
        raise OperationFailed("GINPART00011E", err)
예제 #3
0
def change_part_type(part, type_hex):
    """
    Change the type of the given partition
    :param part: partition number on the device
    :param type_hex: partition type in hex
    :return:
    """
    devname = "".join(i for i in part if not i.isdigit())
    majmin = _get_dev_major_min(devname)

    dev_path = _get_dev_node_path(majmin)
    partnum = "".join(filter(lambda x: x.isdigit(), part))

    device = PDevice(dev_path)
    disk = PDisk(device)
    parts = disk.partitions

    if len(parts) == 1:
        typ_str = "\nt\n" + type_hex + "\n" + "w\n"
    elif len(parts) > 1:
        typ_str = "\nt\n" + partnum + "\n" + type_hex + "\n" + "w\n"
    else:
        wok_log.error("No partitions found for disk,  %s", disk)
        raise OperationFailed("GINSP00017E", {"disk": "No partitions found for disk " + disk})

    t1_out = subprocess.Popen(["echo", "-e", "'", typ_str, "'"], stdout=subprocess.PIPE)
    t2_out = subprocess.Popen(["fdisk", dev_path], stdin=t1_out.stdout, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    t1_out.stdout.close()
    out, err = t2_out.communicate()

    if t2_out.returncode != 0:
        wok_log.error("Unable to change the partition type.")
        raise OperationFailed("change type failed", err)

    return part
예제 #4
0
파일: utils.py 프로젝트: LiftedKilt/ginger
def _makefs(fstype, name):
    """
    Formats the partition with the specified file system type
    :param fstype: type of filesystem (e.g ext3, ext4)
    :param name: name of the partition to be formatted (e.g sdb1)
    :return:
    """
    majmin = _get_dev_major_min(name)
    path = _get_dev_node_path(majmin)
    force_flag = '-F'
    if fstype == 'xfs':
        force_flag = '-f'
    fs_out, err, rc = run_command(["mkfs", "-t", fstype, force_flag, path])
    if rc != 0:
        raise OperationFailed("GINPART00012E", {'err': err})
    return
예제 #5
0
파일: utils.py 프로젝트: lcorreia/ginger
def _makefs(fstype, name):
    """
    Formats the partition with the specified file system type
    :param fstype: type of filesystem (e.g ext3, ext4)
    :param name: name of the partition to be formatted (e.g sdb1)
    :return:
    """
    majmin = _get_dev_major_min(name)
    path = _get_dev_node_path(majmin)
    force_flag = '-F'
    if fstype == 'xfs':
        force_flag = '-f'
    fs_out, err, rc = run_command(["mkfs", "-t", fstype, force_flag, path])
    if rc != 0:
        raise OperationFailed("GINPART00012E", {'err': err})
    return
예제 #6
0
파일: utils.py 프로젝트: lcorreia/ginger
def change_part_type(part, type_hex):
    """
    Change the type of the given partition
    :param part: partition number on the device
    :param type_hex: partition type in hex
    :return:
    """
    devname = ''.join(i for i in part if not i.isdigit())
    majmin = _get_dev_major_min(devname)

    dev_path = _get_dev_node_path(majmin)
    partnum = ''.join(filter(lambda x: x.isdigit(), part))

    device = PDevice(dev_path)
    disk = PDisk(device)
    parts = disk.partitions

    if len(parts) == 1:
        typ_str = '\nt\n' + type_hex + '\n' + 'w\n'
    elif len(parts) > 1:
        typ_str = '\nt\n' + partnum + '\n' + type_hex + '\n' + 'w\n'
    else:
        raise OperationFailed("GINSP00017E", {'disk': disk})

    t1_out = subprocess.Popen(["echo", "-e", "\'", typ_str, "\'"],
                              stdout=subprocess.PIPE)
    t2_out = subprocess.Popen(["fdisk", dev_path],
                              stdin=t1_out.stdout,
                              stderr=subprocess.PIPE,
                              stdout=subprocess.PIPE)
    t1_out.stdout.close()
    out, err = t2_out.communicate()

    if t2_out.returncode != 0:
        raise OperationFailed("GINSP00021E", {'err': err})

    return part
예제 #7
0
파일: utils.py 프로젝트: LiftedKilt/ginger
def change_part_type(part, type_hex):
    """
    Change the type of the given partition
    :param part: partition number on the device
    :param type_hex: partition type in hex
    :return:
    """
    devname = ''.join(i for i in part if not i.isdigit())
    majmin = _get_dev_major_min(devname)

    dev_path = _get_dev_node_path(majmin)
    partnum = ''.join(filter(lambda x: x.isdigit(), part))

    device = PDevice(dev_path)
    disk = PDisk(device)
    parts = disk.partitions

    if len(parts) == 1:
        typ_str = '\nt\n' + type_hex + '\n' + 'w\n'
    elif len(parts) > 1:
        typ_str = '\nt\n' + partnum + '\n' + type_hex + '\n' + 'w\n'
    else:
        raise OperationFailed("GINSP00017E", {'disk': disk})

    t1_out = subprocess.Popen(["echo", "-e", "\'", typ_str, "\'"],
                              stdout=subprocess.PIPE)
    t2_out = subprocess.Popen(["fdisk",
                               dev_path], stdin=t1_out.stdout,
                              stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    t1_out.stdout.close()
    out, err = t2_out.communicate()

    if t2_out.returncode != 0:
        raise OperationFailed("GINSP00021E", {'err': err})

    return part