mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-11 16:41:04 +00:00
Dynamips import/export configs.
This commit is contained in:
parent
3797e27de5
commit
8d02f464c5
@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import base64
|
||||||
from ..web.route import Route
|
from ..web.route import Route
|
||||||
from ..schemas.dynamips_vm import VM_CREATE_SCHEMA
|
from ..schemas.dynamips_vm import VM_CREATE_SCHEMA
|
||||||
from ..schemas.dynamips_vm import VM_UPDATE_SCHEMA
|
from ..schemas.dynamips_vm import VM_UPDATE_SCHEMA
|
||||||
from ..schemas.dynamips_vm import VM_CAPTURE_SCHEMA
|
from ..schemas.dynamips_vm import VM_CAPTURE_SCHEMA
|
||||||
from ..schemas.dynamips_vm import VM_OBJECT_SCHEMA
|
from ..schemas.dynamips_vm import VM_OBJECT_SCHEMA
|
||||||
from ..schemas.dynamips_vm import VM_NIO_SCHEMA
|
from ..schemas.dynamips_vm import VM_NIO_SCHEMA
|
||||||
|
from ..schemas.dynamips_vm import VM_CONFIGS_SCHEMA
|
||||||
from ..modules.dynamips import Dynamips
|
from ..modules.dynamips import Dynamips
|
||||||
from ..modules.project_manager import ProjectManager
|
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.update_vm_settings(vm, request.json)
|
||||||
yield from dynamips_manager.ghost_ios_support(vm)
|
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.set_status(201)
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
@ -329,3 +327,25 @@ class DynamipsVMHandler:
|
|||||||
yield from vm.stop_capture(slot_number, port_number)
|
yield from vm.stop_capture(slot_number, port_number)
|
||||||
response.set_status(204)
|
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})
|
||||||
|
@ -480,6 +480,9 @@ class Dynamips(BaseManager):
|
|||||||
if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]:
|
if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]:
|
||||||
yield from vm.uninstall_wic(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
|
@asyncio.coroutine
|
||||||
def create_vm_configs(self, vm, startup_config_content, private_config_content):
|
def create_vm_configs(self, vm, startup_config_content, private_config_content):
|
||||||
"""
|
"""
|
||||||
|
@ -21,7 +21,6 @@ order to run an IOU instance.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -32,12 +31,12 @@ import threading
|
|||||||
import configparser
|
import configparser
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from pkg_resources import parse_version
|
|
||||||
from .iou_error import IOUError
|
from .iou_error import IOUError
|
||||||
from ..adapters.ethernet_adapter import EthernetAdapter
|
from ..adapters.ethernet_adapter import EthernetAdapter
|
||||||
from ..adapters.serial_adapter import SerialAdapter
|
from ..adapters.serial_adapter import SerialAdapter
|
||||||
from ..nios.nio_udp import NIO_UDP
|
from ..nios.nio_udp import NIO_UDP
|
||||||
from ..nios.nio_tap import NIO_TAP
|
from ..nios.nio_tap import NIO_TAP
|
||||||
|
from ..nios.nio_generic_ethernet import NIO_GenericEthernet
|
||||||
from ..base_vm import BaseVM
|
from ..base_vm import BaseVM
|
||||||
from .ioucon import start_ioucon
|
from .ioucon import start_ioucon
|
||||||
import gns3server.utils.asyncio
|
import gns3server.utils.asyncio
|
||||||
|
@ -295,11 +295,19 @@ VM_UPDATE_SCHEMA = {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
|
"startup_config_content": {
|
||||||
|
"description": "Content of IOS startup configuration file",
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
"private_config": {
|
"private_config": {
|
||||||
"description": "path to the IOS private configuration file",
|
"description": "path to the IOS private configuration file",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
|
"private_config_content": {
|
||||||
|
"description": "Content of IOS private configuration file",
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
"ram": {
|
"ram": {
|
||||||
"description": "amount of RAM in MB",
|
"description": "amount of RAM in MB",
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
@ -888,3 +896,23 @@ VM_OBJECT_SCHEMA = {
|
|||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "vm_id", "project_id", "dynamips_id"]
|
"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"]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user