Automating VM creation
Hello,
I am trying to automate the procedure of creating VM from template. I am using python oVirt sdk.
My script not only creates but assigns IP to VM and performes runtime configuration.
All created VMs should have predefined static IP, thus i can't set ip in template.
So i need to somehow modify an ip address on VM's disk image. On RHEL ip is stored in file /etc/sysconfig/network-scripts/icfg-eth0.
My options are:
1). Connect to hypervisor via SSH and patch disk (assuming i know the offset of ip on disk image).
This will only work for RAW disk images.
2). Connect to hypervisor via SSH, mount image using libguestfs utils (guestmount). This works on cow disks too.
Do i have any other options to modify VM files?
What is the best option in terms of security and relaiability?
Can i somehow mount disk images stored on hypervisor on another VM?
The last step of VM creation is to run it and perform configuration(for ex. ipa-client-install)
My script connects to VM using ssh and runs required commands.
Is there a better way to run commands on VM?
Regards
Andrey
Responses
I raised a similar discussion regarding IPAM solutions here:
https://access.redhat.com/discussions/969603
The methods I have used and would suggest are (because they are portable by nature):
1. Have the image configured with DHCP and use static assignment via DHCP (ie. write an API call from the hypervisor to configure a static assignment on your DHCP server).
2. Configure the template with DHCP, and on first boot (from the guest) configure static IP by calling out to an API / service to fetch the IP and restart networking.
3. Depending on hypervisor technology, you may be able to 'pass through' information to the guest on build by use of an internal REST API or environment variable.
I have solved this several different ways when using different technologies eg. AWS, Openstack, VMware, I've personally found a central IPAM solution with API is the most reliable across mixed environments.
As for running the commands on the VM, depending on how much configuration you do I would suggesting looking at installing a Puppet agent on the base image and then registering the server with Puppet on first boot and pulling down configuration with a Puppet run (IP could even potentially be done this way if the initial Puppet run happens using DHCP). Puppet is perfectly suited (and designed) to carry out the configuration management steps of your builds to ensure a consistent state at the end of the build process.
Depending on the type of disk image you create (or possibly all disk images, I'm not 100% sure) you should be able to mount the disk image as a loopback and modify the file.
Here is OpenStack documentation using guestfish
http://docs.openstack.org/grizzly/openstack-image/content/ch_modifying_images.html
Another example from one of the Community Leaders
https://access.redhat.com/discussions/664843
I am going to look around to see if there is a way without using guestfish/libguestfs
Would this be an option for your environment?
https://github.com/jasonc/puppet-ovirt
I've been reading about puppet, and am considering it.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
