Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ovirt/ovirt-get-vm-ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ def get_vm_addresses(nics):
addresses = []
for nic in nics:
rps = nic.reported_devices
LOG.debug("RP objects: %s", rps)
if rps:
for rp in rps:
ips = rp.ips
LOG.debug("NIC IP objects: %s", ips)
if ips:
for ip in ips:
addr = ip.address
LOG.debug("NIC IP address: %s", addr)
if addr:
addresses.append(addr)
return addresses
Expand All @@ -77,6 +80,23 @@ def get_vm_main_address(nics):
return ip_address


def get_ips_from_vm_rps(conn, vm):
addresses = []
vm_reported_devices = conn.follow_link(vm.reported_devices)
LOG.debug("RP objects: %s", vm_reported_devices)
for rp in vm_reported_devices:
ips = rp.ips
LOG.debug("IP objects: %s", ips)
if ips:
for ip in ips:
address = ip.address
LOG.debug("IP address: %s", address)
if address:
addresses.append(address)

return addresses


def main():
setup_logging()
parser = argparse.ArgumentParser(description="oVirt VM IP Address fetcher")
Expand Down Expand Up @@ -110,6 +130,8 @@ def main():
vms = conn.system_service().vms_service()
vm = get_vm(vms, vm_id)
vm_nics = get_vm_nics(conn, vm)

LOG.info("Checking VM NIC reported devices...")
vm_primary_addr = get_vm_main_address(vm_nics)
vm_addresses = get_vm_addresses(vm_nics)

Expand All @@ -121,6 +143,10 @@ def main():

LOG.info("IP addresses for VM '%s': %s" % (vm_id, vm_addresses))

LOG.info("Fetching IP addresses directly from VM Reported Devices...")
vm_addresses = get_ips_from_vm_rps(conn, vm)
LOG.info("IP addresses for VM '%s': %s", vm_id, vm_addresses)


if __name__ == "__main__":
main()