Beispiel #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
	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()
	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()