mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
Add an endpoint for exporting the initial config file
This commit is contained in:
1 parent
57348d0508
commit
0e98497a99
4 files changed
+80
-4
No files matched your search
@@ -25,6 +25,7 @@ from ..schemas.iou import IOU_UPDATE_SCHEMA
|
||||
from ..schemas.iou import IOU_OBJECT_SCHEMA
|
||||
from ..schemas.iou import IOU_NIO_SCHEMA
|
||||
from ..schemas.iou import IOU_CAPTURE_SCHEMA
|
||||
from ..schemas.iou import IOU_INITIAL_CONFIG_SCHEMA
|
||||
from ..modules.iou import IOU
|
||||
|
||||
|
||||
@@ -293,3 +294,21 @@ class IOUHandler:
|
||||
port_number = int(request.match_info["port_number"])
|
||||
yield from vm.stop_capture(adapter_number, port_number)
|
||||
response.set_status(204)
|
||||
|
||||
@Route.get(
|
||||
r"/projects/{project_id}/iou/vms/{vm_id}/initial_config",
|
||||
status_codes={
|
||||
200: "Initial config retrieved",
|
||||
400: "Invalid request",
|
||||
404: "Instance doesn't exist"
|
||||
},
|
||||
output=IOU_INITIAL_CONFIG_SCHEMA,
|
||||
description="Retrieve the initial config content")
|
||||
def show_initial_config(request, response):
|
||||
|
||||
iou_manager = IOU.instance()
|
||||
vm = iou_manager.get_vm(request.match_info["vm_id"],
|
||||
project_id=request.match_info["project_id"])
|
||||
response.set_status(200)
|
||||
response.json({"content": vm.initial_config,
|
||||
"path": vm.relative_initial_config_file})
|
||||
@@ -889,6 +889,21 @@ class IOUVM(BaseVM):
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def relative_initial_config_file(self):
|
||||
"""
|
||||
Returns the initial config file relative to the project directory.
|
||||
It's compatible with pre 1.3 topologies.
|
||||
|
||||
:returns: path to config file. None if the file doesn't exist
|
||||
"""
|
||||
|
||||
path = os.path.join(self.working_dir, 'initial-config.cfg')
|
||||
if os.path.exists(path):
|
||||
return path.replace(self.project.path, "")[1:]
|
||||
else:
|
||||
return None
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_capture(self, adapter_number, port_number, output_file, data_link_type="DLT_EN10MB"):
|
||||
"""
|
||||
|
||||
@@ -281,3 +281,23 @@ IOU_CAPTURE_SCHEMA = {
|
||||
"additionalProperties": False,
|
||||
"required": ["capture_file_name", "data_link_type"]
|
||||
}
|
||||
|
||||
IOU_INITIAL_CONFIG_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to get the initial configuration file",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content": {
|
||||
"description": "Content of the initial configuration file",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
"path": {
|
||||
"description": "Relative path on the server of the initial configuration file",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["content", "path"]
|
||||
}
|
||||
Reference in new issue
Block a user