mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-23 14:42:28 +00:00
Allow to send the iourc when starting the VM
Ref https://github.com/GNS3/gns3-server/issues/255
This commit is contained in:
parent
dd6c377b15
commit
a461cb71c6
@ -21,6 +21,7 @@ from aiohttp.web import HTTPConflict
|
|||||||
from ...web.route import Route
|
from ...web.route import Route
|
||||||
from ...schemas.nio import NIO_SCHEMA
|
from ...schemas.nio import NIO_SCHEMA
|
||||||
from ...schemas.iou import IOU_CREATE_SCHEMA
|
from ...schemas.iou import IOU_CREATE_SCHEMA
|
||||||
|
from ...schemas.iou import IOU_START_SCHEMA
|
||||||
from ...schemas.iou import IOU_UPDATE_SCHEMA
|
from ...schemas.iou import IOU_UPDATE_SCHEMA
|
||||||
from ...schemas.iou import IOU_OBJECT_SCHEMA
|
from ...schemas.iou import IOU_OBJECT_SCHEMA
|
||||||
from ...schemas.iou import IOU_CAPTURE_SCHEMA
|
from ...schemas.iou import IOU_CAPTURE_SCHEMA
|
||||||
@ -151,11 +152,19 @@ class IOUHandler:
|
|||||||
400: "Invalid request",
|
400: "Invalid request",
|
||||||
404: "Instance doesn't exist"
|
404: "Instance doesn't exist"
|
||||||
},
|
},
|
||||||
|
input=IOU_START_SCHEMA,
|
||||||
description="Start a IOU instance")
|
description="Start a IOU instance")
|
||||||
def start(request, response):
|
def start(request, response):
|
||||||
|
|
||||||
iou_manager = IOU.instance()
|
iou_manager = IOU.instance()
|
||||||
vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
vm = iou_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
||||||
|
|
||||||
|
for name, value in request.json.items():
|
||||||
|
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||||
|
setattr(vm, name, value)
|
||||||
|
print(name)
|
||||||
|
print(vm.iourc_path)
|
||||||
|
|
||||||
yield from vm.start()
|
yield from vm.start()
|
||||||
response.set_status(204)
|
response.set_status(204)
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ IOU_CREATE_SCHEMA = {
|
|||||||
"type": ["string", "null"]
|
"type": ["string", "null"]
|
||||||
},
|
},
|
||||||
"iourc_content": {
|
"iourc_content": {
|
||||||
"description": "Content of the iourc file, if a file exist on servers this variable is ignored. It's mostly for compatibility with < 1.3 releases",
|
"description": "Content of the iourc file. Ignored if Null",
|
||||||
"type": ["string", "null"]
|
"type": ["string", "null"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -156,13 +156,27 @@ IOU_UPDATE_SCHEMA = {
|
|||||||
"type": ["boolean", "null"]
|
"type": ["boolean", "null"]
|
||||||
},
|
},
|
||||||
"iourc_content": {
|
"iourc_content": {
|
||||||
"description": "Content of the iourc file, if a file exist on servers this variable is ignored. It's mostly for compatibility with < 1.3 releases",
|
"description": "Content of the iourc file. Ignored if Null",
|
||||||
"type": ["string", "null"]
|
"type": ["string", "null"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IOU_START_SCHEMA = {
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"description": "Request validation to start an IOU instance",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"iourc_content": {
|
||||||
|
"description": "Content of the iourc file. Ignored if Null",
|
||||||
|
"type": ["string", "null"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
IOU_OBJECT_SCHEMA = {
|
IOU_OBJECT_SCHEMA = {
|
||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"description": "IOU instance",
|
"description": "IOU instance",
|
||||||
|
@ -137,11 +137,25 @@ def test_iou_get(server, project, vm):
|
|||||||
|
|
||||||
def test_iou_start(server, vm):
|
def test_iou_start(server, vm):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
|
||||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
|
||||||
assert mock.called
|
assert mock.called
|
||||||
assert response.status == 204
|
assert response.status == 204
|
||||||
|
|
||||||
|
|
||||||
|
def test_iou_start_with_iourc(server, vm, tmpdir):
|
||||||
|
body = {"iourc_content": "test"}
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start", return_value=True) as mock:
|
||||||
|
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=body, example=True)
|
||||||
|
assert mock.called
|
||||||
|
assert response.status == 204
|
||||||
|
|
||||||
|
response = server.get("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
|
||||||
|
assert response.status == 200
|
||||||
|
with open(response.json["iourc_path"]) as f:
|
||||||
|
assert f.read() == "test"
|
||||||
|
|
||||||
|
|
||||||
def test_iou_stop(server, vm):
|
def test_iou_stop(server, vm):
|
||||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop", return_value=True) as mock:
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop", return_value=True) as mock:
|
||||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user