OpenStack script to pre-allocate fixed IPs

The script allocates ports and indirectly gets fixed IPs from the DHCP server. The ports are named openstack000, openstack001 etc. and they are displayed in a format suitable for dnsmasq:

$ python --count 2 --net fsf-lan |  \
   sudo tee /etc/dnsmasq.d/openstack

If fsf-lan is a network shared with other tenants, it makes sure the IP are reserved, although they are not yet bound to an instance.

$ neutron port-list
| id                                   | name         | ...
| 1d1a05b1-383d-49ef-ae75-5ddcb5c714db | openstack001 |....

An new instance can then be given a known IP with:

$ openstack server create --image ubuntu-trusty-14.04 \
  --flavor 1cpu-1G \
  --key-name teuthology \
  --nic net-id=d936f445-5d68-485a-94f2-b852fd6b7d0c,v4-fixed-ip= \
  --wait openstack001

In the case of teuthology it is useful because the DNS can be configured once and for all while instances are dynamically created using IPs from the DNS instead of relying on allocation from the OpenStack DHCP server.

The script is derived from The python-openstackclient API does not encapsulate the python-neutronclient API but it provides access to it via like so:

    client_manager = clientmanager.ClientManager(
    net =

The best documentation for python-neutronclient is the the file from the sources. The body argument of the create_port function is a structure that looks like the following:

            body_value = {
                "port": {
                    "admin_state_up": True,
                    "name": name,
                    "network_id": network_id
            port =

where the semantic and name of the fields can be inferred from the structure returned by the list_ports function. The output of the list_ports function can be displayed by using the –debug option:

$ python --debug --count 2 --net fsf-lan
RESP BODY: {"ports": [{"status": "DOWN", "name": "openstack001",
   "allowed_address_pairs": [], "admin_state_up": true,
   "network_id": "d936f445-5d68-485a-94f2-b852fd6b7d0c", ...