mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
parent
c231e2bbf1
commit
2a159c06c5
@ -36,7 +36,8 @@ log = logging.getLogger(__name__)
|
|||||||
class Node:
|
class Node:
|
||||||
# This properties are used only on controller and are not forwarded to the compute
|
# This properties are used only on controller and are not forwarded to the compute
|
||||||
CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "width", "height", "symbol", "label", "console_host",
|
CONTROLLER_ONLY_PROPERTIES = ["x", "y", "z", "width", "height", "symbol", "label", "console_host",
|
||||||
"port_name_format", "first_port_name", "port_segment_size", "ports"]
|
"port_name_format", "first_port_name", "port_segment_size", "ports",
|
||||||
|
"category"]
|
||||||
|
|
||||||
def __init__(self, project, compute, name, node_id=None, node_type=None, **kwargs):
|
def __init__(self, project, compute, name, node_id=None, node_type=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -90,11 +91,14 @@ class Node:
|
|||||||
# Update node properties with additional elements
|
# Update node properties with additional elements
|
||||||
for prop in kwargs:
|
for prop in kwargs:
|
||||||
if prop not in ignore_properties:
|
if prop not in ignore_properties:
|
||||||
try:
|
if hasattr(self, prop):
|
||||||
setattr(self, prop, kwargs[prop])
|
try:
|
||||||
except AttributeError as e:
|
setattr(self, prop, kwargs[prop])
|
||||||
log.critical("Can't set attribute %s", prop)
|
except AttributeError as e:
|
||||||
raise e
|
log.critical("Can't set attribute %s", prop)
|
||||||
|
raise e
|
||||||
|
else:
|
||||||
|
self.properties[prop] = kwargs[prop]
|
||||||
|
|
||||||
if self._symbol is None:
|
if self._symbol is None:
|
||||||
self.symbol = ":/symbols/computer.svg"
|
self.symbol = ":/symbols/computer.svg"
|
||||||
|
@ -81,6 +81,18 @@ def test_name(compute, project):
|
|||||||
assert node.name == "PC2"
|
assert node.name == "PC2"
|
||||||
|
|
||||||
|
|
||||||
|
def test_vmname(compute, project):
|
||||||
|
"""
|
||||||
|
Additionnal properties should add to the properties
|
||||||
|
field
|
||||||
|
"""
|
||||||
|
node = Node(project, compute, "PC",
|
||||||
|
node_id=str(uuid.uuid4()),
|
||||||
|
node_type="virtualbox",
|
||||||
|
vmname="test")
|
||||||
|
assert node.properties["vmname"] == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_eq(compute, project, node, controller):
|
def test_eq(compute, project, node, controller):
|
||||||
assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")
|
assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")
|
||||||
assert node != "a"
|
assert node != "a"
|
||||||
|
Loading…
Reference in New Issue
Block a user