def get_vm_ips(self):
"""
Returns a list of VMs and their IPs available through the current
connection.
"""
try:
#get all VMs
vms = self.SESSION.listDefinedDomains()
result = []
#scan _all_ the VMs
for vm in vms:
#get VM and lookup hostname
target_vm = self.SESSION.lookupByName(vm)
target_hostname = target_vm.hostname()
#lookup IP
target_ip = socket.gethostbyname(target_hostname)
result.append(
{"hostname": target_hostname, "ip": target_ip}
)
return result
except libvirt.libvirtError as err:
raise SessionException("Unable to get VM IP information: '{}'".format(err))
评论列表
文章目录