How to find out all allocated IP's in OpenNebula

I can run the following to show me all the leased IP’s for each network:

$ onevnet show

but how do I find out ALL the leased IP’s for ALL the defined networks with a single command? I could call onvnet show through a loop over all the networks but that is slow and rather ugly. Looking for a single command, if possible.

Thx,

You can use onevnet list --xml and process the output (XML format)

Thank you. However, this doesn’t show the leases.

[oneadmin@srv01 ~]$ onevnet list --xml | grep -Ei 10.0.0.102
[oneadmin@srv01 ~]$

vs

[oneadmin@srv01 ~]$ onevnet show 26 --xml | grep -Ei 10.0.0.102
          <IP><![CDATA[10.0.0.102]]></IP>
[oneadmin@srv01 ~]$

Thx

The IP adresses are in the AR_POOL/AR/ALLOCATED element of the returned XML. The format of this field is space separated list of INDEX ENCODED_VMID.

For example, if you have the following AR_POOL/AR:

  <AR_POOL>
    <AR>
      <ALLOCATED><![CDATA[ 1 68719477428 2 68719477429 3 68719477432 4 68719477433 5 68719477434 6 68719477435 7 68719477436 8 68719477438 9 68719477440]]></ALLOCATED>
      <AR_ID><![CDATA[1]]></AR_ID>
      <IP><![CDATA[10.2.1.40]]></IP>
      <MAC><![CDATA[02:00:0a:02:01:28]]></MAC>
      <SIZE><![CDATA[40]]></SIZE>
      <TYPE><![CDATA[IP4]]></TYPE>
    </AR>
  </AR_POOL>

There are 9 IPs allocated, with start IP 10.2.1.40.
So you convert the first IP Address to IP Number and add the INDEX. Then convert back the result from IP Number to IP Address to have the dot notation.

For example, the last allocated IP is 167903528 + 9 = 167903537 where 167903537 is 10.2.1.49.

Hope this helps.

Best Regards,
Anton Todorov

Thanks Anton. Got it.

What are numbers such as these?

68719477428 , 68719477429 , etc

If I’m just using the 1,2,3,4 etc.

Thx,
TK

These values are referenced as “binary_magic” in the OpenNebula code. The upper part of this 64bit value defines the type of the allocation, currently VM, VNet or VRouter. The lower value is the OID of the entry in case of VM, it is the VM’s ID. The value of 0xFFFFFFFF defines the allocation as on HOLD.

I’ve found the best summary in the network’s section of onedb fsck : https://github.com/OpenNebula/one/blob/c26b6d470536b4c549c1968ac665716a78202eb4/src/onedb/fsck/network.rb#L473

Hope this helps.

Best Regards,
Anton Todorov