mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 06:41:13 +02:00
New feature: import/export device configs.
This commit is contained in:
1 parent
9ac5b86431
commit
7c99ee9de8
7 files changed
+159
-1
No files matched your search
@@ -46,6 +46,7 @@ from .schemas import IOU_ADD_NIO_SCHEMA
|
||||
from .schemas import IOU_DELETE_NIO_SCHEMA
|
||||
from .schemas import IOU_START_CAPTURE_SCHEMA
|
||||
from .schemas import IOU_STOP_CAPTURE_SCHEMA
|
||||
from .schemas import IOU_EXPORT_CONFIG_SCHEMA
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -755,6 +756,43 @@ class IOU(IModule):
|
||||
response = {"port_id": request["port_id"]}
|
||||
self.send_response(response)
|
||||
|
||||
@IModule.route("iou.export_config")
|
||||
def export_config(self, request):
|
||||
"""
|
||||
Exports the initial-config from an IOU instance.
|
||||
|
||||
Mandatory request parameters:
|
||||
- id (vm identifier)
|
||||
|
||||
Response parameters:
|
||||
- initial_config_base64 (initial-config base64 encoded)
|
||||
- False if no configuration can be exported
|
||||
"""
|
||||
|
||||
# validate the request
|
||||
if not self.validate_request(request, IOU_EXPORT_CONFIG_SCHEMA):
|
||||
return
|
||||
|
||||
# get the instance
|
||||
iou_instance = self.get_iou_instance(request["id"])
|
||||
if not iou_instance:
|
||||
return
|
||||
|
||||
response = {}
|
||||
initial_config_path = os.path.join(iou_instance.working_dir, iou_instance.initial_config)
|
||||
try:
|
||||
with open(initial_config_path, "rb") as f:
|
||||
config = f.read()
|
||||
response["initial_config_base64"] = base64.encodebytes(config).decode("utf-8")
|
||||
except OSError as e:
|
||||
self.send_custom_error("unable to export the initial-config: {}".format(e))
|
||||
return
|
||||
|
||||
if not response:
|
||||
self.send_response(False)
|
||||
else:
|
||||
self.send_response(response)
|
||||
|
||||
@IModule.route("iou.echo")
|
||||
def echo(self, request):
|
||||
"""
|
||||
|
||||
@@ -452,3 +452,17 @@ IOU_STOP_CAPTURE_SCHEMA = {
|
||||
"additionalProperties": False,
|
||||
"required": ["id", "slot", "port", "port_id"]
|
||||
}
|
||||
|
||||
IOU_EXPORT_CONFIG_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to export an initial-config from an IOU instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "IOU device instance ID",
|
||||
"type": "integer"
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["id"]
|
||||
}
|
||||
Reference in new issue
Block a user