def do_host_label_list(cc, args): """List kubernetes labels assigned to a host.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) host_label = cc.label.list(ihost.uuid) for i in host_label[:]: setattr(i, 'hostname', ihost.hostname) field_labels = ['hostname', 'label key', 'label value'] fields = ['hostname', 'label_key', 'label_value'] utils.print_list(host_label, fields, field_labels, sortby=1)
def do_host_update(cc, args): """Update host attributes.""" patch = utils.args_array_to_patch("replace", args.attributes[0]) ihost = ihost_utils._find_ihost(cc, args.hostnameorid) try: ihost = cc.ihost.update(ihost.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_ihost_show(ihost)
def do_host_node_list(cc, args): """List nodes.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) inodes = cc.inode.list(ihost.uuid) field_labels = ['uuid', 'numa_node', 'capabilities'] fields = ['uuid', 'numa_node', 'capabilities'] utils.print_list(inodes, fields, field_labels, sortby=0)
def do_host_disk_show(cc, args): """Show disk attributes.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) idisk = _find_disk(cc, ihost, args.device_nodeoruuid) # Convert size from mib to gib and round it down idisk.size_mib = math.floor(float(idisk.size_mib) / 1024 * 1000) / 1000.0 idisk.available_mib = math.floor(float(idisk.available_mib) / 1024 * 1000) / 1000.0 _print_idisk_show(idisk)
def do_host_stor_add(cc, args): """Add a storage to a host.""" field_list = [ 'function', 'idisk_uuid', 'journal_location', 'journal_size', 'tier_uuid' ] integer_fields = ['journal_size'] user_specified_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_specified_fields: try: if f in integer_fields: user_specified_fields[f] = int(user_specified_fields[f]) except ValueError: raise exc.CommandError('Journal size must be an integer ' 'greater than 0: %s' % user_specified_fields[f]) if 'journal_size' in user_specified_fields.keys(): user_specified_fields['journal_size_mib'] = \ user_specified_fields.pop('journal_size') * 1024 if 'function' in user_specified_fields.keys(): user_specified_fields['function'] = \ user_specified_fields['function'].replace(" ", "") if 'tier_uuid' in user_specified_fields.keys(): user_specified_fields['tier_uuid'] = \ user_specified_fields['tier_uuid'].replace(" ", "") # default values, name comes from 'osd add' fields = {'function': 'osd'} fields.update(user_specified_fields) ihost = ihost_utils._find_ihost(cc, args.hostnameorid) try: fields['ihost_uuid'] = ihost.uuid istor = cc.istor.create(**fields) except exc.HTTPNotFound: raise exc.CommandError('Stor create failed: host %s: fields %s' % (args.hostnameorid, fields)) suuid = getattr(istor, 'uuid', '') try: istor = cc.istor.get(suuid) except exc.HTTPNotFound: raise exc.CommandError('Created Stor UUID not found: %s' % suuid) # istor_utils._get_disks(cc, ihost, istor) _print_istor_show(istor)
def do_host_power_off(cc, args): """Power off a host.""" attributes = [] attributes.append('action=power-off') patch = utils.args_array_to_patch("replace", attributes) ihost = ihost_utils._find_ihost(cc, args.hostnameorid) try: ihost = cc.ihost.update(ihost.id, patch) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % args.hostnameorid) _print_ihost_show(ihost)
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_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)
def do_host_cpu_modify(cc, args): """Modify cpu core assignments.""" field_list = [ 'function', 'allocated_function', 'cpulist', 'num_cores_on_processor0', 'num_cores_on_processor1', 'num_cores_on_processor2', 'num_cores_on_processor3' ] capabilities = [] sockets = [] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in field_list and not (v is None)) cap = {'function': user_specified_fields.get('function')} cpulist = user_specified_fields.get('cpulist') if cpulist: cap['cpulist'] = cpulist for k, v in user_specified_fields.items(): if k.startswith('num_cores_on_processor'): sockets.append({k.lstrip('num_cores_on_processor'): v}) # can't specify both the -c option and any of the -pX options if sockets and cpulist: raise exc.CommandError( 'Not allowed to specify both -c and -pX options.') if sockets: cap.update({'sockets': sockets}) elif not cpulist: raise exc.CommandError('Number of cores on Processor (Socket) ' 'not provided.') capabilities.append(cap) icpus = cc.ihost.host_cpus_modify(ihost.uuid, capabilities) field_labels = [ 'uuid', 'log_core', 'processor', 'phy_core', 'thread', 'processor_model', 'assigned_function' ] fields = [ 'uuid', 'cpu', 'numa_node', 'core', 'thread', 'cpu_model', 'allocated_function' ] utils.print_list(icpus, fields, field_labels, sortby=1, formatters={ 'allocated_function': icpu_utils._cpu_function_tuple_formatter })
def do_host_label_assign(cc, args): """Update the Kubernetes labels on a host.""" attributes = utils.extract_keypairs(args) ihost = ihost_utils._find_ihost(cc, args.hostnameorid) new_labels = cc.label.assign(ihost.uuid, attributes) for p in new_labels.labels: uuid = p['uuid'] if uuid is not None: try: label_obj = cc.label.get(uuid) except exc.HTTPNotFound: raise exc.CommandError('Host label not found: %s' % uuid) _print_label_show(label_obj)
def do_host_fs_delete(cc, args): """Delete a host filesystem.""" # Get the ihost object ihost = ihost_utils._find_ihost(cc, args.hostnameorid) host_fs = fs_utils._find_fs(cc, ihost, args.name) try: cc.host_fs.delete(host_fs.uuid) except exc.HTTPNotFound: raise exc.CommandError('Filesystem delete failed: host %s: ' 'name %s' % (args.hostnameorid, args.name))
def do_host_lvg_delete(cc, args): """Delete a Local Volume Group.""" # Get the ihost object ihost = ihost_utils._find_ihost(cc, args.hostnameorid) ilvg = ilvg_utils._find_ilvg(cc, ihost, args.lvm_vg_name) try: cc.ilvg.delete(ilvg.uuid) except exc.HTTPNotFound: raise exc.CommandError('Local Volume Group delete failed: host %s: ' 'lvg %s' % (args.hostnameorid, args.lvm_vg_name))
def do_host_ethernet_port_list(cc, args): """List host ethernet ports.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) ports = cc.ethernet_port.list(ihost.uuid) for p in ports: p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB field_labels = ['uuid', 'name', 'mac address', 'pci address', 'processor', 'auto neg', 'device type', 'boot i/f'] fields = ['uuid', 'name', 'mac', 'pciaddr', 'numa_node', 'autoneg', 'pdevice', 'bootp'] utils.print_list(ports, fields, field_labels, sortby=1, formatters={'bootp': _bootp_port_formatter})
def do_host_apply_storprofile(cc, args): """Apply a storage profile to a host.""" # Assemble patch profile = iprofile_utils._find_iprofile(cc, args.profilenameoruuid) patch = _prepare_profile_patch(profile.uuid) host = ihost_utils._find_ihost(cc, args.hostnameorid) try: host = cc.ihost.update(host.id, patch) except exc.HTTPNotFound: raise exc.CommandError('Host not found: %s' % args.hostnameorid) _list_storage(cc, host)
def do_host_lvg_modify(cc, args): """Modify the attributes of a Local Volume Group.""" # Get all the fields from the command arguments field_list = [ 'hostnameorid', 'lvgnameoruuid', 'instance_backing', 'concurrent_disk_operations', 'lvm_type' ] fields = dict((k, v) for (k, v) in vars(args).items() if k in field_list and not (v is None)) all_caps_list = [ 'instance_backing', 'concurrent_disk_operations', 'lvm_type' ] integer_fields = ['concurrent_disk_operations'] requested_caps_dict = {} for cap in all_caps_list: if cap in fields: try: if cap in integer_fields: requested_caps_dict[cap] = int(fields[cap]) else: requested_caps_dict[cap] = fields[cap] except ValueError: raise exc.CommandError('{0} value {1} is invalid'.format( cap, fields[cap])) # Get the ihost object ihost = ihost_utils._find_ihost(cc, args.hostnameorid) # Get the volume group lvg = ilvg_utils._find_ilvg(cc, ihost, args.lvgnameoruuid) # format the arguments patch = [] patch.append({ 'path': '/capabilities', 'value': jsonutils.dumps(requested_caps_dict), 'op': 'replace' }) # Update the volume group attributes try: ilvg = cc.ilvg.update(lvg.uuid, patch) except exc.HTTPNotFound: raise exc.CommandError("ERROR: Local Volume Group update failed: " "host %s volume group %s : update %s" % (args.hostnameorid, args.lvgnameoruuid, patch)) _print_ilvg_show(ilvg)
def do_host_device_label_list(cc, args): """List device labels""" host = ihost_utils._find_ihost(cc, args.hostnameorid) device = pci_device.find_device(cc, host, args.nameorpciaddr) device_labels = cc.device_label.list() for dl in device_labels[:]: if dl.pcidevice_uuid != device.uuid: device_labels.remove(dl) else: setattr(dl, 'hostname', host.hostname) setattr(dl, 'devicename', device.name) field_labels = ['hostname', 'PCI device name', 'label key', 'label value'] fields = ['hostname', 'devicename', 'label_key', 'label_value'] utils.print_list(device_labels, fields, field_labels, sortby=1)
def do_host_memory_show(cc, args): """Show memory attributes.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) inodes = cc.inode.list(ihost.uuid) imemorys = cc.imemory.list(ihost.uuid) for m in imemorys: for n in inodes: if m.inode_uuid == n.uuid: if int(n.numa_node) == int(args.numa_node): _print_imemory_show(m) return else: raise exc.CommandError('Processor not found: host %s processor %s' % (ihost.hostname, args.numa_node))
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_if_modify(cc, args): """Modify interface attributes.""" rwfields = [ 'iftype', 'ifname', 'imtu', 'aemode', 'txhashpolicy', 'datanetworks', 'providernetworks', 'ports', 'ifclass', 'networks', 'ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool', 'sriov_numvfs' ] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in rwfields and not (v is None)) if 'providernetworks' in user_specified_fields.keys(): user_specified_fields['datanetworks'] = \ user_specified_fields['providernetworks'] del user_specified_fields['providernetworks'] elif 'datanetworks' in user_specified_fields.keys(): user_specified_fields['datanetworks'] = \ user_specified_fields['datanetworks'] interface = _find_interface(cc, ihost, args.ifnameoruuid) fields = interface.__dict__ fields.update(user_specified_fields) if 'networks' in user_specified_fields.keys(): network = network_utils._find_network(cc, args.networks) user_specified_fields['networks'] = str(network.id) # Allow setting an interface back to a None type if 'ifclass' in user_specified_fields.keys(): if args.ifclass == 'none': iinterface_utils._get_ports(cc, ihost, interface) if interface.ports or interface.uses: if interface.iftype != 'ae' and interface.iftype != 'vlan': for p in interface.ports: user_specified_fields['ifname'] = p break if interface.ifclass == 'data': user_specified_fields['datanetworks'] = 'none' patch = [] for (k, v) in user_specified_fields.items(): patch.append({'op': 'replace', 'path': '/' + k, 'value': v}) iinterface = cc.iinterface.update(interface.uuid, patch) iinterface_utils._get_ports(cc, ihost, iinterface) _print_iinterface_show(cc, iinterface)
def do_host_sensorgroup_relearn(cc, args): """Relearn sensor model.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) isensorgroups = cc.isensorgroup.relearn(ihost.uuid) print("%s sensor model and any related alarm assertions are being " "deleted." % (args.hostnameorid)) print("Any sensor suppression settings at the group or sensor levels " "will be lost.") print("Will attempt to preserve customized group actions and monitor " "interval when the model is relearned on next audit interval.") print("The learning process may take several minutes. Please stand-by.")
def do_host_memory_modify(cc, args): """Modify platform reserved and/or libvirt vm huge page memory attributes for compute nodes.""" rwfields = [ 'platform_reserved_mib', 'vm_hugepages_nr_2M_pending', 'vm_hugepages_nr_1G_pending' ] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in rwfields and not (v is None)) ihost = ihost_utils._find_ihost(cc, args.hostnameorid) inodes = cc.inode.list(ihost.uuid) imemorys = cc.imemory.list(ihost.uuid) mem = None for m in imemorys: for n in inodes: if m.inode_uuid == n.uuid: if int(n.numa_node) == int(args.numa_node): mem = m break if mem: break if mem is None: raise exc.CommandError('Processor not found: host %s processor %s' % (ihost.hostname, args.numa_node)) patch = [] for (k, v) in user_specified_fields.items(): patch.append({'op': 'replace', 'path': '/' + k, 'value': v}) if patch: imemory = cc.imemory.update(mem.uuid, patch) _print_imemory_show(imemory)
def do_host_lldp_agent_list(cc, args): """List host lldp agents.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) agents = cc.lldp_agent.list(ihost.uuid) field_labels = ['uuid', 'local_port', 'status', 'chassis_id', 'port_id', 'system_name', 'system_description'] fields = ['uuid', 'port_name', 'status', 'chassis_id', 'port_identifier', 'system_name', 'system_description'] formatters = {'system_name': _lldp_system_name_formatter, 'system_description': _lldp_system_description_formatter, 'port_description': _lldp_port_description_formatter} utils.print_list(agents, fields, field_labels, sortby=1, formatters=formatters)
def do_host_if_add(cc, args): """Add an interface.""" field_list = [ 'ifname', 'iftype', 'imtu', 'ifclass', 'networks', 'aemode', 'txhashpolicy', 'datanetworks', 'vlan_id', 'ipv4_mode', 'ipv6_mode', 'ipv4_pool', 'ipv6_pool' ] ihost = ihost_utils._find_ihost(cc, args.hostnameorid) user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in field_list and not (v is None)) if 'iftype' in user_specified_fields.keys(): if args.iftype == 'ae' or args.iftype == 'vlan': uses = args.portsorifaces portnamesoruuids = None elif args.iftype == 'virtual': uses = None portnamesoruuids = [] else: uses = None portnamesoruuids = ','.join(args.portsorifaces) user_specified_fields = dict((k, v) for (k, v) in vars(args).items() if k in field_list and not (v is None)) if 'datanetworks' in user_specified_fields.keys(): user_specified_fields['datanetworks'] = \ user_specified_fields['datanetworks'].split(',') if 'networks' in user_specified_fields.keys(): network = network_utils._find_network(cc, args.networks) user_specified_fields['networks'] = [str(network.id)] user_specified_fields['ihost_uuid'] = ihost.uuid user_specified_fields['ports'] = portnamesoruuids user_specified_fields['uses'] = uses iinterface = cc.iinterface.create(**user_specified_fields) suuid = getattr(iinterface, 'uuid', '') try: iinterface = cc.iinterface.get(suuid) except exc.HTTPNotFound: raise exc.CommandError('Created Interface UUID not found: %s' % suuid) iinterface_utils._get_ports(cc, ihost, iinterface) _print_iinterface_show(cc, iinterface)
def do_device_label_list(cc, args): """List all device labels""" device_labels = cc.device_label.list() for dl in device_labels[:]: if dl.pcidevice_uuid is None: setattr(dl, 'devicename', "") setattr(dl, 'hostname', "") else: pci_device = cc.pci_device.get(dl.pcidevice_uuid) setattr(dl, 'devicename', getattr(pci_device, 'name')) host = ihost_utils._find_ihost(cc, getattr(pci_device, 'host_uuid')) setattr(dl, 'hostname', host.hostname) field_labels = ['hostname', 'PCI device name', 'label key', 'label value'] fields = ['hostname', 'devicename', 'label_key', 'label_value'] utils.print_list(device_labels, fields, field_labels, sortby=1)
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_list(cc, args): """List disks.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) idisks = cc.idisk.list(ihost.uuid) field_labels = [ 'uuid', 'device_node', 'device_num', 'device_type', 'size_mib', 'available_mib', 'rpm', 'serial_id', 'device_path' ] fields = [ 'uuid', 'device_node', 'device_num', 'device_type', 'size_mib', 'available_mib', 'rpm', 'serial_id', 'device_path' ] utils.print_list(idisks, fields, field_labels, sortby=1)
def do_host_node_delete(cc, args): """Delete a node.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) i = _find_node(cc, ihost, args.inodeuuid) # The following semantic checks should be in REST or DB API # if ihost.administrative != 'locked': # raise exc.CommandError('Host must be locked.') # do no allow delete if cpu members try: cc.inode.delete(i.uuid) except exc.HTTPNotFound: raise exc.CommandError('Delete node failed: host %s if %s' % (args.hostnameorid, args.inodeuuid)) print('Deleted node: host %s if %s' % (args.hostnameorid, args.inodeuuid))
def do_host_sensorgroup_modify(cc, args): """Modify sensor group of a host.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) sensorgroup = _find_sensorgroup(cc, ihost, args.sensorgroup_uuid) patch = utils.args_array_to_patch("replace", args.attributes[0]) try: isensorgroup = cc.isensorgroup.update(sensorgroup.uuid, patch) except exc.HTTPNotFound: raise exc.CommandError( "Sensor update failed: host %s sensorgroup %s :" " update %s" % (args.hostnameorid, args.sensorgroup_uuid, patch)) _print_isensorgroup_show(isensorgroup)
def do_host_pv_list(cc, args): """List Physical Volumes.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) ipvs = cc.ipv.list(ihost.uuid) # Adjust state to be more user friendly for pv in ipvs: pv.pv_state = _adjust_state_data(pv.lvm_vg_name, pv.pv_state) field_labels = ['uuid', 'lvm_pv_name', 'disk_or_part_uuid', 'disk_or_part_device_node', 'disk_or_part_device_path', 'pv_state', 'pv_type', 'lvm_vg_name', 'ihost_uuid'] fields = ['uuid', 'lvm_pv_name', 'disk_or_part_uuid', 'disk_or_part_device_node', 'disk_or_part_device_path', 'pv_state', 'pv_type', 'lvm_vg_name', 'ihost_uuid'] utils.print_list(ipvs, fields, field_labels, sortby=0)
def do_host_device_label_assign(cc, args): """Assign a label to a device of a host""" attributes = utils.args_array_to_list_dict(args.attributes[0]) parameters = ["overwrite=" + str(args.overwrite)] host = ihost_utils._find_ihost(cc, args.hostnameorid) device = pci_device.find_device(cc, host, args.nameorpciaddr) attributes.append({'pcidevice_uuid': device.uuid}) new_device_labels = cc.device_label.assign(attributes, parameters) for p in new_device_labels.device_labels: uuid = p['uuid'] if uuid is not None: try: device_label = cc.device_label.get(uuid) except exc.HTTPNotFound: raise exc.CommandError('Host device label not found: %s' % uuid) _print_device_label_show(device_label)