diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index e72d1dde..56c89bd1 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -106,7 +106,22 @@ class VPCSVM(BaseVM): "vm_id": self.id, "console": self._console, "project_id": self.project.id, - "startup_script": self.startup_script} + "startup_script": self.startup_script, + "startup_script_path": self.relative_startup_script} + + @property + def relative_startup_script(self): + """ + Returns the startup config file relative to the project directory. + + :returns: path to config file. None if the file doesn't exist + """ + + path = os.path.join(self.working_dir, 'startup.vpc') + if os.path.exists(path): + return 'startup.vpc' + else: + return None @property def vpcs_path(self): diff --git a/gns3server/schemas/vpcs.py b/gns3server/schemas/vpcs.py index 8ba53064..14cad8be 100644 --- a/gns3server/schemas/vpcs.py +++ b/gns3server/schemas/vpcs.py @@ -165,7 +165,11 @@ VPCS_OBJECT_SCHEMA = { "description": "Content of the VPCS startup script", "type": ["string", "null"] }, + "startup_script_path": { + "description": "Path of the VPCS startup script relative to project directory", + "type": ["string", "null"] + }, }, "additionalProperties": False, - "required": ["name", "vm_id", "console", "project_id"] + "required": ["name", "vm_id", "console", "project_id", "startup_script_path"] } diff --git a/tests/handlers/api/test_vpcs.py b/tests/handlers/api/test_vpcs.py index 190ab8d0..473a533e 100644 --- a/tests/handlers/api/test_vpcs.py +++ b/tests/handlers/api/test_vpcs.py @@ -42,6 +42,7 @@ def test_vpcs_get(server, project, vm): assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}" assert response.json["name"] == "PC TEST 1" assert response.json["project_id"] == project.id + assert response.json["startup_script_path"] == None def test_vpcs_create_startup_script(server, project): @@ -51,6 +52,7 @@ def test_vpcs_create_startup_script(server, project): assert response.json["name"] == "PC TEST 1" assert response.json["project_id"] == project.id assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST" + assert response.json["startup_script_path"] == "startup.vpc" def test_vpcs_create_port(server, project, free_console_port):