Example #1
0
 def __configure_vms(self, deployer, node_vm, basic = True, chef = True):
     nodes = node_vm.keys()
     mt_configure = MultiThread()
     topology = deployer.instance.topology
     order = topology.get_launch_order(nodes)
     
     threads = {}
     for nodeset in order:
         rest = dict([(n, deployer.NodeConfigureThread(mt_configure, 
                         "configure-%s" % n.id, 
                         n, 
                         node_vm[n], 
                         deployer, 
                         depends=threads.get(topology.get_depends(n)),
                         basic = basic,
                         chef = chef)) for n in nodeset])
         threads.update(rest)
     
     for thread in threads.values():
         mt_configure.add_thread(thread)
     
     mt_configure.run()
     if not mt_configure.all_success():
         message = self.__mt_exceptions_to_text(mt_configure.get_exceptions(), "Globus Provision was unable to configure the instances.")
         return (False, message)
     
     return (True, "Success")
Example #2
0
    def __stop_vms(self, deployer, nodes):
        node_vm = deployer.get_node_vm(nodes)
        topology = deployer.instance.topology
        mt_configure = MultiThread()        
        order = topology.get_launch_order(nodes)

        for n in node_vm:
            n.state = Node.STATE_STOPPING
        topology.save()
        
        threads = {}
        for node in order:
            threads[node] = deployer.NodeConfigureThread(mt_configure, 
                                                         "stop-configure-%s" % node.id, 
                                                         node, 
                                                         node_vm[node], 
                                                         deployer, 
                                                         depends=[threads[t] for t in topology.get_depends(node)])            

        for thread in threads.values():
            mt_configure.add_thread(thread)
        
        mt_configure.run()
        if not mt_configure.all_success():
            message = self.__mt_exceptions_to_text(mt_configure.get_exceptions(), "Globus Provision was unable to configure the instances.")
            return (False, message)        
        
        order.reverse()
        for node in order:
            deployer.stop_vms([node])
        
        log.debug("Waiting for instances to stop.")
        mt_instancewait = MultiThread()
        for node, vm in node_vm.items():
            mt_instancewait.add_thread(deployer.NodeWaitThread(mt_instancewait, "wait-%s" % str(vm), node, vm, deployer, state = Node.STATE_STOPPED))
        
        mt_instancewait.run()
        if not mt_instancewait.all_success():
            message = self.__mt_exceptions_to_text(mt_instancewait.get_exceptions(), "Exception raised while waiting for instances.")
            return (False, message)     
            
        return (True, "Success")
Example #3
0
    def __allocate_vms(self, deployer, nodes, resuming):
        # TODO: Make this an option
        sequential = False
        topology = deployer.instance.topology
        
        if not resuming:
            log.info("Allocating %i VMs." % len(nodes))
            next_state = Node.STATE_RUNNING_UNCONFIGURED
        else:
            log.info("Resuming %i VMs" % len(nodes))
            next_state = Node.STATE_RESUMED_UNCONFIGURED
        node_vm = {}
        for n in nodes:
            try:
                if not resuming:
                    n.set_property("state", Node.STATE_STARTING)
                    topology.save()
                    vm = deployer.allocate_vm(n)
                else:
                    n.set_property("state", Node.STATE_RESUMING)
                    topology.save()
                    vm = deployer.resume_vm(n)
                node_vm[n] = vm
            except Exception:
                message = self.__unexpected_exception_to_text()
                return (False, message, None)
        
            if sequential:
                log.debug("Waiting for instance to start.")
                wait = deployer.NodeWaitThread(None, "wait-%s" % str(vm), n, vm, deployer, state = next_state)
                wait.run2()
                
        if not sequential:        
            log.debug("Waiting for instances to start.")
            mt_instancewait = MultiThread()
            for node, vm in node_vm.items():
                mt_instancewait.add_thread(deployer.NodeWaitThread(mt_instancewait, "wait-%s" % str(vm), node, vm, deployer, state = next_state))

            mt_instancewait.run()
            if not mt_instancewait.all_success():
                message = self.__mt_exceptions_to_text(mt_instancewait.get_exceptions(), "Exception raised while waiting for instances.")
                return (False, message, None)
            
        return (True, "Success", node_vm)
Example #4
0
    def __terminate_vms(self, deployer, nodes):
        topology = deployer.instance.topology

        deployer.terminate_vms(nodes)
        
        node_vm = deployer.get_node_vm(nodes)
        
        log.debug("Waiting for instances to terminate.")
        mt_instancewait = MultiThread()
        for node, vm in node_vm.items():
            mt_instancewait.add_thread(deployer.NodeWaitThread(mt_instancewait, "wait-%s" % str(vm), node, vm, deployer, state = Node.STATE_TERMINATED))
        
        mt_instancewait.run()
        if not mt_instancewait.all_success():
            message = self.__mt_exceptions_to_text(mt_instancewait.get_exceptions(), "Exception raised while waiting for instances.")
            return (False, message)
            
        return (True, "Success")
        
        
Example #5
0
 def __stop_vms(self, deployer, nodes):
     topology = deployer.instance.topology
     order = topology.get_launch_order(nodes)
     order.reverse()
     
     for nodeset in order:
         deployer.stop_vms(nodeset)
     
     node_vm = deployer.get_node_vm(nodes)
     
     log.debug("Waiting for instances to stop.")
     mt_instancewait = MultiThread()
     for node, vm in node_vm.items():
         mt_instancewait.add_thread(deployer.NodeWaitThread(mt_instancewait, "wait-%s" % str(vm), node, vm, deployer, state = Node.STATE_STOPPED))
     
     mt_instancewait.run()
     if not mt_instancewait.all_success():
         message = self.__mt_exceptions_to_text(mt_instancewait.get_exceptions(), "Exception raised while waiting for instances.")
         return (False, message)
         
     return (True, "Success")