def info(dev):
    result = utils.execute('parted', '-s', dev, '-m',
                           'unit', 'MiB',
                           'print', 'free',
                           check_exit_code=[0, 1])
    lines = result[0].split('\n')
    generic_params = lines[1].rstrip(';').split(':')
    generic = {
        'dev': generic_params[0],
        'size': utils.parse_unit(generic_params[1], 'MiB'),
        'logical_block': int(generic_params[3]),
        'physical_block': int(generic_params[4]),
        'table': generic_params[5],
        'model': generic_params[6]
    }
    parts = []
    for line in lines[2:]:
        line = line.strip().rstrip(';')
        if not line:
            continue
        part_params = line.split(':')
        parts.append({
            'num': int(part_params[0]),
            'begin': utils.parse_unit(part_params[1], 'MiB'),
            'end': utils.parse_unit(part_params[2], 'MiB'),
            'size': utils.parse_unit(part_params[3], 'MiB'),
            'fstype': part_params[4] or None
        })
    return {'generic': generic, 'parts': parts}
Exemple #2
0
def parse_partition_info(output):
    lines = output.split('\n')
    generic_params = lines[1].rstrip(';').split(':')
    generic = {
        'dev': generic_params[0],
        'size': utils.parse_unit(generic_params[1], 'MiB'),
        'logical_block': int(generic_params[3]),
        'physical_block': int(generic_params[4]),
        'table': generic_params[5],
        'model': generic_params[6]
    }
    parts = []
    for line in lines[2:]:
        line = line.strip().rstrip(';')
        if not line:
            continue
        part_params = line.split(':')
        parts.append({
            'num': int(part_params[0]),
            'begin': utils.parse_unit(part_params[1], 'MiB'),
            'end': utils.parse_unit(part_params[2], 'MiB'),
            'size': utils.parse_unit(part_params[3], 'MiB'),
            'fstype': part_params[4] or None
        })
    return {'generic': generic, 'parts': parts}
Exemple #3
0
def parse_partition_info(output):
    lines = output.split("\n")
    generic_params = lines[1].rstrip(";").split(":")
    generic = {
        "dev": generic_params[0],
        "size": utils.parse_unit(generic_params[1], "MiB"),
        "logical_block": int(generic_params[3]),
        "physical_block": int(generic_params[4]),
        "table": generic_params[5],
        "model": generic_params[6],
    }
    parts = []
    for line in lines[2:]:
        line = line.strip().rstrip(";")
        if not line:
            continue
        part_params = line.split(":")
        parts.append(
            {
                "num": int(part_params[0]),
                "begin": utils.parse_unit(part_params[1], "MiB"),
                "end": utils.parse_unit(part_params[2], "MiB"),
                "size": utils.parse_unit(part_params[3], "MiB"),
                "fstype": part_params[4] or None,
            }
        )
    return {"generic": generic, "parts": parts}
Exemple #4
0
def pvdisplay():
    # unit m means MiB (power of 2)
    result = utils.execute('pvdisplay',
                           '-C',
                           '--noheading',
                           '--units',
                           'm',
                           '--options',
                           'pv_name,vg_name,pv_size,dev_size,pv_uuid',
                           '--separator',
                           ';',
                           check_exit_code=[0])
    pvs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        pv_params = line.split(';')
        pvs.append({
            'name': pv_params[0],
            'vg': pv_params[1] or None,
            'psize': utils.parse_unit(pv_params[2], 'm'),
            'devsize': utils.parse_unit(pv_params[3], 'm'),
            'uuid': pv_params[4]
        })
    LOG.debug('Found physical volumes: {0}'.format(pvs))
    return pvs
Exemple #5
0
def vgdisplay():
    result = utils.execute('vgdisplay',
                           '-C',
                           '--noheading',
                           '--units',
                           'm',
                           '--options',
                           'vg_name,vg_uuid,vg_size,vg_free',
                           '--separator',
                           ';',
                           check_exit_code=[0])

    vgs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        vg_params = line.split(';')
        vgs.append({
            'name': vg_params[0],
            'uuid': vg_params[1],
            'size': utils.parse_unit(vg_params[2], 'm'),
            'free': utils.parse_unit(vg_params[3], 'm', ceil=False)
        })
    LOG.debug('Found volume groups: {0}'.format(vgs))
    return vgs
Exemple #6
0
def pvdisplay():
    # unit m means MiB (power of 2)
    result = utils.execute(
        'pvdisplay',
        '-C',
        '--noheading',
        '--units', 'm',
        '--options', 'pv_name,vg_name,pv_size,dev_size,pv_uuid',
        '--separator', ';',
        check_exit_code=[0])
    pvs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        pv_params = line.split(';')
        pvs.append({
            'name': pv_params[0],
            'vg': pv_params[1] or None,
            'psize': utils.parse_unit(pv_params[2], 'm'),
            'devsize': utils.parse_unit(pv_params[3], 'm'),
            'uuid': pv_params[4]
        })
    LOG.debug('Found physical volumes: {0}'.format(pvs))
    return pvs
Exemple #7
0
def parse_partition_info(output):
    lines = output.split('\n')
    generic_params = lines[1].rstrip(';').split(':')
    generic = {
        'dev': generic_params[0],
        'size': utils.parse_unit(generic_params[1], 'MiB'),
        'logical_block': int(generic_params[3]),
        'physical_block': int(generic_params[4]),
        'table': generic_params[5],
        'model': generic_params[6]
    }
    parts = []
    for line in lines[2:]:
        line = line.strip().rstrip(';')
        if not line:
            continue
        part_params = line.split(':')
        parts.append({
            'num': int(part_params[0]),
            'begin': utils.parse_unit(part_params[1], 'MiB'),
            'end': utils.parse_unit(part_params[2], 'MiB'),
            'size': utils.parse_unit(part_params[3], 'MiB'),
            'fstype': part_params[4] or None
        })
    return {'generic': generic, 'parts': parts}
Exemple #8
0
def vgdisplay_parse(output):
    vgs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        vg_params = line.split(';')
        vgs.append({
            'name': vg_params[0],
            'uuid': vg_params[1],
            'size': utils.parse_unit(vg_params[2], 'm'),
            'free': utils.parse_unit(vg_params[3], 'm', ceil=False)
        })
    LOG.debug('Found volume groups: {0}'.format(vgs))
    return vgs
Exemple #9
0
def vgdisplay_parse(output):
    vgs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        vg_params = line.split(';')
        vgs.append({
            'name': vg_params[0],
            'uuid': vg_params[1],
            'size': utils.parse_unit(vg_params[2], 'm'),
            'free': utils.parse_unit(vg_params[3], 'm', ceil=False)
        })
    LOG.debug('Found volume groups: {0}'.format(vgs))
    return vgs
Exemple #10
0
def pvdisplay_parse(output):
    pvs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        pv_params = line.split(';')
        pvs.append({
            'name': pv_params[0],
            'vg': pv_params[1] or None,
            'psize': utils.parse_unit(pv_params[2], 'm'),
            'devsize': utils.parse_unit(pv_params[3], 'm'),
            'uuid': pv_params[4]
        })
    LOG.debug('Found physical volumes: {0}'.format(pvs))
    return pvs
Exemple #11
0
def lvdisplay():
    result = utils.execute(
        'lvdisplay',
        '-C',
        '--noheading',
        '--units', 'm',
        '--options', 'lv_name,lv_size,vg_name,lv_uuid,lv_path',
        '--separator', ';',
        check_exit_code=[0])

    lvs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        lv_params = line.split(';')
        lvs.append({
            'name': lv_params[0],
            'size': utils.parse_unit(lv_params[1], 'm'),
            'vg': lv_params[2],
            'uuid': lv_params[3],
            'path': lv_params[4]
        })
    LOG.debug('Found logical volumes: {0}'.format(lvs))
    return lvs
Exemple #12
0
def lvdisplay():
    result = utils.execute(
        'lvdisplay',
        '-C',
        '--noheading',
        '--units', 'm',
        #NOTE(agordeev): lv_path had been removed from options
        # since versions of lvdisplay prior 2.02.68 don't have it.
        '--options', 'lv_name,lv_size,vg_name,lv_uuid',
        '--separator', ';',
        check_exit_code=[0])

    lvs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        lv_params = line.split(';')
        lvs.append({
            'name': lv_params[0],
            'size': utils.parse_unit(lv_params[1], 'm'),
            'vg': lv_params[2],
            'uuid': lv_params[3],
            #NOTE(agordeev): simulate lv_path with '/dev/$vg_name/$lv_name'
            'path': '/dev/%s/%s' % (lv_params[2], lv_params[0])
        })
    LOG.debug('Found logical volumes: {0}'.format(lvs))
    return lvs
Exemple #13
0
def pvdisplay_parse(output):
    pvs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        pv_params = line.split(';')
        pvs.append({
            'name': pv_params[0],
            'vg': pv_params[1] or None,
            'psize': utils.parse_unit(pv_params[2], 'm'),
            'devsize': utils.parse_unit(pv_params[3], 'm'),
            'uuid': pv_params[4]
        })
    LOG.debug('Found physical volumes: {0}'.format(pvs))
    return pvs
Exemple #14
0
def lvdisplay():
    result = utils.execute(
        'lvdisplay',
        '-C',
        '--noheading',
        '--units',
        'm',
        #NOTE(agordeev): lv_path had been removed from options
        # since versions of lvdisplay prior 2.02.68 don't have it.
        '--options',
        'lv_name,lv_size,vg_name,lv_uuid',
        '--separator',
        ';',
        check_exit_code=[0])

    lvs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        lv_params = line.split(';')
        lvs.append({
            'name': lv_params[0],
            'size': utils.parse_unit(lv_params[1], 'm'),
            'vg': lv_params[2],
            'uuid': lv_params[3],
            #NOTE(agordeev): simulate lv_path with '/dev/$vg_name/$lv_name'
            'path': '/dev/%s/%s' % (lv_params[2], lv_params[0])
        })
    LOG.debug('Found logical volumes: {0}'.format(lvs))
    return lvs
Exemple #15
0
 def test_parse_unit(self):
     self.assertEqual(utils.parse_unit('1.00m', 'm', ceil=True), 1)
     self.assertEqual(utils.parse_unit('1.00m', 'm', ceil=False), 1)
     self.assertEqual(utils.parse_unit('1.49m', 'm', ceil=True), 2)
     self.assertEqual(utils.parse_unit('1.49m', 'm', ceil=False), 1)
     self.assertEqual(utils.parse_unit('1.51m', 'm', ceil=True), 2)
     self.assertEqual(utils.parse_unit('1.51m', 'm', ceil=False), 1)
     self.assertRaises(ValueError, utils.parse_unit, '1.00m', 'MiB')
     self.assertRaises(ValueError, utils.parse_unit, '', 'MiB')
Exemple #16
0
 def test_parse_unit(self):
     self.assertEqual(utils.parse_unit("1.00m", "m", ceil=True), 1)
     self.assertEqual(utils.parse_unit("1.00m", "m", ceil=False), 1)
     self.assertEqual(utils.parse_unit("1.49m", "m", ceil=True), 2)
     self.assertEqual(utils.parse_unit("1.49m", "m", ceil=False), 1)
     self.assertEqual(utils.parse_unit("1.51m", "m", ceil=True), 2)
     self.assertEqual(utils.parse_unit("1.51m", "m", ceil=False), 1)
     self.assertRaises(ValueError, utils.parse_unit, "1.00m", "MiB")
     self.assertRaises(ValueError, utils.parse_unit, "", "MiB")
Exemple #17
0
 def test_parse_unit(self):
     self.assertEqual(utils.parse_unit('1.00m', 'm', ceil=True), 1)
     self.assertEqual(utils.parse_unit('1.00m', 'm', ceil=False), 1)
     self.assertEqual(utils.parse_unit('1.49m', 'm', ceil=True), 2)
     self.assertEqual(utils.parse_unit('1.49m', 'm', ceil=False), 1)
     self.assertEqual(utils.parse_unit('1.51m', 'm', ceil=True), 2)
     self.assertEqual(utils.parse_unit('1.51m', 'm', ceil=False), 1)
     self.assertRaises(ValueError, utils.parse_unit, '1.00m', 'MiB')
     self.assertRaises(ValueError, utils.parse_unit, '', 'MiB')
Exemple #18
0
def vgdisplay():
    result = utils.execute(
        'vgdisplay',
        '-C',
        '--noheading',
        '--units', 'm',
        '--options', 'vg_name,vg_uuid,vg_size,vg_free',
        '--separator', ';',
        check_exit_code=[0])

    vgs = []
    for line in result[0].split('\n'):
        line = line.strip()
        if not line:
            continue
        vg_params = line.split(';')
        vgs.append({
            'name': vg_params[0],
            'uuid': vg_params[1],
            'size': utils.parse_unit(vg_params[2], 'm'),
            'free': utils.parse_unit(vg_params[3], 'm', ceil=False)
        })
    LOG.debug('Found volume groups: {0}'.format(vgs))
    return vgs
Exemple #19
0
def lvdisplay_parse(output):
    lvs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        lv_params = line.split(';')
        lvs.append({
            'name': lv_params[0],
            'size': utils.parse_unit(lv_params[1], 'm'),
            'vg': lv_params[2],
            'uuid': lv_params[3],
            # NOTE(agordeev): simulate lv_path with '/dev/$vg_name/$lv_name'
            'path': '/dev/%s/%s' % (lv_params[2], lv_params[0])
        })
    LOG.debug('Found logical volumes: {0}'.format(lvs))
    return lvs
Exemple #20
0
def lvdisplay_parse(output):
    lvs = []
    for line in output.split('\n'):
        line = line.strip()
        if not line:
            continue
        lv_params = line.split(';')
        lvs.append({
            'name': lv_params[0],
            'size': utils.parse_unit(lv_params[1], 'm'),
            'vg': lv_params[2],
            'uuid': lv_params[3],
            #NOTE(agordeev): simulate lv_path with '/dev/$vg_name/$lv_name'
            'path': '/dev/%s/%s' % (lv_params[2], lv_params[0])
        })
    LOG.debug('Found logical volumes: {0}'.format(lvs))
    return lvs