def _stopCaptureViaNet(self): host = self.getHost() if self.getLiveCapturePort(): tcpdump.stopCaptureViaNet(host, self._captureName(), self.getLiveCapturePort()) self.live_capture_port = None self.save() resources.give(self, self.LIVE_CAPTURE_PORT_SLOT)
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))
def _unassignVmid(self): if self.getVmid(): self.vmid = None self.save() resources.give(self, self.VMID_SLOT)
def _unassignVncPort(self): if self.getVncPort(): self.vnc_port = None self.save() resources.give(self, self.VNC_PORT_SLOT)
def _unassignIfb(self): self.ifb_id = None self.save() resources.give(self, self.IFB_ID_SLOT)
def _unassignTincPort(self): if self.getTincPort(): self.tinc_port = None self.save() resources.give(self, self.TINC_PORT_SLOT)
def _unassignBridgeId(self): if self.getBridgeId(): self.bridge_id = None self.save() resources.give(self, self.BRIDGE_ID_SLOT)
def _unassignVtunData(self): if self.getExternalAccessPort(): self.external_access_port = None self.save() resources.give(self, self.EXTERNAL_ACCESS_PORT_SLOT)