diff --git a/gns3server/handlers/iou_handler.py b/gns3server/handlers/iou_handler.py index 9b72da8f..05d34614 100644 --- a/gns3server/handlers/iou_handler.py +++ b/gns3server/handlers/iou_handler.py @@ -62,7 +62,7 @@ class IOUHandler: ram=request.json.get("ram"), nvram=request.json.get("nvram"), l1_keepalives=request.json.get("l1_keepalives"), - initial_config=request.json.get("initial_config") + initial_config=request.json.get("initial_config_content") ) vm.path = request.json.get("path", vm.path) response.set_status(201) @@ -116,7 +116,7 @@ class IOUHandler: vm.ram = request.json.get("ram", vm.ram) vm.nvram = request.json.get("nvram", vm.nvram) vm.l1_keepalives = request.json.get("l1_keepalives", vm.l1_keepalives) - vm.initial_config = request.json.get("initial_config", vm.initial_config) + vm.initial_config = request.json.get("initial_config_content", vm.initial_config) response.json(vm) diff --git a/gns3server/modules/iou/iou_vm.py b/gns3server/modules/iou/iou_vm.py index 04c3afdd..29b8f21c 100644 --- a/gns3server/modules/iou/iou_vm.py +++ b/gns3server/modules/iou/iou_vm.py @@ -200,6 +200,7 @@ class IOUVM(BaseVM): "ram": self._ram, "nvram": self._nvram, "l1_keepalives": self._l1_keepalives, + "initial_config": self.relative_initial_config_file } @property @@ -890,7 +891,7 @@ class IOUVM(BaseVM): path = os.path.join(self.working_dir, 'initial-config.cfg') if os.path.exists(path): - return path.replace(self.project.path, "")[1:] + return 'initial-config.cfg' else: return None diff --git a/gns3server/schemas/iou.py b/gns3server/schemas/iou.py index 9e846f59..e495af5e 100644 --- a/gns3server/schemas/iou.py +++ b/gns3server/schemas/iou.py @@ -66,7 +66,7 @@ IOU_CREATE_SCHEMA = { "description": "Always up ethernet interface", "type": ["boolean", "null"] }, - "initial_config": { + "initial_config_content": { "description": "Initial configuration of the IOU", "type": ["string", "null"] } @@ -115,7 +115,7 @@ IOU_UPDATE_SCHEMA = { "description": "Always up ethernet interface", "type": ["boolean", "null"] }, - "initial_config": { + "initial_config_content": { "description": "Initial configuration of the IOU", "type": ["string", "null"] } @@ -177,9 +177,13 @@ IOU_OBJECT_SCHEMA = { "description": "Always up ethernet interface", "type": "boolean" }, + "initial_config": { + "description": "Path of the initial config content relative to project directory", + "type": ["string", "null"] + } }, "additionalProperties": False, - "required": ["name", "vm_id", "console", "project_id", "path", "serial_adapters", "ethernet_adapters", "ram", "nvram", "l1_keepalives"] + "required": ["name", "vm_id", "console", "project_id", "path", "serial_adapters", "ethernet_adapters", "ram", "nvram", "l1_keepalives", "initial_config"] } IOU_NIO_SCHEMA = { diff --git a/tests/api/test_iou.py b/tests/api/test_iou.py index 2fe63861..e112bd94 100644 --- a/tests/api/test_iou.py +++ b/tests/api/test_iou.py @@ -72,7 +72,7 @@ def test_iou_create_with_params(server, project, base_params): params["serial_adapters"] = 4 params["ethernet_adapters"] = 0 params["l1_keepalives"] = True - params["initial_config"] = "hostname test" + params["initial_config_content"] = "hostname test" response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), params, example=True) assert response.status == 201 @@ -84,8 +84,9 @@ def test_iou_create_with_params(server, project, base_params): assert response.json["ram"] == 1024 assert response.json["nvram"] == 512 assert response.json["l1_keepalives"] is True + assert "initial-config.cfg" in response.json["initial_config"] with open(initial_config_file(project, response.json)) as f: - assert f.read() == params["initial_config"] + assert f.read() == params["initial_config_content"] def test_iou_get(server, project, vm): @@ -138,7 +139,7 @@ def test_iou_update(server, vm, tmpdir, free_console_port, project): "ethernet_adapters": 4, "serial_adapters": 0, "l1_keepalives": True, - "initial_config": "hostname test" + "initial_config_content": "hostname test" } response = server.put("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), params) assert response.status == 200 @@ -149,6 +150,7 @@ def test_iou_update(server, vm, tmpdir, free_console_port, project): assert response.json["ram"] == 512 assert response.json["nvram"] == 2048 assert response.json["l1_keepalives"] is True + assert "initial-config.cfg" in response.json["initial_config"] with open(initial_config_file(project, response.json)) as f: assert f.read() == "hostname test" @@ -244,4 +246,4 @@ def test_get_initial_config_with_config_file(server, project, vm): response = server.get("/projects/{project_id}/iou/vms/{vm_id}/initial_config".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) assert response.status == 200 assert response.json["content"] == "TEST" - assert response.json["path"] == "project-files/iou/{vm_id}/initial-config.cfg".format(vm_id=vm["vm_id"]) + assert response.json["path"] == "initial-config.cfg"