def configure(self, properties): if self.state != State.CREATED: fault.check(not "network_type" in properties, "Cannot change type of external network with prepared connections: %s", self.name) fault.check(not "network_group" in properties, "Cannot change group of external network with prepared connections: %s", self.name) Connector.configure(self, properties) if self.getNetworkGroup() == "auto": self.setNetworkGroup(None) self.save()
def getPrepareTasks(self): taskset = Connector.getPrepareTasks(self) assign_resources = tasks.Task("assign-resources", self._assignResources) tinc_tasks = tinc.getPrepareNetworkTasks(self._endpoints(), self.type) tinc_tasks.after(assign_resources) taskset.add([assign_resources, tinc_tasks]) return self._adaptTaskset(taskset)
def getDestroyTasks(self): taskset = Connector.getDestroyTasks(self) tinc_tasks = tinc.getDestroyNetworkTasks(self._endpoints(), self.mode) unassign_resources = tasks.Task("destroy-bridges", self._unassignResources, after=tinc_tasks) taskset.add([tinc_tasks, unassign_resources]) taskset.add(tasks.Task("destroy-external-access", self._destroyExternalAccess)) return self._adaptTaskset(taskset)
def getStopTasks(self): taskset = Connector.getStopTasks(self) taskset.add(tinc.getStopNetworkTasks(self._endpoints(), self.mode)) for con in self.connectionSetAll(): taskset.add(con.upcast().getStopTasks().prefix(con)) taskset.add(tasks.Task("stop-external-access", self._stopExternalAccess)) return self._adaptTaskset(taskset)
def getCapabilities(self, user): capabilities = Connector.getCapabilities(self, user) capabilities["configure"].update({ "network_type": self.state == State.CREATED, "network_group": self.state == State.CREATED, }) return capabilities
def getPrepareTasks(self): taskset = Connector.getPrepareTasks(self) assign_resources = tasks.Task("assign-resources", self._assignResources) tinc_tasks = tinc.getPrepareNetworkTasks(self._endpoints(), self.mode) tinc_tasks.after(assign_resources) taskset.add([assign_resources, tinc_tasks]) taskset.add(tasks.Task("prepare-external-access", self._prepareExternalAccess)) return self._adaptTaskset(taskset)
def _runAction(self, action, attrs, direct): if action == "download_capture": interface = self.topology.interfacesGet(attrs["iface"]) fault.check(interface, "No such interface: %s", attrs["iface"]) con = interface.connection.upcast() assert con.connector.id == self.id return con.downloadCaptureUri() else: return Connector._runAction(self, action, attrs, direct)
def _runAction(self, action, attrs, direct): if action == "download_capture": interface = self.topology.interfacesGet(attrs["iface"]) fault.check(interface, "No such interface: %s", attrs["iface"]) con = interface.connection.upcast() assert con.connector.id == self.id return tasks.runTask(tasks.Task("%s-download-capture-uri" % self, con.downloadCaptureUri, kwargs={"onlyLatest": "onlyLatest" in attrs and attrs["onlyLatest"]})) else: return Connector._runAction(self, action, attrs, direct)
def getStartTasks(self): taskset = Connector.getStartTasks(self) tinc_tasks = tinc.getStartNetworkTasks(self._endpoints(), self.type) taskset.add(tinc_tasks) for con in self.connectionSetAll(): ts = con.upcast().getStartTasks() ts.prefix(con).after(tinc_tasks) taskset.add(ts) return self._adaptTaskset(taskset)
def toDict(self, auth): res = Connector.toDict(self, auth) res["attrs"].update(external_access=self.getExternalAccess(), mode=self.mode) if auth: if self.getExternalAccess(): if self.getExternalAccessPort(): res["attrs"]["external_access_host"] = self.getExternalAccessHost().name res["attrs"]["external_access_port"] = self.getExternalAccessPort() res["attrs"]["external_access_password"] = self.getExternalAccessPassword() return res
def getCapabilities(self, user): capabilities = Connector.getCapabilities(self, user) capabilities["configure"].update({ "external_access": self.state == State.CREATED, }) capabilities["action"].update({ "download_capture": self.state != State.CREATED, }) capabilities.update(other={ "external_access": self.state == State.STARTED and self.getExternalAccess() }) return capabilities
def getStartTasks(self): taskset = Connector.getStartTasks(self) tinc_tasks = tinc.getStartNetworkTasks(self._endpoints(), self.mode) taskset.add(tinc_tasks) tinc_tasks_dummy = tasks.Task("tinc_started") tinc_tasks_dummy.after(tinc_tasks) taskset.add(tinc_tasks_dummy) for con in self.connectionSetAll(): ts = con.upcast().getStartTasks() ts.prefix(con).after(tinc_tasks_dummy) taskset.add(ts) taskset.add(tasks.Task("start-external-access", self._startExternalAccess)) return self._adaptTaskset(taskset)
def getPrepareTasks(self): taskset = Connector.getPrepareTasks(self) taskset.add(tasks.Task("select-network", self._selectUsedNetwork)) return self._adaptTaskset(taskset)
def getCapabilities(self, user): capabilities = Connector.getCapabilities(self, user) capabilities["action"].update({ "download_capture": self.state != State.CREATED, }) return capabilities
def getDestroyTasks(self): taskset = Connector.getDestroyTasks(self) tinc_tasks = tinc.getDestroyNetworkTasks(self._endpoints(), self.type) unassign_resources = tasks.Task("unassign-resources", self._unassignResources, after=tinc_tasks) taskset.add([tinc_tasks, unassign_resources]) return self._adaptTaskset(taskset)
def configure(self, properties): Connector.configure(self, properties)
def configure(self, properties): Connector.configure(self, properties) if "external_access" in properties: self.setExternalAccess(properties["external_access"]) if "mode" in properties: self.setMode(properties["mode"])
def getStopTasks(self): taskset = Connector.getStopTasks(self) taskset.add(tinc.getStopNetworkTasks(self._endpoints(), self.type)) for con in self.connectionSetAll(): taskset.add(con.upcast().getStopTasks().prefix(con)) return self._adaptTaskset(taskset)
def toDict(self, auth): res = Connector.toDict(self, auth) res["attrs"].update(network_type=self.network_type, network_group=self.network_group) return res
def getIdUsage(self, host): ids = Connector.getIdUsage(self, host) if self.getExternalAccessHost() == host: ids["port"] = ids.get("port", set()) | set((self.getExternalAccessPort(),)) return ids
def getDestroyTasks(self): taskset = Connector.getDestroyTasks(self) taskset.add(tasks.Task("unselect-network", self._unselectUsedNetwork)) return self._adaptTaskset(taskset)