Strip endpoint for configs files because now we use the /files API

pull/638/head
Julien Duponchelle 8 years ago
parent 7e40eb02e6
commit fc6b220c7c
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -33,8 +33,7 @@ from gns3server.schemas.node import (
from gns3server.schemas.dynamips_vm import (
VM_CREATE_SCHEMA,
VM_UPDATE_SCHEMA,
VM_OBJECT_SCHEMA,
VM_CONFIGS_SCHEMA
VM_OBJECT_SCHEMA
)
DEFAULT_CHASSIS = {
@ -350,64 +349,6 @@ class DynamipsVMHandler:
yield from vm.stop_capture(slot_number, port_number)
response.set_status(204)
@Route.get(
r"/projects/{project_id}/dynamips/nodes/{node_id}/configs",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
},
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 get_configs(request, response):
dynamips_manager = Dynamips.instance()
vm = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
startup_config_base64, private_config_base64 = yield from vm.extract_config()
module_workdir = vm.project.module_working_directory(dynamips_manager.module_name.lower())
result = {}
if startup_config_base64:
startup_config_content = base64.b64decode(startup_config_base64).decode("utf-8", errors='replace')
result["startup_config_content"] = startup_config_content
else:
# The NVRAM doesn't contain anything if the router has not been started at least once
# in this case just use the startup-config file
if vm.startup_config:
startup_config_path = os.path.join(module_workdir, vm.startup_config)
if os.path.isfile(startup_config_path):
try:
with open(startup_config_path, "rb") as f:
content = f.read().decode("utf-8", errors='replace')
if content:
result["startup_config_content"] = content
except OSError as e:
raise DynamipsError("Could not read the startup-config {}: {}".format(startup_config_path, e))
if private_config_base64:
private_config_content = base64.b64decode(private_config_base64).decode("utf-8", errors='replace')
result["private_config_content"] = private_config_content
else:
# The NVRAM doesn't contain anything if the router has not been started at least once
# in this case just use the private-config file
if vm.private_config:
private_config_path = os.path.join(module_workdir, vm.private_config)
if os.path.isfile(private_config_path):
try:
with open(private_config_path, "rb") as f:
content = f.read().decode("utf-8", errors='replace')
if content:
result["private_config_content"] = content
except OSError as e:
raise DynamipsError("Could not read the private-config {}: {}".format(private_config_path, e))
response.set_status(200)
response.json(result)
@Route.get(
r"/projects/{project_id}/dynamips/nodes/{node_id}/idlepc_proposals",
parameters={

@ -303,47 +303,6 @@ class IOUHandler:
yield from vm.stop_capture(adapter_number, port_number)
response.set_status(204)
@Route.get(
r"/projects/{project_id}/iou/nodes/{node_id}/configs",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
200: "Configs retrieved",
400: "Invalid request",
404: "Instance doesn't exist"
},
output=IOU_CONFIGS_SCHEMA,
description="Retrieve the startup and private configs content")
def get_configs(request, response):
iou_manager = IOU.instance()
vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
startup_config_content, private_config_content = vm.extract_configs()
result = {}
if startup_config_content:
result["startup_config_content"] = startup_config_content.decode("utf-8", errors='replace')
else:
# nvram doesn't exists if the VM has not been started at least once
# in this case just use the startup-config file
startup_config_content = vm.startup_config_content
if startup_config_content:
result["startup_config_content"] = startup_config_content
if private_config_content:
result["private_config_content"] = private_config_content.decode("utf-8", errors='replace')
else:
# nvram doesn't exists if the VM has not been started at least once
# in this case just use the private-config file
private_config_content = vm.private_config_content
if private_config_content:
result["private_config_content"] = private_config_content
response.set_status(200)
response.json(result)
@Route.get(
r"/iou/images",
status_codes={

@ -767,21 +767,3 @@ VM_OBJECT_SCHEMA = {
"required": ["name", "node_id", "project_id", "dynamips_id", "console", "console_type"]
}
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,
}

@ -309,25 +309,6 @@ def test_iou_stop_capture_not_started(http_compute, vm, tmpdir):
assert response.status == 409
def test_get_configs_without_configs_file(http_compute, vm):
response = http_compute.get("/projects/{project_id}/iou/nodes/{node_id}/configs".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert response.status == 200
assert "startup_config" not in response.json
assert "private_config" not in response.json
def test_get_configs_with_startup_config_file(http_compute, project, vm):
path = startup_config_file(project, vm)
with open(path, "w+") as f:
f.write("TEST")
response = http_compute.get("/projects/{project_id}/iou/nodes/{node_id}/configs".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert response.status == 200
assert response.json["startup_config_content"] == "TEST"
def test_images(http_compute, fake_iou_bin):
response = http_compute.get("/iou/images", example=True)

Loading…
Cancel
Save