From 818174824b3bb8da1ed33af30fbd9412fb6acea2 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 1 Jul 2016 14:37:59 +0200 Subject: [PATCH] Breaking change for 2.X topologies! Store width and height for nodes & a style properties --- gns3server/controller/node.py | 41 ++++++++++++++++++++++++++--------- gns3server/schemas/label.py | 24 ++++++++++---------- gns3server/schemas/node.py | 8 +++++++ tests/controller/test_node.py | 6 +++-- 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index 16141a73..bab78218 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -59,16 +59,17 @@ class Node: self._command_line = None self._node_directory = None self._status = "stopped" + self._width = 70 + self._height = 70 self._x = 0 self._y = 0 self._z = 0 self._symbol = ":/symbols/computer.svg" self._label = { - "color": "#ff000000", - "y": -25.0, + "y": -25, "text": "", - "font": "TypeWriter,10,-1,5,75,0,0,0,0,0", - "x": -17.0234375 + "style": "", + "x": -17 } # Update node properties with additional elements for prop in kwargs: @@ -164,6 +165,22 @@ class Node: def z(self, val): self._z = val + @property + def width(self): + return self._width + + @width.setter + def width(self, val): + self._width = val + + @property + def height(self): + return self._height + + @height.setter + def height(self, val): + self._height = val + @property def symbol(self): return self._symbol @@ -396,9 +413,11 @@ class Node: "console_type": self._console_type, "properties": self._properties, "label": self._label, - "x": int(self._x), - "y": int(self._y), - "z": int(self._z), + "x": self._x, + "y": self._y, + "z": self._z, + "width": self._width, + "height": self._height, "symbol": self._symbol } return { @@ -415,8 +434,10 @@ class Node: "properties": self._properties, "status": self._status, "label": self._label, - "x": int(self._x), - "y": int(self._y), - "z": int(self._z), + "x": self._x, + "y": self._y, + "z": self._z, + "width": self._width, + "height": self._height, "symbol": self._symbol } diff --git a/gns3server/schemas/label.py b/gns3server/schemas/label.py index 84719dd2..44b309b9 100644 --- a/gns3server/schemas/label.py +++ b/gns3server/schemas/label.py @@ -18,19 +18,19 @@ LABEL_OBJECT_SCHEMA = { "type": "object", "properties": { - "color": { - "type": "string", - "pattern": "^#[0-9a-f]{6,8}$" - }, - "font": { - "type": "string", - "minLength": 1 - }, "text": {"type": "string"}, - "x": {"type": "number"}, - "y": {"type": "number"}, - "z": {"type": "number"}, - "rotation": {"type": "number"} + "style": { + "description": "SVG style attribute", + "type": "string" + }, + "x": { + "description": "Relative X position of the label", + "type": "integer" + }, + "y": { + "description": "Relative Y position of the label", + "type": "integer" + }, }, "required": [ "text", diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index 5cf2653f..c75aaa90 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -144,6 +144,14 @@ NODE_OBJECT_SCHEMA = { "type": "string", "minLength": 1 }, + "width": { + "description": "Width of the node", + "type": "integer" + }, + "height": { + "description": "Height of the node", + "type": "integer" + }, "x": { "description": "X position of the node", "type": "integer" diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index c431c9fa..426a2ee8 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -67,6 +67,8 @@ def test_json(node, compute): "x": node.x, "y": node.y, "z": node.z, + "width": node.width, + "height": node.height, "symbol": node.symbol, "label": node.label } @@ -81,6 +83,8 @@ def test_json(node, compute): "x": node.x, "y": node.y, "z": node.z, + "width": node.width, + "height": node.height, "symbol": node.symbol, "label": node.label } @@ -186,7 +190,6 @@ def test_update_properties(node, compute, project, async_run, controller): controller._notification.emit.assert_called_with("node.updated", node_notif) - def test_update_only_controller(node, controller, compute, project, async_run): """ When updating property used only on controller we don't need to @@ -206,7 +209,6 @@ def test_update_only_controller(node, controller, compute, project, async_run): assert not controller._notification.emit.called - def test_update_no_changes(node, compute, project, async_run): """ We don't call the compute node if all compute properties has not changed