コード例 #1
0
	def startDomain(vm):
		#Getting connection
		conn = XendManager.__getConnection()

		with open(HdManager.getConfigFilePath(vm),'r') as openConfig: 
			xmlConf = conn.domainXMLFromNative('xen-xm', openConfig.read(), 0) 

		if XendManager.isVmRunning(vm.name) and not  XendManager.isVmRunningByUUID(vm.uuid):
			#Duplicated name; trying to find an Alias
			newVmName = XendManager.__findAliasForDuplicatedVmName(vm)
			subprocess.call(['/usr/sbin/xm','create','name='+newVmName,XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))])
		else:	
			try:
				#Try first using libvirt call
				#conn.createXML(xmlConf,0)
				raise Exception("Skip") #otherwise stop is ridicously slow
			except Exception as e:
				#Fallback solution; workarounds BUG that created wrong .conf files (extra spaces that libvirt cannot parse)
				subprocess.call(['/usr/sbin/xm','create',XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))])
			
		time.sleep(OXA_XEN_CREATE_WAIT_TIME)

		if not XendManager.isVmRunningByUUID(vm.uuid):
			#TODO: add more info to exception
			raise Exception("Could not start VM")
コード例 #2
0
    def startDomain(vm):
        #Getting connection
        conn = XendManager.__getConnection()

        with open(HdManager.getConfigFilePath(vm), 'r') as openConfig:
            xmlConf = conn.domainXMLFromNative('xen-xm', openConfig.read(), 0)

        #con = libvirt.open('xen:///')
        #dom = con.createLinux(xmlConf,0)

        if XendManager.isVmRunning(
                vm.name) and not XendManager.isVmRunningByUUID(vm.uuid):
            #Duplicated name; trying to find an Alias
            newVmName = XendManager.__findAliasForDuplicatedVmName(vm)
            command_list = [
                '/usr/sbin/xm', 'create', 'name=' + newVmName,
                XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))
            ]
            process = subprocess.Popen(command_list,
                                       shell=False,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            out, err = process.communicate()
        else:
            try:
                #Try first using libvirt call
                #XendManager.logger.warning('creating vm using python-libvirt methods')
                #XendManager.logger.warning(xmlConf)
                #conn.createXML(xmlConf,0)
                #XendManager.logger.warning(XendManager.sanitize_arg(HdManager.getConfigFilePath(vm)))
                #XendManager.logger.warning('created vm?')
                raise Exception("Skip")  #otherwise stop is ridicously slow
            except Exception as e:
                #Fallback solution; workarounds BUG that created wrong .conf files (extra spaces that libvirt cannot parse)
                command_list = [
                    '/usr/sbin/xm', 'create',
                    XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))
                ]
                process = subprocess.Popen(command_list,
                                           shell=False,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                out, err = process.communicate()

        time.sleep(OXA_XEN_CREATE_WAIT_TIME)

        if not XendManager.isVmRunningByUUID(vm.uuid):
            # Complete with other types of exceptions
            detailed_error = ""
            if "Not enough free memory" in err:
                detailed_error = " because there is not enough free memory in that server. Try another."
            raise Exception("Could not start VM%s" % detailed_error)
コード例 #3
0
	def startVM(id,vm):
		try:
			#Trigger	
			HdManager.startHook(vm)	
			XendManager.startDomain(vm)
	
			XenProvisioningDispatcher.logger.info("VM named "+vm.name+" has been started.")
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"SUCCESS","")
		except Exception as e:
			XenProvisioningDispatcher.logger.error(str(e))
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"FAILED",str(e))
			return
コード例 #4
0
    def __createParavirtualizationFileHdConfigFile(vm, env):
        template_name = "paraVirtualizedFileHd.pt"
        template = env.get_template(template_name)

        #Set vars&render
        output = template.render(kernelImg=OXA_XEN_SERVER_KERNEL,
                                 initrdImg=OXA_XEN_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()
コード例 #5
0
	def __createFullvirtualizationFileHdConfigFile(vm,env):
                template_name = "fullVirtualizedFileHd.pt"
                template = env.get_template(template_name)	

		#Set vars&render		
		output = template.render(
		kernelImg=OXA_XEN_SERVER_KERNEL,
		initrdImg=OXA_XEN_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()
コード例 #6
0
    def startVM(id, vm):
        try:
            #Trigger
            HdManager.startHook(vm)
            XendManager.startDomain(vm)

            XenProvisioningDispatcher.logger.info("VM named " + vm.name +
                                                  " has been started.")
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
コード例 #7
0
    def __createConfigFile(vm, env):
        template_name = "spirentSTCVMTemplate.pt"
        template = env.get_template(template_name)

        #Set vars&render
        output = template.render(
            kernelImg=OXA_XEN_SERVER_KERNEL,
            initrdImg=OXA_XEN_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()
コード例 #8
0
	def deleteVM(id,vm):
		try:
			try:
				#if it wasn't stopped, do it
				XendManager.stopDomain(vm)	
			except Exception as e:
				pass
			
			#Trigger Hd Deletion in Remote	
			HdManager.delete(vm)	

			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"SUCCESS","")
		except Exception as e:
			XenProvisioningDispatcher.logger.error(str(e))
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"FAILED",str(e))
			return
コード例 #9
0
    def deleteVM(id, vm):
        try:
            try:
                #if it wasn't stopped, do it
                XendManager.stopDomain(vm)
            except Exception as e:
                pass

            #Trigger Hd Deletion in Remote
            HdManager.delete(vm)

            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
コード例 #10
0
ファイル: XendManager.py プロジェクト: HalasNet/felix
	def startDomain(vm):
		#Getting connection
		conn = XendManager.__getConnection()

		with open(HdManager.getConfigFilePath(vm),'r') as openConfig: 
			xmlConf = conn.domainXMLFromNative('xen-xm', openConfig.read(), 0) 

		#con = libvirt.open('xen:///')
		#dom = con.createLinux(xmlConf,0)
				

		if XendManager.isVmRunning(vm.name) and not  XendManager.isVmRunningByUUID(vm.uuid):
			#Duplicated name; trying to find an Alias
			newVmName = XendManager.__findAliasForDuplicatedVmName(vm)
			command_list = ['/usr/sbin/xm', 'create', 'name=' + newVmName, XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))]
			process = subprocess.Popen(command_list, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
			out, err = process.communicate()
		else:	
			try:
				#Try first using libvirt call
				#XendManager.logger.warning('creating vm using python-libvirt methods')
                                #XendManager.logger.warning(xmlConf)
				#conn.createXML(xmlConf,0)
				#XendManager.logger.warning(XendManager.sanitize_arg(HdManager.getConfigFilePath(vm)))
                                #XendManager.logger.warning('created vm?')
				raise Exception("Skip") #otherwise stop is ridicously slow
			except Exception as e:
				#Fallback solution; workarounds BUG that created wrong .conf files (extra spaces that libvirt cannot parse)
				command_list = ['/usr/sbin/xm', 'create', XendManager.sanitize_arg(HdManager.getConfigFilePath(vm))]
				process = subprocess.Popen(command_list, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
				out, err = process.communicate()

		time.sleep(OXA_XEN_CREATE_WAIT_TIME)

		if not XendManager.isVmRunningByUUID(vm.uuid):
			# Complete with other types of exceptions
			detailed_error = ""
			if "Not enough free memory" in err:
				detailed_error = " because there is not enough free memory in that server. Try another."
			raise Exception("Could not start VM%s" % detailed_error)
コード例 #11
0
    def __createHVMFileHdConfigFile(vm, env):
        template_name = "mediacatHVMFileHd.pt"
        template = env.get_template(template_name)

        #Set vars&render
        output = template.render(kernelImg=OXA_XEN_SERVER_KERNEL,
                                 initrdImg=OXA_XEN_SERVER_INITRD,
                                 vm=vm)

        #write file
        cfile = open(HdManager.getConfigFilePath(vm), 'w')
        cfile.write(output)
        cfile.close()
コード例 #12
0
        def __createHVMFileHdConfigFile(vm,env):
                template_name = "mediacatHVMFileHd.pt"
                template = env.get_template(template_name)

                #Set vars&render
                output = template.render(
                kernelImg=OXA_XEN_SERVER_KERNEL,
                initrdImg=OXA_XEN_SERVER_INITRD,
                vm=vm)

                #write file
                cfile = open(HdManager.getConfigFilePath(vm),'w')
                cfile.write(output)
		cfile.close()
コード例 #13
0
    def createVMfromImage(id, vm):
        pathToMountPoint = ""
        XenProvisioningDispatcher.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)
            XenProvisioningDispatcher.logger.debug("HD cloned successfully...")

            #Mount copy
            pathToMountPoint = HdManager.mount(vm)
            XenProvisioningDispatcher.logger.debug("Mounting at:" +
                                                   pathToMountPoint)
            XenProvisioningDispatcher.logger.debug(
                "HD mounted successfully...")

            #Configure VM OS
            VMConfigurator.configureVmDisk(vm, pathToMountPoint)

            #Umount copy
            HdManager.umount(vm, pathToMountPoint)
            XenProvisioningDispatcher.logger.debug(
                "HD unmounted successfully...")

            #Synthesize config file
            VMConfigurator.createVmConfigurationFile(vm)
            XenProvisioningDispatcher.logger.debug(
                "XEN configuration file created successfully...")

            XenProvisioningDispatcher.logger.info("Creation of VM " + vm.name +
                                                  " has been successful!!")
            #Send async notification
            XmlRpcClient.sendAsyncProvisioningActionStatus(id, "SUCCESS", "")
        except Exception as e:
            XenProvisioningDispatcher.logger.error(str(e))
            #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):
                    XenProvisioningDispatcher.deleteVM(id, vm)
            except:
                pass
            XmlRpcClient.sendAsyncProvisioningActionStatus(
                id, "FAILED", str(e))
            return
コード例 #14
0
	def createVMfromImage(id,vm):
		pathToMountPoint = ""	
		XenProvisioningDispatcher.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)
			XenProvisioningDispatcher.logger.debug("HD cloned successfully...")
			
			#Mount copy
			pathToMountPoint=HdManager.mount(vm)
			XenProvisioningDispatcher.logger.debug("Mounting at:"+pathToMountPoint)
			XenProvisioningDispatcher.logger.debug("HD mounted successfully...")
			
			#Configure VM OS
			VMConfigurator.configureVmDisk(vm,pathToMountPoint)

			#Umount copy
			HdManager.umount(vm,pathToMountPoint)
			XenProvisioningDispatcher.logger.debug("HD unmounted successfully...")
	
			#Synthesize config file
			VMConfigurator.createVmConfigurationFile(vm)
			XenProvisioningDispatcher.logger.debug("XEN configuration file created successfully...")
			
			XenProvisioningDispatcher.logger.info("Creation of VM "+vm.name+" has been successful!!")
			#Send async notification
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"SUCCESS","")
		except Exception as e:
			XenProvisioningDispatcher.logger.error(str(e))
			#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):
					XenProvisioningDispatcher.deleteVM(id,vm)
			except:
				pass
			XmlRpcClient.sendAsyncProvisioningActionStatus(id,"FAILED",str(e))
			return