Пример #1
0
def _is_dev_extended_partition(devType, devNodePath):
    if devType != 'part':
        return False

    if devNodePath.startswith('/dev/mapper'):
        try:
            dev_maj_min = _get_dev_major_min(devNodePath.split('/')[-1])
            parent_sys_path = '/sys/dev/block/' + dev_maj_min + '/slaves'
            parent_dm_name = os.listdir(parent_sys_path)[0]
            parent_maj_min = open(parent_sys_path + '/' + parent_dm_name +
                                  '/dev').readline().rstrip()
            diskPath = _get_dev_node_path(parent_maj_min)
        except Exception as e:
            wok_log.error('Error dealing with dev mapper device: ' +
                          devNodePath)
            raise OperationFailed('GGBDISK00001E', {'err': e.message})
    else:
        diskPath = devNodePath.rstrip('0123456789')

    device = PDevice(diskPath)
    try:
        extended_part = PDisk(device).getExtendedPartition()
    except NotImplementedError as e:
        wok_log.warning(
            'Error getting extended partition info for dev %s type %s: %s',
            devNodePath, devType, e.message)
        # Treate disk with unsupported partiton table as if it does not
        # contain extended partitions.
        return False
    if extended_part and extended_part.path == devNodePath:
        return True
    return False
Пример #2
0
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 _create_dasd_part(dev, size):
    """
    This method creates a DASD partition
    :param dev: name of DASD device for creation of partition
    :param size: block size
    :return:
    """
    devname = '/dev/' + dev
    device = PDevice(devname)
    disk = PDisk(device)
    num_parts = len(disk.partitions)
    if num_parts == 3:
        raise OperationFailed("GINDASDPAR0016E")

    def kill_proc(proc, timeout_flag):
        try:
            parent = psutil.Process(proc.pid)
            for child in parent.get_children(recursive=True):
                child.kill()
            # kill the process after no children is left
            proc.kill()
        except OSError:
            pass
        else:
            timeout_flag[0] = True

    dasd_devs = _get_dasd_names()
    if dev not in dasd_devs:
        raise NotFoundError("GINDASDPAR0012E", {'name': dev})
    p_str = _form_part_str(size)
    try:
        p1_out = subprocess.Popen(["echo", "-e", "\'", p_str, "\'"],
                                  stdout=subprocess.PIPE)
        p2_out = subprocess.Popen(["fdasd", devname],
                                  stdin=p1_out.stdout,
                                  stderr=subprocess.PIPE,
                                  stdout=subprocess.PIPE)
        p1_out.stdout.close()
        timeout = 2.0
        timeout_flag = [False]
        timer = Timer(timeout, kill_proc, [p2_out, timeout_flag])
        timer.setDaemon(True)
        timer.start()
        out, err = p2_out.communicate()
        if timeout_flag[0]:
            msg_args = {'cmd': "fdasd " + devname, 'seconds': str(timeout)}
            raise TimeoutExpired("WOKUTILS0002E", msg_args)
        if p2_out.returncode != 0:
            if 'error while rereading partition table' in err.lower():
                run_command(["partprobe", devname, "-s"])
            else:
                raise OperationFailed("GINDASDPAR0007E", {
                    'name': devname,
                    'err': err
                })
    except TimeoutExpired:
        raise
    finally:
        if timer and not timeout_flag[0]:
            timer.cancel()
Пример #4
0
def get_dev_part(dev):
    """
    This method fetches the path of newly created partition
    :param dev: path of the device which is partitioned
    :return:
    """
    part_paths = []
    device = PDevice(dev)
    disk = PDisk(device)
    parts = disk.partitions
    for part in parts:
        part_paths.append(part.path)
    return part_paths[len(part_paths) - 1]
Пример #5
0
def _is_dev_extended_partition(devType, devNodePath):
    if devType != 'part':
        return False
    diskPath = devNodePath.rstrip('0123456789')
    device = PDevice(diskPath)
    try:
        extended_part = PDisk(device).getExtendedPartition()
    except NotImplementedError as e:
        kimchi_log.warning(
            "Error getting extended partition info for dev %s type %s: %s",
            devNodePath, devType, e.message)
        # Treate disk with unsupported partiton table as if it does not
        # contain extended partitions.
        return False
    if extended_part and extended_part.path == devNodePath:
        return True
    return False
Пример #6
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:
        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