Exemplo n.º 1
0
Arquivo: common.py Projeto: m3z/ToMaTo
	def getVmid(self):
		res = resources.get(self, self.VMID_SLOT, "vmid")
		if res:
			return res.num
Exemplo n.º 2
0
Arquivo: openvz.py Projeto: m3z/ToMaTo
	def migrateRun(self, host=None):
		if self.state == State.CREATED:
			self._unassignHost()
			self._unassignVmid()
			return
		task = tasks.get_current_task()
		#save src data
		src_host = self.host
		src_vmid = resources.get(self, self.VMID_SLOT)
		#assign new host and vmid
		self.host = None
		if host:
			self.host = host
		else:
			self._assignHost()
		dst_host = self.host
		dst_vmid = resources.take(dst_host, "vmid", self, "migration")
		#reassign host and vmid
		self.host = src_host
		#destroy all connectors and save their state
		constates={}
		for iface in self.interfaceSetAll():
			if iface.isConnected():
				con = iface.connection.connector.upcast()
				if con.name in constates:
					continue
				constates[con.name] = con.state
				if con.state == State.STARTED:
					con.stop(True, noProcess=True)
				if con.state == State.PREPARED:
					con.destroy(True, noProcess=True)
		tasks.set_current_task(task)
		#actually migrate the vm
		if self.state == State.STARTED:
			self._stopVnc()
			try:
				self.state = State.PREPARED
				for iface in self.interfaceSetAll():
					if iface.isConnected():
						con = iface.connection.upcast()
						con.destroyBridge()
			finally:
				self.state = State.STARTED
		ifaces = map(lambda x: x.name, self.interfaceSetAll())
		try:
			vzctl.migrate(src_host, src_vmid.num, dst_host, dst_vmid.num, self.getTemplate(), ifaces)
		except:
			# reverted to SRC host
			if self.state == State.STARTED:
				self._startVnc()
			raise
		#switch host and vmid
		self.host = dst_host
		self.vmid = dst_vmid
		self.save()
		resources.give(self, self.VMID_SLOT)
		self.vmid.slot = self.VMID_SLOT
		self.vmid.save()
		self.save()
		self._configureVm()
		if self.state == State.STARTED:
			self._startVnc()			
		#redeploy all connectors
		for iface in self.interfaceSetAll():
			if iface.isConnected():
				con = iface.connection.connector.upcast()
				if not con.name in constates:
					continue
				state = constates[con.name]
				del constates[con.name]
				if state == State.PREPARED or state == State.STARTED:
					con.prepare(True, noProcess=True)
				if state == State.STARTED:
					con.start(True, noProcess=True)
				if self.state == State.STARTED:
					self.connectToBridge(iface, self.getBridge(iface))
Exemplo n.º 3
0
 def hasIfbId(self):
     return resources.get(self, self.IFB_ID_SLOT, "ifb_id")
Exemplo n.º 4
0
Arquivo: common.py Projeto: m3z/ToMaTo
	def getVncPort(self):
		res = resources.get(self, self.VNC_PORT_SLOT, "vnc_port")
		if res:
			return res.num
Exemplo n.º 5
0
 def getIfbId(self):
     res = resources.get(self, self.IFB_ID_SLOT, "ifb_id")
     if res:
         return res.num
Exemplo n.º 6
0
 def getLiveCapturePort(self):
     res = resources.get(self, self.LIVE_CAPTURE_PORT_SLOT, "live_capture_port")
     if res:
         return res.num
Exemplo n.º 7
0
Arquivo: vpn.py Projeto: m3z/ToMaTo
	def getExternalAccessHost(self):
		res = resources.get(self, self.EXTERNAL_ACCESS_PORT_SLOT, "external_access_port")
		if res:
			return res.getHost()
Exemplo n.º 8
0
Arquivo: vpn.py Projeto: m3z/ToMaTo
	def getBridgeHost(self):
		res = resources.get(self, self.BRIDGE_ID_SLOT, "bridge_id")
		if res:
			return res.getHost()
Exemplo n.º 9
0
Arquivo: vpn.py Projeto: m3z/ToMaTo
	def getTincHost(self):
		res = resources.get(self, self.TINC_PORT_SLOT, "tinc_port")
		if res:
			return res.getHost()