Michel Alexandre Salim 01f1db
#!/usr/bin/python3
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
import argparse
Michel Alexandre Salim 01f1db
import sys
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
import blivet
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
POOL_NAME = "blivet_test"
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
parser = argparse.ArgumentParser()
Michel Alexandre Salim 01f1db
parser.add_argument('-d', '--disks', default='')
Michel Alexandre Salim 01f1db
args = parser.parse_args()
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
b = blivet.Blivet()
Michel Alexandre Salim 01f1db
b.reset()
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
disks = list()
Michel Alexandre Salim 01f1db
for disk_id in args.disks.split(','):
Michel Alexandre Salim 01f1db
    disk = b.devicetree.resolve_device(disk_id)
Michel Alexandre Salim 01f1db
    if not disk.is_disk:
Michel Alexandre Salim 01f1db
        sys.stderr.write("specified disk '%s' is not a disk\n" % disk_id)
Michel Alexandre Salim 01f1db
        sys.exit(1)
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
    disks.append(disk)
Michel Alexandre Salim 01f1db
    b.initialize_disk(disk)
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
if len(disks) > 1:
Michel Alexandre Salim 01f1db
    container_raid_level = "raid1"
Michel Alexandre Salim 01f1db
    total_size = min(d.size for d in disks)
Michel Alexandre Salim 01f1db
else:
Michel Alexandre Salim 01f1db
    container_raid_level = None
Michel Alexandre Salim 01f1db
    total_size = sum(d.size for d in disks)
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
lv1 = b.factory_device(size=total_size*0.8, disks=disks,
Michel Alexandre Salim 01f1db
                       name="lv1", container_name=POOL_NAME,
Michel Alexandre Salim 01f1db
                       fstype='xfs', device_type=blivet.devicefactory.DEVICE_TYPE_LVM)
Michel Alexandre Salim 01f1db
lv2 = b.factory_device(disks=disks, name="lv2",
Michel Alexandre Salim 01f1db
                       container_name=POOL_NAME, container_raid_level='raid1',
Michel Alexandre Salim 01f1db
                       fstype='ext4', device_type=blivet.devicefactory.DEVICE_TYPE_LVM)
Michel Alexandre Salim 01f1db
Michel Alexandre Salim 01f1db
b.do_it()