Commit 00e14db7 authored by Antoine Millet's avatar Antoine Millet
Browse files

Now wait for the VM to be registered after an allocation

parent bbf57926
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
# along with CloudControl.  If not, see <http://www.gnu.org/licenses/>.


import time
import threading

from cloudcontrol.common.jobs import Job
@@ -32,6 +33,8 @@ class AllocationJob(Job):
    """ Allocate a set of VM on hypervisors.
    """

    WAIT_RETRY = 20

    # Global allocation lock. Must be locked before to do allocation for a
    # single virtual machine:
    allocation_lock = threading.Lock()
@@ -72,6 +75,13 @@ class AllocationJob(Job):
                        self.logger.info('VM %s: spawned on %s' % (vmspec['title'], target_hv_name))
                        results_by_vm[vmspec['title']] = 'spawned %s on %s' % (vm_uuid, target_hv_name)

                    # Wait for the new VM to appear on the server:
                    for _ in xrange(self.WAIT_RETRY):
                        if server.list('uuid=%s' % vm_uuid):
                            self.logger.info('VM %s: has been registered' % vmspec['title'])
                            break
                        time.sleep(1)

        # Write a summary of the Allocation job in the results attachment:
        results = self.attachment('results')
        for vm_name, result in results_by_vm.iteritems():