def sendUpdateVMs(server): #Recover from the client the list of active VMs obj = XmlHelper.getListActiveVMsQuery() #Create new Action action = ActionController.createNewAction(Action.MONITORING_SERVER_VMS_TYPE,Action.QUEUED_STATUS,server.getUUID(),"") obj.query.monitoring.action[0].id = action.getUUID() obj.query.monitoring.action[0].server.virtualization_type = server.getid = server.getVirtTech() XmlRpcClient.callRPCMethod(server.getAgentURL(),"send",UrlUtils.getOwnCallbackURL(),0,server.agentPassword,XmlHelper.craftXmlClass(obj))
def processProvisioning(provisioning): logging.debug("PROVISIONING STARTED...\n") for action in provisioning.action: actionModel = ActionController.ActionToModel(action,"provisioning") logging.debug("ACTION type: %s with id: %s" % (actionModel.type, actionModel.uuid)) try: RuleTableManager.Evaluate(action,RuleTableManager.getDefaultName()) except Exception as e: MAX_CHARS_ALLOWED = 200 XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action,str(e)[0:MAX_CHARS_ALLOWED-1]))) return None try: controller = VTDriver.getDriver(action.server.virtualization_type) #XXX:Change this when xml schema is updated server = VTDriver.getServerByUUID(action.server.uuid) #if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE: # server = VTDriver.getServerByUUID(action.virtual_machine.server_id) #else: # server = VTDriver.getVMbyUUID(action.virtual_machine.uuid).Server.get() except Exception as e: logging.error(e) raise e try: #PROVISIONING CREATE if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE: try: vm = ProvisioningDispatcher.__createVM(controller, actionModel, action) except: vm = None raise #PROVISIONING DELETE, START, STOP, REBOOT else : ProvisioningDispatcher.__deleteStartStopRebootVM(controller, actionModel, action) XmlRpcClient.callRPCMethod(server.getAgentURL() ,"send", UrlUtils.getOwnCallbackURL(), 1, server.getAgentPassword(),XmlHelper.craftXmlClass(XmlHelper.getSimpleActionQuery(action)) ) return except Exception as e: if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE: # If the VM creation was interrupted in the network # configuration, the created VM won't be returned try: if not vm: vm = controller.getVMbyUUID(action.server.virtual_machines[0].uuid) controller.deleteVM(vm) # Keep actions table up-to-date after each deletion actionModel.delete() except Exception as e: print "Could not delete VM. Exception: %s" % str(e) #XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action, str(e)))) logging.debug("PROVISIONING FINISHED...")
def sendUpdateVMs(server): #Recover from the client the list of active VMs obj = XmlHelper.getListActiveVMsQuery() #Create new Action action = ActionController.createNewAction( Action.MONITORING_SERVER_VMS_TYPE, Action.QUEUED_STATUS, server.getUUID(), "") obj.query.monitoring.action[0].id = action.getUUID() obj.query.monitoring.action[ 0].server.virtualization_type = server.getid = server.getVirtTech( ) XmlRpcClient.callRPCMethod(server.getAgentURL(), "send", UrlUtils.getOwnCallbackURL(), 0, server.agentPassword, XmlHelper.craftXmlClass(obj))
def processProvisioning(provisioning): logging.debug("PROVISIONING STARTED...\n") for action in provisioning.action: actionModel = ActionController.ActionToModel( action, "provisioning") logging.debug("ACTION type: %s with id: %s" % (actionModel.type, actionModel.uuid)) try: RuleTableManager.Evaluate(action, RuleTableManager.getDefaultName()) except Exception as e: a = str(e) if len(a) > 200: a = a[0:199] XmlRpcClient.callRPCMethod( threading.currentThread().callBackURL, "sendAsync", XmlHelper.craftXmlClass( XmlHelper.getProcessingResponse( Action.FAILED_STATUS, action, a))) # XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse('FAILED', action, 'You requested more than the 128Mbytes allowed for your project'))) return None try: controller = VTDriver.getDriver( action.server.virtualization_type) #XXX:Change this when xml schema is updated server = VTDriver.getServerByUUID(action.server.uuid) #if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE: # server = VTDriver.getServerByUUID(action.virtual_machine.server_id) #else: # server = VTDriver.getVMbyUUID(action.virtual_machine.uuid).Server.get() except Exception as e: logging.error(e) raise e try: #PROVISIONING CREATE if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE: try: vm = ProvisioningDispatcher.__createVM( controller, actionModel, action) except: vm = None raise #PROVISIONING DELETE, START, STOP, REBOOT else: ProvisioningDispatcher.__deleteStartStopRebootVM( controller, actionModel, action) XmlRpcClient.callRPCMethod( server.getAgentURL(), "send", UrlUtils.getOwnCallbackURL(), 1, server.getAgentPassword(), XmlHelper.craftXmlClass( XmlHelper.getSimpleActionQuery(action))) except Exception as e: if actionModel.getType( ) == Action.PROVISIONING_VM_CREATE_TYPE and vm: controller.deleteVM(vm) XmlRpcClient.callRPCMethod( threading.currentThread().callBackURL, "sendAsync", XmlHelper.craftXmlClass( XmlHelper.getProcessingResponse( Action.FAILED_STATUS, action, str(e)))) logging.debug("PROVISIONING FINISHED...")