1

I have a vSphere farm with virtual machines and python script that handles cloning and managing of those VMs.

I also have a machine (RedHat 6) that I clone if I need a new one. It has a script that I need to launch after each clone operation so that this machine will get an IP address (static by writing IP in /etc/sysconfig/network-scripts/ifcfg-eth0), hostname etc etc.

So the procedure is as follows:

  • launch cloning script
  • wait in it until cloning finishes
  • start cloned VM
  • sleep X seconds
  • launch remotely ip_and_hostname_assigning_script.sh (stored on clone so in results on cloning this will be available on cloned VM as well) - This is like launching command via ssh (I remotely call script on cloned VM)

The issue here is that sometimes does not change/assign IP address (namely: it will assign hostname but not IP). I have although noticed than when I wait for e.g. 1 minute after initial start of this cloned VM everything works just fine.

The question is: until WHAT (event/log/file) can I wait (instead of sleep) to be sure that I can run this type of script?

EDIT

This is the flow:

+-----------------+                                                 
|template (clone) |                               +----------------+
+--------^--------+                               | Cloned machine |
         |                                        +---------^------+
         |                                                  |       
         | 2 Perform clone                   3 Run script   |       
         |    network interface is down       assigning IP  |       
         |    during cloning                 hostname etc   |       
         +-------------+--------------+                     |       
                       |              +---------------------+       
                       | vSphere farm |                             
                       |              |                             
                       +-------^------+                             
                               |                                    
                               | 1 Clone template to cloned machine 
                               |                                    
                    +----------+-----------+                        
                    | Machine with script  |                        
                    | managing the cloning |                        
                    +----------------------+                        
  • Isn't your procedure missing that you start the clone before you launch the ip_and_... script? Is that run from the cloning machine or after bootup? Why don't you just use DHCP on the host witch ip addresses/hostnames determined on the basis of the MAC address (which is known to the VMs host? – Anthon Feb 19 '15 at 13:56
  • The problem is that I have to keep track of IPs, and who is responsible for which one etc etc, like a register of VMs on a website. – Patryk Feb 19 '15 at 14:13
  • Is the system you're cloning running or not? Aren't you connecting to the original instead of the cloned system when running your ip_and_hostname_assigning_script.sh? Does the script bring the interfaces down and up again? – wurtel Feb 19 '15 at 15:36
  • @Patryk exactly that is what you can do by telling DHCP to take a particular IP address/hostname for a specific MAC address. Assuming of course you make the clones with a new MAC. – Anthon Feb 19 '15 at 15:43
  • @wurtel Check my update – Patryk Feb 19 '15 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.