def do_host_disk_partition_show(cc, args): """Show disk partition attributes.""" ihost = ihost_utils._find_ihost(cc, args.hostname_or_id) ipartition = part_utils._find_partition(cc, ihost, args.device_path_or_uuid) if not ipartition: raise exc.CommandError('Partition not found on host \'%s\' ' 'by device path or uuid: %s' % (ihost.hostname, args.device_path_or_uuid)) _print_partition_show(ipartition)
def do_host_disk_partition_modify(cc, args): """Modify the attributes of a Disk Partition.""" # Get all the fields from the command arguments field_list = ['size_gib'] integer_fields = ['size_gib'] user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in field_list and not (v is None)) if not user_specified_fields: raise exc.CommandError('No update parameters specified, ' 'partition is unchanged.') for f in user_specified_fields: try: if f in integer_fields: user_specified_fields[f] = int(user_specified_fields[f]) except ValueError: raise exc.CommandError('Partition size must be an integer ' 'greater than 0: %s' % user_specified_fields[f]) # Convert size from gib to mib user_specified_fields['size_mib'] = user_specified_fields.pop('size_gib') * 1024 # Get the ihost object ihost = ihost_utils._find_ihost(cc, args.hostname_or_id) # Get the partition partition = part_utils._find_partition(cc, ihost, args.partition_path_or_uuid) if not partition: raise exc.CommandError('Partition not found on host \'%s\' ' 'by device path or uuid: %s' % (ihost.hostname, args.partition_path_or_uuid)) patch = [] for (k, v) in user_specified_fields.items(): patch.append({'op': 'replace', 'path': '/' + k, 'value': v}) # Update the partition attributes try: updated_partition = cc.partition.update(partition.uuid, patch) except exc.HTTPNotFound: raise exc.CommandError( "ERROR: Partition update failed: " "host %s partition %s : update %s" % (args.hostname_or_id, args.partition_path_or_uuid, patch)) _print_partition_show(updated_partition)
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)
def do_host_disk_partition_delete(cc, args): """Delete a disk partition.""" # Get the ihost object ihost = ihost_utils._find_ihost(cc, args.hostname_or_id) partition = part_utils._find_partition(cc, ihost, args.partition_path_or_uuid) if not partition: raise exc.CommandError('Partition not found on host \'%s\' ' 'by device path or uuid: %s' % (ihost.hostname, args.partition_path_or_uuid)) try: cc.partition.delete(partition.uuid) except exc.HTTPNotFound: raise exc.CommandError('Partition delete failed: host %s: ' 'partition %s' % (args.hostnameorid, args.partition_path_or_uuid))