def do_host_disk_partition_add(cc, args):
    """Add a disk partition to a disk of a specified host."""

    field_list = ['size_gib', 'partition_type']
    integer_fields = ['size_gib']

    user_fields = dict((k, v) for (k, v) in vars(args).items()
                       if k in field_list and not (v is None))

    for f in user_fields:
        try:
            if f in integer_fields:
                user_fields[f] = int(user_fields[f])
        except ValueError:
            raise exc.CommandError('Partition size must be an integer '
                                   'greater than 0: %s' % user_fields[f])

    # Convert size from gib to mib
    user_fields['size_mib'] = user_fields.pop('size_gib') * 1024

    # Get the ihost object
    ihost = ihost_utils._find_ihost(cc, args.hostname_or_id)
    idisk = idisk_utils._find_disk(cc, ihost, args.disk_path_or_uuid)

    if not idisk:
        raise exc.CommandError('Disk not found: %s' % args.disk_path_or_uuid)

    # default values
    fields = {'ihost_uuid': ihost.uuid,
              'idisk_uuid': idisk.uuid,
              'size_mib': 0}

    fields.update(user_fields)

    # Set the requested partition GUID
    fields['type_guid'] = PARTITION_MAP[fields['partition_type']]
    fields.pop('partition_type', None)

    if not fields['size_mib']:
        raise exc.CommandError('Partition size must be greater than 0.')

    try:
        partition = cc.partition.create(**fields)
    except exc.HTTPNotFound:
        raise exc.CommandError('Partition create failed: host %s: fields %s' %
                               (args.hostnameorid, fields))

    puuid = getattr(partition, 'uuid', '')
    try:
        ipartition = cc.partition.get(puuid)
    except exc.HTTPNotFound:
        raise exc.CommandError('Created Partition UUID not found: %s' % puuid)

    _print_partition_show(ipartition)
Example #2
0
def do_host_pv_add(cc, args):
    """Add a Physical Volume."""

    field_list = ['disk_or_part_uuid']

    ihost = ihost_utils._find_ihost(cc, args.hostnameorid)
    ilvg = ilvg_utils._find_ilvg(cc, ihost, args.lvgname)

    fields = {}
    user_specified_fields = dict((k, v) for (k, v) in vars(args).items()
                                 if k in field_list and not (v is None))
    fields.update(user_specified_fields)

    fields['ihost_uuid'] = ihost.uuid
    fields['ilvg_uuid'] = ilvg.uuid

    idisk = idisk_utils._find_disk(cc, ihost,
                                   args.device_name_path_uuid)
    if idisk:
        fields['disk_or_part_uuid'] = idisk.uuid
        fields['pv_type'] = 'disk'
    else:
        partition = partition_utils._find_partition(cc, ihost,
                                                    args.device_name_path_uuid)
        if partition:
            fields['disk_or_part_uuid'] = partition.uuid
            fields['pv_type'] = 'partition'

    if not idisk and not partition:
        raise exc.CommandError("No disk or partition found on host \'%s\' "
                               "by device path or uuid %s" %
                               (ihost.hostname, args.device_name_path_uuid))

    try:
        ipv = cc.ipv.create(**fields)
    except exc.HTTPNotFound:
        raise exc.CommandError("Physical volume creation failed: host %s: "
                               "fields %s" % (args.hostnameorid, fields))

    suuid = getattr(ipv, 'uuid', '')
    try:
        ipv = cc.ipv.get(suuid)
    except exc.HTTPNotFound:
        raise exc.CommandError("Created physical volume UUID not found: "
                               "%s" % suuid)

    _print_ipv_show(ipv)
Example #3
0
def do_host_disk_partition_list(cc, args):
    """List disk partitions."""
    ihost = ihost_utils._find_ihost(cc, args.hostname_or_id)
    if args.disk:
        idisk = idisk_utils._find_disk(cc, args.hostname_or_id, args.disk)
 
        if not idisk:
            raise exc.CommandError('Disk not found: %s' % args.disk)
 
        ipartitions = cc.partition.list(ihost.uuid, idisk.uuid)
    else:
        ipartitions = cc.partition.list(ihost.uuid, None)

    for p in ipartitions:
        p.status = constants.PARTITION_STATUS_MSG[p.status]

    field_labels = ['uuid', 'device_path', 'device_node', 'type_guid',
                    'type_name', 'size_mib', 'status']
    fields = ['uuid', 'device_path', 'device_node', 'type_guid', 'type_name',
              'size_mib', 'status']

    utils.print_list(ipartitions, fields, field_labels, sortby=1)