def cxm_deactivate(cluster, vm, options): """Deactivate the logicals volumes of the specified VM. If options.node is not given, use local node. """ if options.node: node=cluster.get_node(options.node) else: node=cluster.get_local_node() if not core.cfg['QUIET'] : print "Deactivating LVs of",vm,"on",node.get_hostname(),"..." node.deactivate_lv(vm)
def activate_vm(self, selected_node, vmname): """Activate all the LVM logicals volumes of the specified VM exclusively on the selected node. selected_node - (Node) Node where to activate the LVs vmname - (String) hostname of the vm Raise a ClusterNodeError if the VM is running. """ for node in self.get_nodes(): if node.is_vm_started(vmname): raise ClusterNodeError(node.get_hostname(), ClusterNodeError.VM_RUNNING, vmname) else: node.deactivate_lv(vmname) selected_node.activate_lv(vmname)
def start_vm(self, node, vmname, console): """Start the specified VM on the given node. If there is not enough ram on the given node, the VM will be started on the node with the highest free ram and the autostart link will be updated accordingly. node - (Node) Selected host vmname - (String) VM hostname console - (boolean) Attach console to the domain """ # Resources checks needed_ram = vm.VM(vmname).get_ram() free_ram = node.metrics.get_free_ram() if needed_ram > free_ram: # Not enough ram, switching to another node old_node = node # Get the node with the highest free ram (first fit increasing algorithm) pool = self.get_nodes() pool.sort(key=lambda x: x.metrics.get_free_ram(), reverse=True) node = pool[0] # Last resources checks free_ram = node.metrics.get_free_ram() if needed_ram > free_ram: raise ClusterNodeError( node.get_hostname(), ClusterNodeError.NOT_ENOUGH_RAM, "need " + str(needed_ram) + "M, has " + str(free_ram) + "M.") if not core.cfg['QUIET']: print " -> Not enough ram, starting it on %s." % node.get_hostname( ) # Start the VM self.activate_vm(node, vmname) try: node.start_vm(vmname) except Exception, e: node.deactivate_lv(vmname) raise e
def start_vm(self, node, vmname, console): """Start the specified VM on the given node. If there is not enough ram on the given node, the VM will be started on the node with the highest free ram and the autostart link will be updated accordingly. node - (Node) Selected host vmname - (String) VM hostname console - (boolean) Attach console to the domain """ # Resources checks needed_ram = vm.VM(vmname).get_ram() free_ram = node.metrics.get_free_ram() if needed_ram > free_ram: # Not enough ram, switching to another node old_node = node # Get the node with the highest free ram (first fit increasing algorithm) pool = self.get_nodes() pool.sort(key=lambda x: x.metrics.get_free_ram(), reverse=True) node = pool[0] # Last resources checks free_ram = node.metrics.get_free_ram() if needed_ram > free_ram: raise ClusterNodeError( node.get_hostname(), ClusterNodeError.NOT_ENOUGH_RAM, "need " + str(needed_ram) + "M, has " + str(free_ram) + "M.", ) if not core.cfg["QUIET"]: print " -> Not enough ram, starting it on %s." % node.get_hostname() # Start the VM self.activate_vm(node, vmname) try: node.start_vm(vmname) except Exception, e: node.deactivate_lv(vmname) raise e