def do_service_show(cc, args): """Show a service.""" try: iservice = cc.iservice.get(args.iservice) except exc.HTTPNotFound: raise exc.CommandError('service not found: %s' % args.iservice) else: _print_iservice_show(iservice)
def _find_interface(cc, ihost, ifnameoruuid): interfaces = cc.iinterface.list(ihost.uuid) for i in interfaces: if i.ifname == ifnameoruuid or i.uuid == ifnameoruuid: break else: raise exc.CommandError('Interface not found: host %s if %s' % (ihost.hostname, ifnameoruuid)) return i
def do_service_parameter_apply(cc, args): """Apply the Service Parameters.""" try: cc.service_parameter.apply(args.service) except exc.HTTPNotFound: raise exc.CommandError('Failed to apply service parameters') print 'Applying %s service parameters' % args.service
def _find_fs(cc, name): fs_list = cc.controller_fs.list() for fs in fs_list: if fs.name == name: break else: raise exc.CommandError('Filesystem "%s" not found' % name) return fs
def do_event_show(cc, args={}): '''Show a event log.''' try: log = cc.event_log.get(args.event_log) except exc.HTTPNotFound: raise exc.CommandError('Event log not found: %s' % args.event_log) else: _display_event(log)
def do_service_delete(cc, args): """Delete a iservice.""" for c in args.iservice: try: cc.iservice.delete(c) except exc.HTTPNotFound: raise exc.CommandError('Service not found: %s' % c) print('Deleted service %s' % c)
def _find_iprofile(cc, iprofilenameoruuid): iprofiles = cc.iprofile.list() for ip in iprofiles: if ip.hostname == iprofilenameoruuid or ip.uuid == iprofilenameoruuid: break else: raise exc.CommandError('Profile not found: %s' % iprofilenameoruuid) return ip
def do_host_stor_add(cc, args): """Add a storage to a host.""" field_list = [ 'function', 'idisk_uuid', 'journal_location', 'journal_size', 'tier_uuid' ] # default values, name comes from 'osd add' fields = {'function': 'osd'} 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 'journal_size' in user_specified_fields.keys(): user_specified_fields['journal_size_mib'] = \ user_specified_fields.pop('journal_size') 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(" ", "") fields.update(user_specified_fields) 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_servicegroup_show(cc, args): """Show an iservicegroup.""" try: iservicegroup = cc.iservicegroup.get(args.iservicegroup) except exc.HTTPNotFound: raise exc.CommandError('servicegroup not found: %s' % args.iservicegroup) else: _print_iservicegroup_show(iservicegroup)
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_application_abort(cc, args): """Abort the current application operation""" try: cc.app.abort(args.name) print('Application abort request has been accepted. If the ' 'previous operation has not completed/failed, it will ' 'be cancelled shortly.') except exc.HTTPNotFound: raise exc.CommandError('Application not found: %s' % args.name)
def _find_pv(cc, ihost, pvuuid): pvs = cc.ipv.list(ihost.uuid) for i in pvs: if i.uuid == pvuuid: break else: raise exc.CommandError('PV not found: host %s PV %s' % (ihost.hostname, pvuuid)) return i
def do_snmp_trapdest_show(cc, args): """Show a SNMP trap destination.""" try: itrapdest = cc.itrapdest.get(args.itrapdest) except exc.HTTPNotFound: raise exc.CommandError('Trap Destination not found: %s' % args.itrapdest) else: _print_itrapdest_show(itrapdest)
def do_registry_image_delete(cc, args): """Remove the specified Docker image from the local registry""" try: cc.registry_image.delete(args.name_and_tag) print( 'Image %s deleted, please run garbage collect to free disk space.' % args.name_and_tag) except exc.HTTPNotFound: raise exc.CommandError('Image not found: %s' % args.name_and_tag)
def _find_sensor(cc, ihost, sensor_uuid): sensors = cc.isensor.list(ihost.uuid) for p in sensors: if p.uuid == sensor_uuid: break else: raise exc.CommandError('Sensor not found: host %s sensor %s' % (ihost.id, sensor_uuid)) return p
def do_memprofile_delete(cc, args): """Delete a memory profile.""" for n in args.iprofilenameoruuid: iprofile = iprofile_utils._find_iprofile(cc, n) try: cc.iprofile.delete(iprofile.uuid) except exc.HTTPNotFound: raise exc.CommandError('Memory profile delete failed: %s' % n) print('Deleted memory profile %s' % n)
def do_host_device_image_update_abort(cc, args): """Abort device image update on a host.""" ihost = ihost_utils._find_ihost(cc, args.hostnameorid) try: host = cc.ihost.device_image_update_abort(ihost.uuid) except exc.HTTPNotFound: raise exc.CommandError( 'Device image update-abort failed: host %s' % args.hostnameorid) _print_ihost_show(host)
def do_upgrade_abort_complete(cc, args): """Complete a software upgrade.""" try: upgrade = cc.upgrade.delete() except exc.HTTPNotFound: raise exc.CommandError('Upgrade not found') _print_upgrade_show(upgrade)
def do_helm_override_delete(cc, args): """Delete overrides for a chart.""" try: cc.helm.delete_overrides(args.chart, args.namespace) print('Deleted chart overrides for %s:%s' % ( args.chart, args.namespace)) except exc.HTTPNotFound: raise exc.CommandError('chart overrides not found: %s:%s' % ( args.chart, args.namespace))
def _find_node(cc, ihost, inodeuuid): nodes = cc.inode.list(ihost.uuid) for i in nodes: if i.uuid == inodeuuid: break else: raise exc.CommandError('Inode not found: host %s if %s' % (ihost.hostname, inodeuuid)) return i
def _find_fs(cc, ihost, uuid): filesystems = cc.host_fs.list(ihost.uuid) for fs in filesystems: if fs.uuid == uuid: break else: raise exc.CommandError('Filesystem not found: host %s filesystem %s' % (ihost.hostname, uuid)) return fs
def do_ifprofile_show(cc, args): """Show interface profile attributes.""" iprofile = iprofile_utils._find_iprofile(cc, args.ifprofilenameoruuid) get_ifprofile_data(cc, iprofile) if not iprofile.ports: # not an 'interface' profile raise exc.CommandError('If Profile not found: %s' % args.ifprofilenameoruuid) _print_ifprofile_show(iprofile)
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))
def do_memprofile_show(cc, args): """Show memory profile attributes.""" iprofile = iprofile_utils._find_iprofile(cc, args.iprofilenameoruuid) get_memprofile_data(cc, iprofile) if not iprofile.memory: # not a memory profile raise exc.CommandError('Memory Profile not found: %s' % args.ifprofilenameoruuid) _print_memprofile_show(iprofile)
def _find_stor(cc, ihost, storuuid): stors = cc.istor.list(ihost.uuid) for i in stors: if i.uuid == storuuid: break else: raise exc.CommandError('Stor not found: host %s stor %s' % (ihost.hostname, storuuid)) return i
def _find_port(cc, ihost, portnameoruuid): ports = cc.port.list(ihost.uuid) for p in ports: if p.name == portnameoruuid or p.uuid == portnameoruuid: break else: raise exc.CommandError('Port not found: host %s port %s' % (ihost.id, portnameoruuid)) return p
def _find_device(cc, host, nameorpciaddr): devices = cc.pci_device.list(host.uuid) for d in devices: if d.name == nameorpciaddr or d.pciaddr == nameorpciaddr: break else: raise exc.CommandError('PCI devices not found: host %s device %s' % (host.id, nameorpciaddr)) return d
def _find_port(cc, ihost, portnameoruuid): ports = cc.ethernet_port.list(ihost.uuid) for p in ports: if p.name == portnameoruuid or p.uuid == portnameoruuid: break else: raise exc.CommandError('Ethernet port not found: host %s port %s' % (ihost.id, portnameoruuid)) p.autoneg = 'Yes' # TODO(jkung) Remove when autoneg supported in DB return p
def _find_fs(cc, ihost, host_fs): if host_fs.isdigit(): try: fs = cc.host_fs.get(host_fs) except exc.HTTPNotFound: raise exc.CommandError('Filesystem not found by id: %s' % host_fs) else: return fs else: fs_list = cc.host_fs.list(ihost.uuid) for fs in fs_list: if fs.name == host_fs: return fs if fs.uuid == host_fs: return fs else: raise exc.CommandError('Filesystem not found by name or ' 'uuid: %s' % host_fs)
def _find_disk(cc, ihost, disknameoruuid): disks = cc.idisk.list(ihost.uuid) for p in disks: if p.device_node == disknameoruuid or p.uuid == disknameoruuid: break else: raise exc.CommandError('Disk not found: host %s disk %s' % (ihost.id, disknameoruuid)) return p