def main(): """ Simple command-line program for creating host and VM folders in a datacenter. """ args = GetArgs() if args.password: password = args.password else: password = getpass.getpass(prompt='Enter password for host %s and ' 'user %s: ' % (args.host, args.user)) si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=password, port=int(args.port)) if not si: print("Could not connect to the specified host using specified " "username and password") return -1 atexit.register(Disconnect, si) content = si.RetrieveContent() dc = get_obj(content, [vim.Datacenter], args.datacenter) if (get_obj(content, [vim.Folder], args.folder)): print("Folder '%s' already exists" % args.folder) return 0 #create_folder(content, dc.hostFolder, args.folder) #print("Successfully created the host folder '%s'" % args.folder) create_folder(content, dc.vmFolder, args.folder) print("Successfully created the VM folder '%s'" % args.folder) return 0
def main(): args = get_args() # connect this thing si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, si) vm = None if args.uuid: search_index = si.content.searchIndex vm = search_index.FindByUuid(None, args.uuid, True) elif args.vm_name: content = si.RetrieveContent() vm = get_obj(content, [vim.VirtualMachine], args.vm_name) if vm: add_disk(vm, si, args.disk_size, args.disk_type) return 0 else: print("VM not found") return 1
def main(): try: args = get_args() if args.info != 'cpu' and args.info != 'mem' and args.info != 'disk' and args.info != 'power': print("Wrong query info!") return si = None if args.no_ssl: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) else: si = SmartConnect(host=args.host, user=args.user, pwd=args.password, port=args.port) except: print("Failed to connect") exit() # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() for child in content.rootFolder.childEntity: datacenter = child hostfolder = datacenter.hostFolder hostlist = metricvalue(hostfolder, 0) for hosts in hostlist: esxihosts = hosts.host for esxi in esxihosts: name = esxi.summary.config.name run(content, name, [args.info], args.time)
def main(): '''Main program''' args = parse_args() default_cfg = '%s/%s.yml' % (os.path.dirname( os.path.abspath(__file__)), os.path.splitext( os.path.basename(__file__))[0]) cfg_file = os.getenv('VCENTER_INV_CFG', default=default_cfg) config = load_config(cfg_file) env_pwd = os.getenv('VCENTER_INV_PWD') password = config['password'] or env_pwd or getpass( prompt="enter password: ") # connect to vc si = SmartConnectNoSSL( host=config['host'], user=config['username'], pwd=password, port=int(config['port']), ) # disconnect vc atexit.register(Disconnect, si) content = si.RetrieveContent() vm_list = get_vms(content) if args.list: result = create_inventory_list(vm_list, group_by=config['group_by'], use_ip=config['use_ip']) elif args.host: result = create_host_info(vm_list, host=args.host) print(result)
def main(): args = get_args() # connect this thing si = None if args.no_ssl: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) else: si = SmartConnect(host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() template = None template = get_obj(content, [vim.VirtualMachine], args.template) if template: clone_vm(content, template, args.vm_name, si, args.datacenter_name, args.cluster_name, args.resource_pool, args.power_on) else: print("template not found")
def main(): args = cli.get_args() try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except IOError as e: pass if not si: raise SystemExit("Unable to connect to host with supplied info.") content = si.RetrieveContent() perfManager = content.perfManager counterInfo = {} for c in perfManager.perfCounter: prefix = c.groupInfo.key fullName = c.groupInfo.key + "." + c.nameInfo.key + "." + c.rollupType counterInfo[fullName] = c.key dict_to_str = json.dumps(counterInfo) dict_to_str = dict_to_str.replace(',', '\n') sys.stdout = open('counterInfo.txt', 'w') print(dict_to_str)
def clone_vm_from_no(vm_no, temp_no): # 登录vCenter si = SmartConnectNoSSL(host='172.16.1.200', user='******', pwd='Cisc0123,,..//', port=443) atexit.register(Disconnect, si) content = si.RetrieveContent() template = None # 判断克隆模板 if temp_no == 1: template = get_obj(content, [vim.VirtualMachine], 'vm_temp_cpu1_mem1') elif temp_no == 2: template = get_obj(content, [vim.VirtualMachine], 'vm_temp_cpu1_mem2') elif temp_no == 3: template = get_obj(content, [vim.VirtualMachine], 'vm_temp_cpu2_mem1') elif temp_no == 4: template = get_obj(content, [vim.VirtualMachine], 'vm_temp_cpu2_mem2') # 根据VLANID产生虚拟机名字 vm_name = 'CentOS_' + str(vm_no) # 克隆产生虚拟机 clone_vm(content, template, vm_name, si, None, 'vm_cloned_from_template', None, None, 'QYT_Cloud', False, None) return None
def main(): esxi_host = {} args = get_args() print(args) # connect this thing si = SmartConnectNoSSL(host=args['host'], user=args['user'], pwd=args['password'], port=args['port']) # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() esxi_obj = get_obj(content, [vim.HostSystem]) for esxi in esxi_obj: esxi_host[esxi.name] = { 'esxi_info': {}, 'datastore': {}, 'network': {}, 'vm': {} } esxi_host[esxi.name]['esxi_info']['厂商'] = esxi.summary.hardware.vendor esxi_host[esxi.name]['esxi_info']['型号'] = esxi.summary.hardware.model for i in esxi.summary.hardware.otherIdentifyingInfo: if isinstance(i, vim.host.SystemIdentificationInfo): esxi_host[esxi.name]['esxi_info']['SN'] = i.identifierValue esxi_host[esxi.name]['esxi_info'][ '处理器'] = '数量:%s 核数:%s 线程数:%s 频率:%s(%s) ' % ( esxi.summary.hardware.numCpuPkgs, esxi.summary.hardware.numCpuCores, esxi.summary.hardware.numCpuThreads, esxi.summary.hardware.cpuMhz, esxi.summary.hardware.cpuModel) esxi_host[esxi.name]['esxi_info']['处理器使用率'] = '%.1f%%' % ( esxi.summary.quickStats.overallCpuUsage / (esxi.summary.hardware.numCpuPkgs * esxi.summary.hardware.numCpuCores * esxi.summary.hardware.cpuMhz) * 100) esxi_host[esxi.name]['esxi_info'][ '内存(MB)'] = esxi.summary.hardware.memorySize / 1024 / 1024 esxi_host[esxi.name]['esxi_info']['可用内存(MB)'] = '%.1f MB' % ( (esxi.summary.hardware.memorySize / 1024 / 1024) - esxi.summary.quickStats.overallMemoryUsage) esxi_host[esxi.name]['esxi_info']['内存使用率'] = '%.1f%%' % ( (esxi.summary.quickStats.overallMemoryUsage / (esxi.summary.hardware.memorySize / 1024 / 1024)) * 100) esxi_host[esxi.name]['esxi_info'][ '系统'] = esxi.summary.config.product.fullName for ds in esxi.datastore: esxi_host[esxi.name]['datastore'][ds.name] = {} esxi_host[esxi.name]['datastore'][ds.name]['总容量(G)'] = int( (ds.summary.capacity) / 1024 / 1024 / 1024) esxi_host[esxi.name]['datastore'][ds.name]['空闲容量(G)'] = int( (ds.summary.freeSpace) / 1024 / 1024 / 1024) esxi_host[esxi.name]['datastore'][ds.name]['类型'] = ( ds.summary.type) pprint(esxi_host[esxi.name]['datastore']) for nt in esxi.network: esxi_host[esxi.name]['network'][nt.name] = {} esxi_host[esxi.name]['network'][nt.name]['标签ID'] = nt.name
def main(): try: si = SmartConnectNoSSL( host = ho, user = us, pwd = password) atexit.register(Disconnect, si) content = si.RetrieveContent() objview = content.viewManager.CreateContainerView(content.rootFolder,[vim.HostSystem],True) esxi_hosts = objview.view datastores = content.viewManager.CreateContainerView(content.rootFolder,[vim.Datastore],True).view for esxi_host in esxi_hosts: state = esxi_host.summary.runtime.connectionState powerstate = esxi_host.summary.runtime.powerState print("{}\t{}\t{}".format("ESXi Host: ", esxi_host.name,state)) if(state == "connected" and powerstate=="poweredon"): storage_system = esxi_host.configManager.storageSystem host_file_sys_vol_mount_info = storage_system.fileSystemVolumeInfo.mountInfo for host_fs in host_file_sys_vol_mount_info: if host_fs.volume.type == "VMFS": for dt in datastores: if(host_fs.volume.name == dt.summary.name): print("{}\t{}".format("Datastore: ", host_fs.volume.name)) print("{}\t{}".format("Capacity: ", sizeof_fmt(host_fs.volume.capacity))) print("{}\t{}".format("Free space: ", sizeof_fmt(dt.summary.freeSpace))) else: print('poweredoff') except Exception as e: print(str(e),'\n') return -1 return 0
def main(): try: si = SmartConnectNoSSL(host=ho, user=us, pwd=password) atexit.register(Disconnect, si) except Exception as e: print(str(e)) return -1 s = False content = si.RetrieveContent() object_view = content.viewManager.CreateContainerView( content.rootFolder, [vim.HostSystem], True).view for obj in object_view: if obj.summary.config.name == find_host_ip: host = obj s = True break if s: if host.runtime.powerState == 'poweredOn': host.Reboot(force=True) print(1) else: print(0) else: print('Not Found!') # host = si.content.searchIndex.FindByDnsName(None,find_host_ip,False) # if host is not None: # print('1') # else: # print('0') return 0
def main(): args = get_args() # connect this thing si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, si) vm = None if args.uuid: search_index = si.content.searchIndex vm = search_index.FindByUuid(None, args.uuid, True) elif args.vm_name: content = si.RetrieveContent() vm = get_obj(content, [vim.VirtualMachine], args.vm_name) if vm: vm.MarkAsTemplate() print "VM %s marked as template." % args.vm_name return 0 else: print "VM not found" return 1
def start(template_str): """ Let this thing fly args = get_args() """ # connect this thing si = SmartConnectNoSSL(host='xx.xx.xx.xx', user='******', pwd='anamishhinA@2', port='443') # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() template = None template = get_obj(content, [vim.VirtualMachine], template_str) vmname = template_str + ''.join( random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(8)) dc_name, vm_folder, ds_name, cluster_name, resource_pool, ds_cluster_name = ( None for i in range(6)) power_on = True if template: clone_vm(content, template, vmname, si, dc_name, vm_folder, ds_name, cluster_name, resource_pool, power_on, ds_cluster_name) else: print "template not found"
def main(): args = get_args() try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except IOError as e: pass if not si: raise SystemExit("Unable to connect to host with supplied info.") content = si.RetrieveContent() search_index = content.searchIndex vm = None if args.uuid: vm = search_index.FindByUuid(None, args.uuid, True, True) elif args.ip: vm = search_index.FindByIp(None, args.ip, True) else: vm = get_obj(content, [vim.VirtualMachine], args.name) if not vm: print(u"Could not find a virtual machine to examine.") exit(1) perf=perfdata() counters=perf.perfcounters() for counter in counters: p = Thread(target=perf.run, args=(content,vm,counter,)) p.start()
def main(): """ Simple command-line program for listing the virtual machines on a host. """ args = setup_args() si = None try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except vim.fault.InvalidLogin: raise SystemExit("Unable to connect to host " "with supplied credentials.") content = si.RetrieveContent() if args.folder == "": for child in content.rootFolder.childEntity: if hasattr(child, 'vmFolder'): datacenter = child vmfolder = datacenter.vmFolder vmlist = vmfolder.childEntity for vm in vmlist: shutdown(vm) else: vmfolder = get_obj(content, [vim.Folder], args.folder) vmlist = vmfolder.childEntity for vm in vmlist: shutdown(vm)
def main(): args = get_args() try: si = None si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) atexit.register(Disconnect, si) except: print("Connection failed") exit() if si is None: exit() content = si.RetrieveContent() count = 0 vm_collect = {} # vm_collect[args.host] = {} for child in content.rootFolder.childEntity: if hasattr(child, 'vmFolder'): datacenter = child vmfolder = datacenter.vmFolder vmlist = vmfolder.childEntity for vm in vmlist: if type(vm) == vim.VirtualMachine: count = count + 1 if format(vm.runtime.powerState) == "poweredOn": printvminfo(vm_collect, vm) # print(vm_collect) vm_collect["total_vms"] = count requests.post(FULL_HOSTNAME + "/api/usage/addvm/", data=json.dumps(vm_collect))
def run(exsi,user,pwd,interval): try: si = SmartConnectNoSSL(host=exsi, user=user, pwd=pwd, port=443) atexit.register(Disconnect, si) content = si.RetrieveContent() vchtime = si.CurrentTime() perf_dict = {} perfList = content.perfManager.perfCounter for counter in perfList: counter_full = "{}.{}.{}".format(counter.groupInfo.key, counter.nameInfo.key, counter.rollupType) perf_dict[counter_full] = counter.key for datacenter in content.rootFolder.childEntity: datacenter_name = datacenter.name.encode("utf8") datastores = datacenter.datastore for ds in datastores: DatastoreInformation(ds,datacenter_name) if hasattr(datacenter.hostFolder, 'childEntity'): hostFolder = datacenter.hostFolder computeResourceList = [] computeResourceList = getComputeResource(hostFolder,computeResourceList) for computeResource in computeResourceList: ComputeResourceInformation(computeResource,datacenter_name,content,perf_dict,vchtime,interval,exsi) except vmodl.MethodFault as error: print "Caught vmodl fault : " + error.msg return False, error.msg return True, "ok"
def _init_vc_view(self): args = get_args() si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) if not si: print( "Could not connect to the specified host using specified " "username and password") return -1 self.si = si atexit.register(Disconnect, si) self.content = si.RetrieveContent() self.vm_ids = [] try: self.vm_ids = [ vm_id.strip() for vm_id in args.vm_list.split(',') if vm_id ] except Exception: print "Error parsing vm_list: %s" % args.vm_list objview = self.content.viewManager.CreateContainerView( self.content.rootFolder, [vim.VirtualMachine], True) self.vm_obj_list = objview.view objview.Destroy()
def FindVMIP(IP, usern, passw, vIP="10.160.111.161"): def find_IP(virtual_machine, IPLook): summary = virtual_machine.summary for nic in virtual_machine.guest.net: if nic.ipConfig is not None: addresses = nic.ipConfig.ipAddress for adr in addresses: #print(adr.ipAddress) if IPLook == adr.ipAddress: print("IP being used by: " + summary.config.name) return c = SmartConnectNoSSL(host=vIP, user=usern, pwd=passw) content = c.RetrieveContent() container = content.rootFolder viewType = [vim.VirtualMachine] recursive = True containerView = content.viewManager.CreateContainerView( container, viewType, recursive) children = containerView.view for child in children: find_IP(child, IP)
def main(): args = get_args() # connect this thing si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, si) if args.uuid: search_index = si.content.searchIndex vm = search_index.FindByUuid(None, args.uuid, True) elif args.vm_name: content = si.RetrieveContent() vm = get_obj(content, [vim.VirtualMachine], args.vm_name) if vm: if args.cpu and args.memory: print('changeCPU:',args.cpu) print('changeMEMORY:',args.memory) elif args.memory and not args.cpu: print('changeMEMORY:',args.memory) change_memory(vm, si, args.memory) elif args.cpu and not args.memory: print('changeCPU:',args.cpu) change_vcpu(vm, si, args.cpu) else: print("-h, --help show help messages for you") else: print("VM not found")
def get_vds_uuid(vds_name, host, user, pwd): try: service_instance = SmartConnectNoSSL(host=host, user=user, pwd=pwd, port='443') atexit.register(Disconnect, service_instance) content = service_instance.RetrieveContent() # Get VDS object vds = get_obj(content, [vim.DistributedVirtualSwitch], vds_name) if vds is None: logging.error("Distributed Switch: %s Not found in vCenter." % vds_name) print("ERROR: Distributed Switch: %s Not found in vCenter." % vds_name) sys.exit(2) except vmodl.MethodFault as error: logging.error( "Unable to connect to vCenter: Caught vmodl fault: {0}".format( error.msg)) print("Unable to connect to vCenter: Caught vmodl fault: {0}".format( error.msg)) sys.exit(2) vds_uuid = vds.config.uuid logging.debug("VDS %s has UUID: %s" % (vds_name, vds_uuid)) return vds_uuid
def main(): args = cli.get_args() try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except IOError as e: pass if not si: raise SystemExit("Unable to connect to host with supplied info.") content = si.RetrieveContent() containerView = content.viewManager.CreateContainerView(content.rootFolder, [vim.Datacenter], True) children = containerView.view for datacenter in children: if hasattr(datacenter, 'vmFolder'): vmFolder = datacenter.vmFolder vmList = vmFolder.childEntity for vm in vmList: PrintVmInfo(vm) return 0
def main(): args = GetArgs() si = None if args.password: password = args.password else: password = getpass.getpass(prompt="Enter password for host {} and user {}: ".format(args.host, args.user)) try: if args.skip_ssl_validation: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=password, port=int(args.port)) else: si = SmartConnect(host=args.host, user=args.user, pwd=password, port=int(args.port)) except IOError as e: pass if not si: print('Could not connect to the specified host using specified username and password') return -1 atexit.register(Disconnect, si) content = si.RetrieveContent() # Get all the performance counters perf_dict = {} perf_list = content.perfManager.perfCounter for counter in perf_list: counter_full = "{}.{}.{}".format(counter.groupInfo.key, counter.nameInfo.key, counter.rollupType) perf_dict[counter_full] = {'key': counter.key, 'summary': counter.nameInfo.summary} with open('perf_dict.json', 'w') as out: json.dump(perf_dict, out, indent=2)
def post(self, request): data = json.loads(request.body) host = data['host'] username = data['username'] password = data['password'] try: si = None si = SmartConnectNoSSL(host=host, user=username, pwd=password, port=443) atexit.register(Disconnect, si) except: return Response({'message': 'Failure'}, status=401) if si is None: return Response({'message': 'Failure'}, status=401) content = si.RetrieveContent() dic = [] for datacenter in content.rootFolder.childEntity: dic.append(datacenter.name) return Response({ 'message': 'Success', 'results': dic }, status=status.HTTP_200_OK)
def main(): args = get_args() # create the service instance si = None if args.disable_ssl_verification: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=args.port) else: si = SmartConnect(host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect the service instance at program exit atexit.register(Disconnect, si) vm = None if args.uuid: search_index = si.content.searchIndex vm = search_index.FindByUuid(None, args.uuid, True) elif args.vm_name: content = si.RetrieveContent() vm = get_obj(content, [vim.VirtualMachine], args.vm_name) if vm: add_raw_disk(vm, si, args.device_name, args.disk_mode, args.compatibility_mode) else: print "VM not found"
def main(): args = setup_args() si = None try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except vim.fault.InvalidLogin: raise SystemExit("Unable to connect to host " "with supplied credentials.") content = si.RetrieveContent() for child in content.rootFolder.childEntity: if hasattr(child, 'vmFolder'): datacenter = child vmfolder = datacenter.vmFolder vmlist = vmfolder.childEntity diff_24hour = datetime.now() - timedelta(hours=24) for vm in vmlist: # Assuming content.rootFolder.childEntity.vmlist[..].creationTime is VM created time if datetime.strptime(vm.creation.Date, '%b %d %Y %I:%M%p') < diff_24hour: print("VM Name: " + vm.name + "Creation Date: " + str(vm.creation.Date))
def main(): """ Simple command-line program for listing the virtual machines on a host. """ args = setup_args() si = None try: si = SmartConnectNoSSL(host=args.host, user=args.user, pwd=args.password, port=int(args.port)) atexit.register(Disconnect, si) except vim.fault.InvalidLogin: raise SystemExit("Unable to connect to host " "with supplied credentials.") content = si.RetrieveContent() vm_collect = {} for child in content.rootFolder.childEntity: if hasattr(child, 'vmFolder'): datacenter = child vmfolder = datacenter.vmFolder vmlist = vmfolder.childEntity for vm in vmlist: printvminfo(vm_collect, vm) print(vm_collect) with open("/home/annie/CloudTides/Tools/Information.json", "w") as f: json.dump(vm_collect, f)
def main(): args = get_args() # connect this thing serviceInstance = None if args.no_ssl: serviceInstance = SmartConnectNoSSL( host=args.host, user=args.user, pwd=args.password, port=args.port) else: serviceInstance = SmartConnect( host=args.host, user=args.user, pwd=args.password, port=args.port) # disconnect this thing atexit.register(Disconnect, serviceInstance) vm = None if args.uuid: search_index = serviceInstance.content.searchIndex vm = search_index.FindByUuid(None, args.uuid, True) elif args.vm_name: content = serviceInstance.RetrieveContent() vm = get_obj(content, [vim.VirtualMachine], args.vm_name) if vm: add_nic(serviceInstance, vm, args.port_group) else: print("VM not found")
def start(vmname, template_str, cpus, mem, vm_folder, nicnum, nics): """ Let this thing fly args = get_args() """ # connect this thing si = SmartConnectNoSSL(host='xx.xx.xx.xx', user='******', pwd='password', port='443') # disconnect this thing atexit.register(Disconnect, si) content = si.RetrieveContent() template = None template = get_obj(content, [vim.VirtualMachine], template_str) guestid = template.config.guestId dc_name, ds_name, cluster_name, ds_cluster_name = (None for i in range(4)) power_on = True if template: clone_vm(content, template, vmname, dc_name, vm_folder, ds_name, cluster_name, power_on, ds_cluster_name, cpus, mem, guestid, nicnum, nics) else: print "template not found"
def main(): esxi_hosts = [] for vsphere_host in vsphere_hosts: serviceInstance = SmartConnectNoSSL(host=vsphere_host, user=vsphere_username, pwd=vsphere_password) content = serviceInstance.RetrieveContent() host_view = content.viewManager.CreateContainerView( content.rootFolder, [vim.HostSystem], True) hosts = [host for host in host_view.view] for host in hosts: host_info = dict() host_pnics = capture_host_pnics(host) host_vnics = capture_host_vnics(host) host_vswitches = capture_host_vswitches(host) host_portgroups = capture_host_portgroups(host) host_info.update({ 'host': vsphere_host, 'hostname': host.name, 'pnics': host_pnics, 'vswitches': host_vswitches, 'portgroups': host_portgroups, 'vnics': host_vnics }) esxi_hosts.append(host_info) Disconnect(serviceInstance) print(json.dumps(esxi_hosts, indent=4))
def main(): try: si = SmartConnectNoSSL( host = ho, user = us, pwd = password) atexit.register(Disconnect, si) except Exception as e: print(str(e)) return -1 content = si.RetrieveContent() host = None object_view = content.viewManager.CreateContainerView( content.rootFolder, [vim.HostSystem], True).view for obj in object_view: if obj.summary.config.name == find_host_ip: host = obj break if host is not None: if isinstance(host.parent,vim.ClusterComputeResource): tp = host.parent.name+' (Cluster)' else: tp= 'Datacenter' print("Location: ", tp) print("Host: ", host.summary.config.name) print("Host OS: ", host.summary.config.product.fullName) print("Con State: ", host.summary.runtime.connectionState) print("Power: ", host.summary.runtime.powerState) print("Maintenance mode: ", host.summary.runtime.inMaintenanceMode) else: print('0') return 0