Esempio n. 1
0
    def getActionInstance(servers_slivers,projectName,sliceName):
	provisioningRSpecs = list()
	rspec = XmlHelper.getSimpleActionQuery()
	actionClassEmpty = copy.deepcopy(rspec.query.provisioning.action[0])
        actionClassEmpty.type_ = "create"
        rspec.query.provisioning.action.pop()
        default_action = rspec.query.provisioning.action
        for vms in servers_slivers:
	    server_id = vms['component_id']
	    for vm in vms['slivers']:
                if "interfaces" not in vm.keys():
                    vm['interfaces'] = None
		server = VTServer.objects.get(uuid = server_id)
	        VMSfaManager.setDefaultVMParameters(vm,server,projectName,sliceName)
		actionClass = copy.deepcopy(actionClassEmpty)
                actionClass.id = uuid.uuid4()
                Translator.VMdictToClass(vm, actionClass.server.virtual_machines[0])
		Translator.VMdicIfacesToClass(vm['interfaces'],actionClass.server.virtual_machines[0].xen_configuration.interfaces)
                actionClass.server.uuid = server_id
                actionClass.server.virtualization_type = server.getVirtTech()
                rspec.query.provisioning.action = [actionClass]
		provisioningRSpecs.append(copy.deepcopy(rspec.query.provisioning))
                

	return provisioningRSpecs
Esempio n. 2
0
 def get_action_instance(self, reservation):
     rspec = XmlHelper.getSimpleActionQuery()
     actionClass = copy.deepcopy(rspec.query.provisioning.action[0])
     actionClass.type_ = "create"
     rspec.query.provisioning.action.pop()
     #server = reservation.server()
     server = reservation.server
     vm = self.get_default_vm_parameters(reservation)
     actionClass.id = uuid.uuid4()
     self.vm_dict_to_class(vm, actionClass.server.virtual_machines[0])
     self.vm_dict_ifaces_to_class(vm["interfaces"],actionClass.server.virtual_machines[0].xen_configuration.interfaces)
     actionClass.server.uuid = server.uuid
     actionClass.server.virtualization_type = server.getVirtTech()
     rspec.query.provisioning.action.append(actionClass)
     return rspec.query.provisioning
Esempio n. 3
0
	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:
				ProvisioningDispatcher.logger.debug("virtualization_type = " + action.server.virtualization_type)
				controller = VTDriver.getDriver(action.server.virtualization_type)
				
				#XXX:Change this when xml schema is updated
				ProvisioningDispatcher.logger.debug("XXX action.server.uuid = " + str(action.server.uuid))
				server = VTDriver.getServerByUUID(action.server.uuid)
				ProvisioningDispatcher.logger.debug("server.id = " + str(server.id))
				#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)) )
				logging.debug("PROVISIONING FINISHED...")
				return
			except Exception as e:
				logging.warn(traceback.format_exc())
				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...")
		return
Esempio n. 4
0
    def prepare_vm_class(self):
        rspec = XmlHelper.getSimpleActionQuery()
	actionClassEmpty = copy.deepcopy(rspec.query.provisioning.action[0])
        actionClassEmpty.type_ = "create"
        rspec.query.provisioning.action.pop()
        return actionClassEmpty.server.virtual_machines[0]