How to get CIDR or netmask after deploy instance.

Asked by Ellen Batbouta

When I deploy an instance, the IPs (both private and floating) are returned. However, my application needs more info. Is it possible to get the CIDR or netmask info as well? In the future, I can also envision needing additional info for ipv4 and ipv6.

A work around could be to parse the output of ip address show.

Question information

English Edit question
Murano Edit question
No assignee Edit question
Solved by:
Stan Lagun
Last query:
Last reply:
Revision history for this message
Stan Lagun (slagun) said :

I see 2 possible ways to get this (or some of this) information:
1. There is a "joinedNetworks" property in the Instance class which can be used to get list of networks instance joined to ($ Each network object has a "describe" method which returns structure with info about network including CIDR. joinedNetworks was introduced in Newton. If you're on older version you will need to put more efforts into calculating list of networks for the instance (it can join Environment/Region networks or custom networks provided to the Instance explicitly)
2. Ask the VM. VMs get their network configuration through DHCP so you can write a shell script that will retrieve that information from VM

Revision history for this message
Ellen Batbouta (ellen-batbouta) said :

Thank you. I am using Mitaka. So I don't have the joinedNetworks property unfortunately. Here is what I have
done: I first check the property:


this is set to True

So then I get the default network info from the environment:

$defNet: $._environment.defaultNetworks.environment.describe()

The describe method returns a Network object, yes? How do I get
the CIDR from this?

The CIDR should be: $defNet.subnetCidr for a Neutron network.
In my case, there is no value for this field.

Revision history for this message
Best Stan Lagun (slagun) said :

Here is the structure that describe() returns:

CIDR is under 'cidr' key so $._environment.defaultNetworks.environment.describe().cidr should work for you

Revision history for this message
Ellen Batbouta (ellen-batbouta) said :

Thank you. Just what I need.

Revision history for this message
Ellen Batbouta (ellen-batbouta) said :

Thanks Stan Lagun, that solved my question.