diff --git a/gns3server/handlers/dynamips_vm_handler.py b/gns3server/handlers/dynamips_vm_handler.py index f88c9297..4b284a0c 100644 --- a/gns3server/handlers/dynamips_vm_handler.py +++ b/gns3server/handlers/dynamips_vm_handler.py @@ -17,13 +17,14 @@ import os -import asyncio +import base64 from ..web.route import Route from ..schemas.dynamips_vm import VM_CREATE_SCHEMA from ..schemas.dynamips_vm import VM_UPDATE_SCHEMA from ..schemas.dynamips_vm import VM_CAPTURE_SCHEMA from ..schemas.dynamips_vm import VM_OBJECT_SCHEMA from ..schemas.dynamips_vm import VM_NIO_SCHEMA +from ..schemas.dynamips_vm import VM_CONFIGS_SCHEMA from ..modules.dynamips import Dynamips from ..modules.project_manager import ProjectManager @@ -59,9 +60,6 @@ class DynamipsVMHandler: yield from dynamips_manager.update_vm_settings(vm, request.json) yield from dynamips_manager.ghost_ios_support(vm) - yield from dynamips_manager.create_vm_configs(vm, - request.json.get("startup_config_content"), - request.json.get("private_config_content")) response.set_status(201) response.json(vm) @@ -329,3 +327,25 @@ class DynamipsVMHandler: yield from vm.stop_capture(slot_number, port_number) response.set_status(204) + @Route.get( + r"/projects/{project_id}/dynamips/vms/{vm_id}/configs", + status_codes={ + 200: "Configs retrieved", + 400: "Invalid request", + 404: "Instance doesn't exist" + }, + output=VM_CONFIGS_SCHEMA, + description="Retrieve the startup and private configs content") + def show_initial_config(request, response): + + dynamips_manager = Dynamips.instance() + vm = dynamips_manager.get_vm(request.match_info["vm_id"], + project_id=request.match_info["project_id"]) + + startup_config, private_config = yield from vm.extract_config() + startup_config_content = base64.decodebytes(startup_config.encode("utf-8")).decode("utf-8") + private_config_content = base64.decodebytes(private_config.encode("utf-8")).decode("utf-8") + + response.set_status(200) + response.json({"startup_config_content": startup_config_content, + "private_config_content": private_config_content}) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index 03eb326c..fc0eb7d8 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -480,6 +480,9 @@ class Dynamips(BaseManager): if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]: yield from vm.uninstall_wic(wic_slot_id) + # update the configs if needed + yield from self.create_vm_configs(vm, settings.get("startup_config_content"), settings.get("private_config_content")) + @asyncio.coroutine def create_vm_configs(self, vm, startup_config_content, private_config_content): """ diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 8fef72a9..ab0d064d 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -21,7 +21,6 @@ order to run an IOU instance. """ import os -import sys import signal import re import asyncio @@ -32,12 +31,12 @@ import threading import configparser import glob -from pkg_resources import parse_version from .iou_error import IOUError from ..adapters.ethernet_adapter import EthernetAdapter from ..adapters.serial_adapter import SerialAdapter from ..nios.nio_udp import NIO_UDP from ..nios.nio_tap import NIO_TAP +from ..nios.nio_generic_ethernet import NIO_GenericEthernet from ..base_vm import BaseVM from .ioucon import start_ioucon import gns3server.utils.asyncio diff --git a/gns3server/schemas/dynamips_vm.py b/gns3server/schemas/dynamips_vm.py index 0d767dd9..304bcc65 100644 --- a/gns3server/schemas/dynamips_vm.py +++ b/gns3server/schemas/dynamips_vm.py @@ -295,11 +295,19 @@ VM_UPDATE_SCHEMA = { "type": "string", "minLength": 1, }, + "startup_config_content": { + "description": "Content of IOS startup configuration file", + "type": "string", + }, "private_config": { "description": "path to the IOS private configuration file", "type": "string", "minLength": 1, }, + "private_config_content": { + "description": "Content of IOS private configuration file", + "type": "string", + }, "ram": { "description": "amount of RAM in MB", "type": "integer" @@ -888,3 +896,23 @@ VM_OBJECT_SCHEMA = { "additionalProperties": False, "required": ["name", "vm_id", "project_id", "dynamips_id"] } + +VM_CONFIGS_SCHEMA = { + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Request validation to get the startup and private configuration file", + "type": "object", + "properties": { + "startup_config_content": { + "description": "Content of the startup configuration file", + "type": ["string", "null"], + "minLength": 1, + }, + "private_config_content": { + "description": "Content of the private configuration file", + "type": ["string", "null"], + "minLength": 1, + }, + }, + "additionalProperties": False, + "required": ["startup_config_content", "private_config_content"] +}