mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Shape => Drawing
This commit is contained in:
21 files changed
+181
-181
No files matched your search
@@ -19,19 +19,19 @@ import asyncio
|
||||
import uuid
|
||||
|
||||
|
||||
class Shape:
|
||||
class Drawing:
|
||||
"""
|
||||
Shape are visual element not used by the network emulation. Like
|
||||
Drawing are visual element not used by the network emulation. Like
|
||||
text, images, rectangle... They are pure SVG elements.
|
||||
"""
|
||||
|
||||
def __init__(self, project, shape_id=None, svg="<svg></svg>", x=0, y=0, z=0, rotation=0):
|
||||
def __init__(self, project, drawing_id=None, svg="<svg></svg>", x=0, y=0, z=0, rotation=0):
|
||||
self.svg = svg
|
||||
self._project = project
|
||||
if shape_id is None:
|
||||
if drawing_id is None:
|
||||
self._id = str(uuid.uuid4())
|
||||
else:
|
||||
self._id = shape_id
|
||||
self._id = drawing_id
|
||||
self._x = x
|
||||
self._y = y
|
||||
self._z = z
|
||||
@@ -84,9 +84,9 @@ class Shape:
|
||||
@asyncio.coroutine
|
||||
def update(self, **kwargs):
|
||||
"""
|
||||
Update the shape
|
||||
Update the drawing
|
||||
|
||||
:param kwargs: Shape properties
|
||||
:param kwargs: Drawing properties
|
||||
"""
|
||||
|
||||
# Update node properties with additional elements
|
||||
@@ -100,7 +100,7 @@ class Shape:
|
||||
data = self.__json__()
|
||||
if not svg_changed:
|
||||
del data["svg"]
|
||||
self._project.controller.notification.emit("shape.updated", data)
|
||||
self._project.controller.notification.emit("drawing.updated", data)
|
||||
self._project.dump()
|
||||
|
||||
def __json__(self, topology_dump=False):
|
||||
@@ -109,7 +109,7 @@ class Shape:
|
||||
"""
|
||||
if topology_dump:
|
||||
return {
|
||||
"shape_id": self._id,
|
||||
"drawing_id": self._id,
|
||||
"x": self._x,
|
||||
"y": self._y,
|
||||
"z": self._z,
|
||||
@@ -118,7 +118,7 @@ class Shape:
|
||||
}
|
||||
return {
|
||||
"project_id": self._project.id,
|
||||
"shape_id": self._id,
|
||||
"drawing_id": self._id,
|
||||
"x": self._x,
|
||||
"y": self._y,
|
||||
"z": self._z,
|
||||
@@ -127,4 +127,4 @@ class Shape:
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return "<gns3server.controller.Shape {}>".format(self._id)
|
||||
return "<gns3server.controller.Drawing {}>".format(self._id)
|
||||
@@ -24,7 +24,7 @@ import shutil
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from .node import Node
|
||||
from .shape import Shape
|
||||
from .drawing import Drawing
|
||||
from .topology import project_to_topology, load_topology
|
||||
from .udp_link import UDPLink
|
||||
from ..config import Config
|
||||
@@ -77,7 +77,7 @@ class Project:
|
||||
self._allocated_node_names = set()
|
||||
self._nodes = {}
|
||||
self._links = {}
|
||||
self._shapes = {}
|
||||
self._drawings = {}
|
||||
|
||||
# Create the project on demand on the compute node
|
||||
self._project_created_on_compute = set()
|
||||
@@ -266,42 +266,42 @@ class Project:
|
||||
return self._nodes
|
||||
|
||||
@property
|
||||
def shapes(self):
|
||||
def drawings(self):
|
||||
"""
|
||||
:returns: Dictionary of the shapes
|
||||
:returns: Dictionary of the drawings
|
||||
"""
|
||||
return self._shapes
|
||||
return self._drawings
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_shape(self, shape_id=None, **kwargs):
|
||||
def add_drawing(self, drawing_id=None, **kwargs):
|
||||
"""
|
||||
Create an shape or return an existing shape
|
||||
Create an drawing or return an existing drawing
|
||||
|
||||
:param kwargs: See the documentation of shape
|
||||
:param kwargs: See the documentation of drawing
|
||||
"""
|
||||
if shape_id not in self._shapes:
|
||||
shape = Shape(self, shape_id=shape_id, **kwargs)
|
||||
self._shapes[shape.id] = shape
|
||||
self.controller.notification.emit("shape.created", shape.__json__())
|
||||
if drawing_id not in self._drawings:
|
||||
drawing = Drawing(self, drawing_id=drawing_id, **kwargs)
|
||||
self._drawings[drawing.id] = drawing
|
||||
self.controller.notification.emit("drawing.created", drawing.__json__())
|
||||
self.dump()
|
||||
return shape
|
||||
return self._shapes[shape_id]
|
||||
return drawing
|
||||
return self._drawings[drawing_id]
|
||||
|
||||
def get_shape(self, shape_id):
|
||||
def get_drawing(self, drawing_id):
|
||||
"""
|
||||
Return the Shape or raise a 404 if the shape is unknown
|
||||
Return the Drawing or raise a 404 if the drawing is unknown
|
||||
"""
|
||||
try:
|
||||
return self._shapes[shape_id]
|
||||
return self._drawings[drawing_id]
|
||||
except KeyError:
|
||||
raise aiohttp.web.HTTPNotFound(text="Shape ID {} doesn't exist".format(shape_id))
|
||||
raise aiohttp.web.HTTPNotFound(text="Drawing ID {} doesn't exist".format(drawing_id))
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_shape(self, shape_id):
|
||||
shape = self.get_shape(shape_id)
|
||||
del self._shapes[shape.id]
|
||||
def delete_drawing(self, drawing_id):
|
||||
drawing = self.get_drawing(drawing_id)
|
||||
del self._drawings[drawing.id]
|
||||
self.dump()
|
||||
self.controller.notification.emit("shape.deleted", shape.__json__())
|
||||
self.controller.notification.emit("drawing.deleted", drawing.__json__())
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_link(self, link_id=None):
|
||||
@@ -397,8 +397,8 @@ class Project:
|
||||
node = self.get_node(node_link["node_id"])
|
||||
yield from link.add_node(node, node_link["adapter_number"], node_link["port_number"])
|
||||
|
||||
for shape_data in topology.get("shapes", []):
|
||||
shape = yield from self.add_shape(**shape_data)
|
||||
for drawing_data in topology.get("drawings", []):
|
||||
drawing = yield from self.add_drawing(**drawing_data)
|
||||
self._status = "opened"
|
||||
|
||||
def dump(self):
|
||||
|
||||
@@ -34,7 +34,7 @@ def project_to_topology(project):
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"shapes": []
|
||||
"drawings": []
|
||||
},
|
||||
"type": "topology",
|
||||
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||
@@ -47,8 +47,8 @@ def project_to_topology(project):
|
||||
data["topology"]["nodes"].append(node.__json__(topology_dump=True))
|
||||
for link in project.links.values():
|
||||
data["topology"]["links"].append(link.__json__(topology_dump=True))
|
||||
for shape in project.shapes.values():
|
||||
data["topology"]["shapes"].append(shape.__json__(topology_dump=True))
|
||||
for drawing in project.drawings.values():
|
||||
data["topology"]["drawings"].append(drawing.__json__(topology_dump=True))
|
||||
for compute in computes:
|
||||
if hasattr(compute, "__json__"):
|
||||
data["topology"]["computes"].append(compute.__json__(topology_dump=True))
|
||||
|
||||
Reference in new issue
Block a user