Beispiel #1
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)
Beispiel #2
0
	def _destroyDev(self):
		host = self.host
		vmid = self.getVmid()
		if not host:
			return
		if vmid:
			state = vzctl.getState(host, vmid)
			if state == State.STARTED:
				vzctl.stop(host, vmid)
				state = vzctl.getState(host, vmid)
			if state == State.PREPARED:
				vzctl.destroy(host, vmid)
				state = vzctl.getState(host, vmid)
			assert state == State.CREATED
			self.state = State.CREATED
			self.save()
			self._unassignVmid()
		self._unassignBridges()
		self._unassignHost()
Beispiel #3
0
	def _prepareDev(self):
		#assign host
		self._assignHost()
		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 = vzctl.getState(host, vmid)
		if state == State.STARTED:
			vzctl.stop(host, vmid)
			state = vzctl.getState(host, vmid)
		if state == State.PREPARED:
			vzctl.destroy(host, vmid)
			state = vzctl.getState(host, vmid)
		assert state == State.CREATED
		
		#nothing happened until here
		
		vzctl.create(host, vmid, self.getTemplate())
		try:
			self._configureVm()
			for iface in self.interfaceSetAll():
				vzctl.addInterface(host, vmid, iface.name)
			self.state = State.PREPARED
			self.save()
		except:
			try:
				vzctl.destroy(host, vmid)
			except:
				pass
			raise
Beispiel #4
0
	def _destroyVm(self):
		if self.host:
			vzctl.destroy(self.host, self.getVmid())