Author: Pekka Helenius Date: Sun, 22 Aug 2021 17:12:44 +0200 Subject: [PATCH] GNS3 Server: Link colors. Add link color support for GNS3 Server. --- a/gns3server/schemas/link.py +++ b/gns3server/schemas/link.py @@ -68,6 +68,27 @@ "type": "boolean", "description": "Suspend the link" }, + "link_style": { + "type": "object", + "description": "Link line style", + "items": { + "type": "object", + "properties": { + "color": { + "description": "Link line color", + "type": "string" + }, + "width": { + "description": "Link line width", + "type": "integer" + }, + "type": { + "description": "Link line type", + "type": "integer" + } + } + } + }, "filters": FILTER_OBJECT_SCHEMA, "capturing": { "description": "Read only property. True if a capture running on the link", --- a/gns3server/handlers/api/controller/link_handler.py +++ b/gns3server/handlers/api/controller/link_handler.py @@ -64,6 +64,8 @@ link = await project.add_link() if "filters" in request.json: await link.update_filters(request.json["filters"]) + if "link_style" in request.json: + await link.update_link_style(request.json["link_style"]) if "suspend" in request.json: await link.update_suspend(request.json["suspend"]) try: @@ -135,6 +137,8 @@ link = project.get_link(request.match_info["link_id"]) if "filters" in request.json: await link.update_filters(request.json["filters"]) + if "link_style" in request.json: + await link.update_link_style(request.json["link_style"]) if "suspend" in request.json: await link.update_suspend(request.json["suspend"]) if "nodes" in request.json: --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -905,6 +905,8 @@ link = await self.add_link(link_id=link_data["link_id"]) if "filters" in link_data: await link.update_filters(link_data["filters"]) + if "link_style" in link_data: + await link.update_link_style(link_data["link_style"]) for node_link in link_data.get("nodes", []): node = self.get_node(node_link["node_id"]) port = node.get_port(node_link["adapter_number"], node_link["port_number"]) --- a/gns3server/controller/link.py +++ b/gns3server/controller/link.py @@ -125,6 +125,8 @@ class Link: self._suspended = False self._filters = {} + self._link_style = {} + @property def filters(self): """ @@ -209,6 +211,12 @@ class Link: self._project.emit_notification("link.updated", self.__json__()) self._project.dump() + async def update_link_style(self, link_style): + if link_style != self._link_style: + self._link_style = link_style + self._project.emit_notification("link.updated", self.__json__()) + self._project.dump() + @property def created(self): """ @@ -446,6 +454,7 @@ class Link: "nodes": res, "link_id": self._id, "filters": self._filters, + "link_style": self._link_style, "suspend": self._suspended } return { @@ -457,5 +466,6 @@ class Link: "capture_file_path": self.capture_file_path, "link_type": self._link_type, "filters": self._filters, + "link_style": self._link_style, "suspend": self._suspended }