mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
nodes: per-node default credentials seeded from the template
Add default_username/default_password as controller-only node properties (the netmiko_device_type pattern): they are not sent to the compute, persist with the project topology and can be updated or cleared per node. Creating a node from a template seeds them from the template appliance metadata, and the metadata itself is dropped there so it never leaks into the node properties.
This commit is contained in:
5 files changed
+125
No files matched your search
@@ -58,6 +58,8 @@ class Node:
|
||||
"category",
|
||||
"console_auto_start",
|
||||
"netmiko_device_type",
|
||||
"default_username",
|
||||
"default_password",
|
||||
]
|
||||
|
||||
def __init__(self, project, compute, name, node_id=None, node_type=None, template_id=None, **kwargs):
|
||||
@@ -114,6 +116,8 @@ class Node:
|
||||
self._first_port_name = None
|
||||
self._console_auto_start = False
|
||||
self._netmiko_device_type = None
|
||||
self._default_username = None
|
||||
self._default_password = None
|
||||
|
||||
# This properties will be recomputed
|
||||
ignore_properties = ("width", "height", "hover_symbol")
|
||||
@@ -222,6 +226,22 @@ class Node:
|
||||
def netmiko_device_type(self, val):
|
||||
self._netmiko_device_type = val
|
||||
|
||||
@property
|
||||
def default_username(self):
|
||||
return self._default_username
|
||||
|
||||
@default_username.setter
|
||||
def default_username(self, val):
|
||||
self._default_username = val
|
||||
|
||||
@property
|
||||
def default_password(self):
|
||||
return self._default_password
|
||||
|
||||
@default_password.setter
|
||||
def default_password(self, val):
|
||||
self._default_password = val
|
||||
|
||||
@property
|
||||
def properties(self):
|
||||
return self._properties
|
||||
@@ -844,6 +864,8 @@ class Node:
|
||||
"console_type": self._console_type,
|
||||
"console_auto_start": self._console_auto_start,
|
||||
"netmiko_device_type": self._netmiko_device_type,
|
||||
"default_username": self._default_username,
|
||||
"default_password": self._default_password,
|
||||
"aux": self._aux,
|
||||
"aux_type": self._aux_type,
|
||||
"properties": self._properties,
|
||||
|
||||
@@ -584,6 +584,12 @@ class Project:
|
||||
default_name_format = template.pop("default_name_format", "{name}-{0}")
|
||||
if name is None:
|
||||
name = default_name_format.replace("{name}", template_name)
|
||||
# the appliance metadata stays template level: only the default
|
||||
# credentials are seeded on the node (where they can be overridden)
|
||||
appliance_metadata = template.pop("appliance_metadata", None) or {}
|
||||
for field in ("default_username", "default_password"):
|
||||
if appliance_metadata.get(field):
|
||||
template[field] = appliance_metadata[field]
|
||||
node_id = str(uuid.uuid4())
|
||||
node = await self.add_node(compute, name, node_id, node_type=node_type, **template)
|
||||
return node
|
||||
|
||||
Reference in new issue
Block a user