Static Addresses in OpenStack Networking
When you launch a virtual machine on an OpenStack-managed network, the VM generally receives a random address in the active subnet. A researcher at work, however, needed a system for launching instances that have static addresses so he could preconfigure the local
/etc/hosts file with all his machines.
The trick is to use set up some networking ports in OpenStack with pre-assigned IPv4 addresses and then launch the instances with the
--port option rather than the
In the example below, the mySubnet network uses the 10.10.10.0/24 CIDR block.
# create a network port with the static IPv4 address # 10.10.10.101 openstack port create static-101 \ --network myNetwork \ --description "10.10.10.101 on mySubnet" \ --vnic-type normal \ --fixed-ip subnet=mySubnet,ip-address=10.10.10.101 # launch an instance using that port rather than specifying # a network openstack server create vm-101 \ --flavor m1.small \ --image cirros \ --port static-101 \ --key work-ed25519 \ --security-group default \ --boot-from-volume 10
Scaling up that solution is easy enough, and cloud-init can be used to pre-populate each