I plan on creating a reusable template image for deploying my application to multiple virtual machines that may be on different networks and different datacenters. I plan on having full control of the host system and running KVM as the hypervisor.
The image will be made immutable when attached to the virtual machine so I can deploy changes more easily by updating a single template instead of each machine's internal software.
I understand how to configure the /etc/network/interfaces file on a regular ubuntu system, but how would you automatically assign each virtual machine 1 or more IP addresses when you are working with an immutable image for the virtual machine on the first boot?
The only way I have imagined to do this so far is to set up the template to rely on DHCP for networking when it boots. After the machine has booted, it could then run a script that verifies and re-configures the IP configuration by connecting to another server or remote filesystem that has the network configuration information.
Perhaps, immediately after the network is available, I could run a script on the guest VM that sends the MAC address of the attached network interface(s) as the unique id to retrieve the network configuration from another "master" server that has the IP assignments. This assumes that all VMs will be assigned a unique MAC address when they are created.
I might need to avoid starting services like mysql, and php until the network has been configured and verified so that the network restarting shortly after boot doesn't disrupt anything important.
Would that sound like a correct way to do it?
Do Amazon EC2, openstack or others have a different approach to network automation? Perhaps they provide an API and/or scripts that do the same thing during boot?
I'm using KVM on the Ubuntu host and the guest OS will also be Ubuntu if that matters.