Exemplo n.º 1
0
	def startDomain(vm):
		KVMManager.logger.info('startDomain ' + vm.name)
		# Getting connection
		conn = KVMManager.__getConnection()

		with open(HdManager.getConfigFilePath(vm), 'r') as openConfig: 
			xmlConf = openConfig.read()

		if KVMManager.isVmRunning(vm.name) and not KVMManager.isVmRunningByUUID(vm.uuid):
			# Duplicated name; trying to find an Alias
			newVmName = KVMManager.__findAliasForDuplicatedVmName(vm)
			xmlConf.replace("<name>"+ vm.name + "<\/name>", "<name>"+ newVmName + "<\/name>", 1)
			KVMManager.logger.warn("duplicate VM name, change VM name from " + vm.name
				+ " to " + newVmName)
		
		try:
			# Try first using libvirt call
			KVMManager.logger.info('creating vm using python-libvirt methods')
			KVMManager.logger.info(xmlConf)
			conn.createXML(xmlConf, 0)
			KVMManager.logger.info(KVMManager.sanitize_arg(HdManager.getConfigFilePath(vm)))
			KVMManager.logger.info('created vm')
			# raise Exception("Skip") #otherwise stop is ridiculously slow
		except Exception as e:
			KVMManager.logger.error(str(e))
			KVMManager.logger.error(traceback.format_exc())
			raise Exception(e)

		time.sleep(OXA_KVM_CREATE_WAIT_TIME)

		if not KVMManager.isVmRunningByUUID(vm.uuid):
			# Complete with other types of exceptions
			raise Exception("Could not start VM, abort")
		
		return
Exemplo n.º 2
0
	def hardStopVM(vmid, vm):
		try:
			# First stop domain
			KVMManager.stopDomain(vm)	
			HdManager.stopHook(vm)	
		
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been stopped.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		return
Exemplo n.º 3
0
	def rebootVM(vmid, vm):
		try:
			# Just try to reboot
			HdManager.rebootHook(vm)
			KVMManager.rebootDomain(vm)
	
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been rebooted.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		return
Exemplo n.º 4
0
	def __createConfigFile(vm, env):
		template_name = "kvm.template.xml"
		template = env.get_template(template_name)	

		# Set vars&render		
		output = template.render(vm_name=vm.name, vm_uuid=vm.uuid,
								vm_memory=vm.xen_configuration.memory_mb,
								vm_cpu=str(1),
								vm_imgfile=HdManager.getHdPath(vm),
								vm=vm)	
			
		# write file
		cfile = open(HdManager.getConfigFilePath(vm), 'w')
		cfile.write(output)
		cfile.close()
	def __createConfigFile(vm,env):
		template_name = "spirentSTCVMTemplate.pt"
		template = env.get_template(template_name)	

		#Set vars&render		
		output = template.render(
		kernelImg=OXA_KVM_SERVER_KERNEL,
		initrdImg=OXA_KVM_SERVER_INITRD,
		hdFilePath=HdManager.getHdPath(vm),
		#swapFilePath=HdManager.getSwapPath(vm),
		vm=vm)	
			
		#write file
		cfile = open(HdManager.getConfigFilePath(vm),'w')
		cfile.write(output)
		cfile.close()
Exemplo n.º 6
0
	def startVM(vmid, vm):
		KVMProvisioningDispatcher.logger.info("XXX startVM start")
		try:
			# Trigger	
			HdManager.startHook(vm)	
			KVMManager.startDomain(vm)
	
			KVMProvisioningDispatcher.logger.info("VM named " + vm.name + " has been started.")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		KVMProvisioningDispatcher.logger.info("XXX startVM end")
		return
Exemplo n.º 7
0
	def deleteVM(vmid, vm):
		try:
			try:
				# if it wasn't stopped, do it
				KVMManager.stopDomain(vm)	
			except Exception as e:
				pass
			
			# Trigger Hd Deletion in Remote	
			HdManager.delete(vm)	

			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			KVMProvisioningDispatcher.logger.exception("XXX")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		return
Exemplo n.º 8
0
	def __createHVMFileHdConfigFile(vm,env):
		template_name = "mediacatHVMFileHd.pt"
		template = env.get_template(template_name)
		#Set vars&render
		output = template.render(
								kernelImg=OXA_KVM_SERVER_KERNEL,
								initrdImg=OXA_KVM_SERVER_INITRD,
								vm=vm)

		#write file
		cfile = open(HdManager.getConfigFilePath(vm),'w')
		cfile.write(output)
		cfile.close()
Exemplo n.º 9
0
	def createVMfromImage(vmid, vm):
		KVMProvisioningDispatcher.logger.info("XXX createVMfromImage start")
		pathToMountPoint = ""	
		KVMProvisioningDispatcher.logger.info("Initiating creation process for VM: " + vm.name
											+ " under project: " + vm.project_id
											+ " and slice: " + vm.slice_id)
		try:
			# Clone HD
			HdManager.clone(vm)
			KVMProvisioningDispatcher.logger.debug("HD cloned successfully...")
			
			# Mount copy
			pathToMountPoint = HdManager.mount(vm)
			KVMProvisioningDispatcher.logger.debug("Mounting at: " + pathToMountPoint)
			KVMProvisioningDispatcher.logger.debug("HD mounted successfully...")
			
			# Configure VM OS
			VMConfigurator.configureVmDisk(vm, pathToMountPoint)

			# Umount copy
			HdManager.umount(vm, pathToMountPoint)
			KVMProvisioningDispatcher.logger.debug("HD unmounted successfully...")
	
			# Synthesize config file
			VMConfigurator.createVmConfigurationFile(vm)
			KVMProvisioningDispatcher.logger.debug("KVM configuration file created successfully...")
			
			KVMProvisioningDispatcher.logger.info("Creation of VM " + vm.name + " has been successful!!")
			# Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "SUCCESS", "")
		except Exception as e:
			KVMProvisioningDispatcher.logger.error(str(e))
			KVMProvisioningDispatcher.logger.error(traceback.format_exc())
			# Send async notification
			try:
				HdManager.umount(vm, pathToMountPoint)
			except:
				pass
			try:
				# Delete VM disc and conf file if the error is not due because
				# the VM already exists
				if not isinstance(e, VMalreadyExists):
					KVMProvisioningDispatcher.deleteVM(vmid, vm)
			except:
				pass
			XmlRpcClient.sendAsyncProvisioningActionStatus(vmid, "FAILED", str(e))
		KVMProvisioningDispatcher.logger.info("XXX createVMfromImage end")
		return