mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Project global variables
This commit is contained in:
1 parent
80958e8a6d
commit
e267f8a8b8
9 files changed
+167
-8
No files matched your search
@@ -325,6 +325,10 @@ class DockerVM(BaseNode):
|
||||
# Give the information to the container the list of volume path mounted
|
||||
params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes)))
|
||||
|
||||
if self.project.variables:
|
||||
for var in self.project.variables:
|
||||
params["Env"].append("{}={}".format(var["name"], var.get('value', '')))
|
||||
|
||||
if self._environment:
|
||||
for e in self._environment.strip().split("\n"):
|
||||
e = e.strip()
|
||||
|
||||
@@ -46,7 +46,7 @@ class Project:
|
||||
:param path: path of the project. (None use the standard directory)
|
||||
"""
|
||||
|
||||
def __init__(self, name=None, project_id=None, path=None):
|
||||
def __init__(self, name=None, project_id=None, path=None, variables=None):
|
||||
|
||||
self._name = name
|
||||
if project_id:
|
||||
@@ -61,6 +61,7 @@ class Project:
|
||||
self._nodes = set()
|
||||
self._used_tcp_ports = set()
|
||||
self._used_udp_ports = set()
|
||||
self._variables = variables
|
||||
|
||||
if path is None:
|
||||
location = get_default_project_directory()
|
||||
@@ -83,7 +84,8 @@ class Project:
|
||||
|
||||
return {
|
||||
"name": self._name,
|
||||
"project_id": self._id
|
||||
"project_id": self._id,
|
||||
"variables": self._variables
|
||||
}
|
||||
|
||||
def _config(self):
|
||||
@@ -131,6 +133,14 @@ class Project:
|
||||
|
||||
return self._nodes
|
||||
|
||||
@property
|
||||
def variables(self):
|
||||
return self._variables
|
||||
|
||||
@variables.setter
|
||||
def variables(self, variables):
|
||||
self._variables = variables
|
||||
|
||||
def record_tcp_port(self, port):
|
||||
"""
|
||||
Associate a reserved TCP port number with this project.
|
||||
|
||||
@@ -68,7 +68,7 @@ class Project:
|
||||
def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened",
|
||||
filename=None, auto_start=False, auto_open=False, auto_close=True,
|
||||
scene_height=1000, scene_width=2000, zoom=100, show_layers=False, snap_to_grid=False, show_grid=False,
|
||||
grid_size=0, show_interface_labels=False):
|
||||
grid_size=0, show_interface_labels=False, variables=None, supplier=None):
|
||||
|
||||
self._controller = controller
|
||||
assert name is not None
|
||||
@@ -85,6 +85,9 @@ class Project:
|
||||
self._show_grid = show_grid
|
||||
self._grid_size = grid_size
|
||||
self._show_interface_labels = show_interface_labels
|
||||
self._variables = variables
|
||||
self._supplier = supplier
|
||||
|
||||
self._loading = False
|
||||
|
||||
# Disallow overwrite of existing project
|
||||
@@ -266,6 +269,36 @@ class Project:
|
||||
"""
|
||||
self._show_interface_labels = show_interface_labels
|
||||
|
||||
@property
|
||||
def variables(self):
|
||||
"""
|
||||
Variables applied to the project
|
||||
:return: list
|
||||
"""
|
||||
return self._variables
|
||||
|
||||
@variables.setter
|
||||
def variables(self, variables):
|
||||
"""
|
||||
Setter for variables applied to the project
|
||||
"""
|
||||
self._variables = variables
|
||||
|
||||
@property
|
||||
def supplier(self):
|
||||
"""
|
||||
Supplier of the project
|
||||
:return: dict
|
||||
"""
|
||||
return self._supplier
|
||||
|
||||
@supplier.setter
|
||||
def supplier(self, supplier):
|
||||
"""
|
||||
Setter for supplier of the project
|
||||
"""
|
||||
self._supplier = supplier
|
||||
|
||||
@property
|
||||
def auto_start(self):
|
||||
"""
|
||||
@@ -1012,7 +1045,9 @@ class Project:
|
||||
"snap_to_grid": self._snap_to_grid,
|
||||
"show_grid": self._show_grid,
|
||||
"grid_size": self._grid_size,
|
||||
"show_interface_labels": self._show_interface_labels
|
||||
"show_interface_labels": self._show_interface_labels,
|
||||
"supplier": self._supplier,
|
||||
"variables": self._variables
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -15,6 +15,40 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
SUPPLIER_OBJECT_SCHEMA = {
|
||||
"type": ["object", "null"],
|
||||
"description": "Supplier of the project",
|
||||
"properties": {
|
||||
"logo": {
|
||||
"type": "string",
|
||||
"description": "Path to the project supplier logo"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "URL to the project supplier site"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VARIABLES_OBJECT_SCHEMA = {
|
||||
"type": ["array", "null"],
|
||||
"description": "Variables required to run the project",
|
||||
"items": {
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Variable name"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"description": "Variable value"
|
||||
}
|
||||
},
|
||||
"required": ["name"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PROJECT_CREATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@@ -73,7 +107,9 @@ PROJECT_CREATE_SCHEMA = {
|
||||
"show_interface_labels": {
|
||||
"type": "boolean",
|
||||
"description": "Show interface labels on the drawing area"
|
||||
}
|
||||
},
|
||||
"supplier": SUPPLIER_OBJECT_SCHEMA,
|
||||
"variables": VARIABLES_OBJECT_SCHEMA
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name"]
|
||||
@@ -136,7 +172,9 @@ PROJECT_UPDATE_SCHEMA = {
|
||||
"show_interface_labels": {
|
||||
"type": "boolean",
|
||||
"description": "Show interface labels on the drawing area"
|
||||
}
|
||||
},
|
||||
"supplier": SUPPLIER_OBJECT_SCHEMA,
|
||||
"variables": VARIABLES_OBJECT_SCHEMA
|
||||
},
|
||||
"additionalProperties": False,
|
||||
}
|
||||
@@ -215,7 +253,9 @@ PROJECT_OBJECT_SCHEMA = {
|
||||
"show_interface_labels": {
|
||||
"type": "boolean",
|
||||
"description": "Show interface labels on the drawing area"
|
||||
}
|
||||
},
|
||||
"supplier": SUPPLIER_OBJECT_SCHEMA,
|
||||
"variables": VARIABLES_OBJECT_SCHEMA
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["project_id"]
|
||||
|
||||
Reference in new issue
Block a user