示例#1
0
文件: kvm.py 项目: david-hock/ToMaTo
	def _startDev(self):
		host = self.host
		vmid = self.vmid
		state = qm.getState(host, vmid)
		if not self.getVncPort():
			self.host.takeId("port", self.setVncPort)
		if state == State.CREATED:
			self._prepareDev()
			state = qm.getState(host, vmid)
		for iface in self.interfaceSetAll():
			iface_id = int(re.match("eth(\d+)", iface.name).group(1))
			# qm automatically connects ethN to vmbrN
			# if this bridge does not exist, kvm start fails
			ifaceutil.bridgeCreate(host, "vmbr%d" % iface_id)
		try: 
			if state == State.PREPARED:
				qm.start(host, vmid)
			for iface in self.interfaceSetAll():
				qm.waitForInterface(host, vmid, iface.name)
				self.connectToBridge(iface, self.getBridge(iface))
			self._startVnc()
			self.state = State.STARTED
			self.save()
		except:
			try:
				qm.stop(host, vmid)
			except:
				pass
			raise
示例#2
0
	def _freeId(self, type, id):
		if type == "vmid":
			if qm.getState(self, id) == State.STARTED:
				qm.stop(self, id)
			if qm.getState(self, id) == State.PREPARED:
				qm.destroy(self, id)
			if vzctl.getState(self, id) == State.STARTED:
				vzctl.stop(self, id)
			if vzctl.getState(self, id) == State.PREPARED:
				vzctl.destroy(self, id)
		elif type == "port":
			process.killPortUser(self, id)
		elif type == "bridge":
			ifaceutil.bridgeRemove(self, "gbr_%d" % id, True, True)
示例#3
0
	def _realIdState(self, type, id):
		if type == "vmid":
			return qm.getState(self, id) != State.CREATED or vzctl.getState(self, id) != State.CREATED
		elif type == "port":
			return not process.portFree(self, id)
		elif type == "bridge":
			return ifaceutil.bridgeExists(self, "gbr_%d" % id) 
示例#4
0
文件: kvm.py 项目: david-hock/ToMaTo
	def interfaceDevice(self, iface):
		try:
			return qm.interfaceDevice(self.host, self.getVmid(), iface.name)
		except:
			self.state = qm.getState(self.host, self.getVmid())
			self.save()
			raise
示例#5
0
文件: kvm.py 项目: david-hock/ToMaTo
	def _destroyDev(self):
		host = self.host
		vmid = self.getVmid()
		if not host:
			return
		if vmid:
			state = qm.getState(host, vmid)
			if state == State.STARTED:
				qm.stop(host, vmid)
				state = qm.getState(host, vmid)
			if state == State.PREPARED:
				qm.destroy(host, vmid)
				state = qm.getState(host, vmid)
			assert state == State.CREATED
			self.state = State.CREATED			
			self.save()
			self._unassignVmid()
		self._unassignBridges()
		self._unassignHost()
示例#6
0
文件: kvm.py 项目: david-hock/ToMaTo
	def _prepareDev(self):
		#assign host
		if not self.host:
			self.host = self.hostOptions().best()
			fault.check(self.host, "No matching host found")
			self.save()		
		host = self.host
		
		self._assignTemplate()
		
		self._assignBridges()
		
		if not self.getVmid():
			self.host.takeId("vmid", self.setVmid)
			fault.check(self.getVmid(), "No free vmid")
		vmid = self.getVmid()
		
		state = qm.getState(host, vmid)
		if state == State.STARTED:
			qm.stop(host, vmid)
			state = qm.getState(host, vmid)
		if state == State.PREPARED:
			qm.destroy(host, vmid)
			state = qm.getState(host, vmid)
		assert state == State.CREATED
		
		#nothing happened until here
		
		qm.create(host, vmid)
		try:
			qm.useTemplate(host, vmid, self.getTemplate())
			self._configureVm()
			for iface in self.interfaceSetAll():
				qm.addInterface(host, vmid, iface.name)
			self.state = State.PREPARED
			self.save()
		except:
			try:
				qm.destroy(host, vmid)
			except:
				pass
			raise
示例#7
0
文件: kvm.py 项目: david-hock/ToMaTo
	def getState(self):
		if not self.getVmid() or not self.host:
			return State.CREATED
		return qm.getState(self.host, self.getVmid())