diff --git a/docs/api/examples/get_vpcsuuid.txt b/docs/api/examples/get_vpcsuuid.txt index f0eb88f9..23e0c6af 100644 --- a/docs/api/examples/get_vpcsuuid.txt +++ b/docs/api/examples/get_vpcsuuid.txt @@ -18,5 +18,5 @@ X-ROUTE: /vpcs/{uuid} "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "script_file": null, "startup_script": null, - "uuid": "a0ecc3ea-907f-4751-9415-9f6d5da4dc3a" + "uuid": "925c4d08-58a5-4078-9e77-a6875e0c28dc" } diff --git a/docs/api/examples/post_virtualbox.txt b/docs/api/examples/post_virtualbox.txt index efc04fdb..fdb19bc6 100644 --- a/docs/api/examples/post_virtualbox.txt +++ b/docs/api/examples/post_virtualbox.txt @@ -1,7 +1,8 @@ -curl -i -X POST 'http://localhost:8000/virtualbox' -d '{"name": "VM1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "vmname": "VM1"}' +curl -i -X POST 'http://localhost:8000/virtualbox' -d '{"linked_clone": false, "name": "VM1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "vmname": "VM1"}' POST /virtualbox HTTP/1.1 { + "linked_clone": false, "name": "VM1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "vmname": "VM1" @@ -19,5 +20,5 @@ X-ROUTE: /virtualbox { "name": "VM1", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", - "uuid": "0f7b32bb-13e1-4c3f-8176-bbf277672b58" + "uuid": "c220788f-ee1e-491c-b318-6542d2f130bf" } diff --git a/docs/api/examples/post_vpcs.txt b/docs/api/examples/post_vpcs.txt index 67c5e242..b66cac02 100644 --- a/docs/api/examples/post_vpcs.txt +++ b/docs/api/examples/post_vpcs.txt @@ -21,5 +21,5 @@ X-ROUTE: /vpcs "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "script_file": null, "startup_script": null, - "uuid": "f4f04818-610c-4e95-aa0e-6d29afa72fc7" + "uuid": "4d670947-44a8-4156-8626-adce3faa5ae6" } diff --git a/docs/api/project.rst b/docs/api/project.rst index 00e354f2..22b8dcfb 100644 --- a/docs/api/project.rst +++ b/docs/api/project.rst @@ -4,7 +4,7 @@ .. contents:: POST /project -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a project on the server Response status codes diff --git a/docs/api/version.rst b/docs/api/version.rst index 66da7325..f98b52f5 100644 --- a/docs/api/version.rst +++ b/docs/api/version.rst @@ -4,7 +4,7 @@ .. contents:: GET /version -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Retrieve the server version number Response status codes @@ -28,7 +28,7 @@ Sample session POST /version -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Check if version is the same as the server Response status codes diff --git a/docs/api/virtualbox.rst b/docs/api/virtualbox.rst index 9a6cb762..3f96363c 100644 --- a/docs/api/virtualbox.rst +++ b/docs/api/virtualbox.rst @@ -4,7 +4,7 @@ .. contents:: POST /virtualbox -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a new VirtualBox VM instance Response status codes @@ -19,9 +19,9 @@ Input - + - + @@ -35,7 +35,7 @@ Output - +
Name Mandatory Type Description
linked_clone boolean either the VM is a linked clone or not
linked_clone boolean either the VM is a linked clone or not
name string VirtualBox VM instance name
project_uuid string Project UUID
project_uuid string Project UUID
uuid string VirtualBox VM instance UUID
vbox_id integer VirtualBox VM instance ID (for project created before GNS3 1.3)
vmname string VirtualBox VM name (in VirtualBox itself)
Name Mandatory Type Description
console integer console TCP port
name string VirtualBox VM instance name
project_uuid string Project UUID
project_uuid string Project UUID
uuid string VirtualBox VM instance UUID
diff --git a/docs/api/virtualboxuuidstart.rst b/docs/api/virtualboxuuidstart.rst index 570a64f7..f60d7c22 100644 --- a/docs/api/virtualboxuuidstart.rst +++ b/docs/api/virtualboxuuidstart.rst @@ -4,7 +4,7 @@ .. contents:: POST /virtualbox/**{uuid}**/start -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start a VirtualBox VM instance Parameters diff --git a/docs/api/virtualboxuuidstop.rst b/docs/api/virtualboxuuidstop.rst index 21fd9809..d8a58373 100644 --- a/docs/api/virtualboxuuidstop.rst +++ b/docs/api/virtualboxuuidstop.rst @@ -4,7 +4,7 @@ .. contents:: POST /virtualbox/**{uuid}**/stop -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Stop a VirtualBox VM instance Parameters diff --git a/docs/api/vpcs.rst b/docs/api/vpcs.rst index 4790ad9e..c525760a 100644 --- a/docs/api/vpcs.rst +++ b/docs/api/vpcs.rst @@ -4,7 +4,7 @@ .. contents:: POST /vpcs -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create a new VPCS instance Response status codes diff --git a/docs/api/vpcsuuid.rst b/docs/api/vpcsuuid.rst index bba2e33f..43bca0e5 100644 --- a/docs/api/vpcsuuid.rst +++ b/docs/api/vpcsuuid.rst @@ -4,7 +4,7 @@ .. contents:: GET /vpcs/**{uuid}** -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get a VPCS instance Parameters @@ -24,7 +24,7 @@ Sample session PUT /vpcs/**{uuid}** -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Update a VPCS instance Response status codes diff --git a/docs/api/vpcsuuidportsportidnio.rst b/docs/api/vpcsuuidportsportidnio.rst index c186c9bb..fd5090de 100644 --- a/docs/api/vpcsuuidportsportidnio.rst +++ b/docs/api/vpcsuuidportsportidnio.rst @@ -4,7 +4,7 @@ .. contents:: POST /vpcs/**{uuid}**/ports/**{port_id}**/nio -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Add a NIO to a VPCS Parameters @@ -26,7 +26,7 @@ Sample session DELETE /vpcs/**{uuid}**/ports/**{port_id}**/nio -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Remove a NIO from a VPCS Parameters diff --git a/docs/api/vpcsuuidstart.rst b/docs/api/vpcsuuidstart.rst index bcf1f8ea..4acce2fc 100644 --- a/docs/api/vpcsuuidstart.rst +++ b/docs/api/vpcsuuidstart.rst @@ -4,7 +4,7 @@ .. contents:: POST /vpcs/**{uuid}**/start -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start a VPCS instance Parameters diff --git a/docs/api/vpcsuuidstop.rst b/docs/api/vpcsuuidstop.rst index 16702e07..3b6e76fe 100644 --- a/docs/api/vpcsuuidstop.rst +++ b/docs/api/vpcsuuidstop.rst @@ -4,7 +4,7 @@ .. contents:: POST /vpcs/**{uuid}**/stop -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Stop a VPCS instance Parameters diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index 86ed9312..18e69709 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -169,3 +169,21 @@ class VPCSHandler: vm = vpcs_manager.get_vm(request.match_info["uuid"]) nio = vm.port_remove_nio_binding(int(request.match_info["port_id"])) response.set_status(204) + + @classmethod + @Route.post( + r"/vpcs/{uuid}/reload", + parameters={ + "uuid": "VPCS instance UUID", + }, + status_codes={ + 204: "VPCS reloaded", + 404: "VPCS instance doesn't exist" + }, + description="Remove a NIO from a VPCS") + def reload(request, response): + + vpcs_manager = VPCS.instance() + vm = vpcs_manager.get_vm(request.match_info["uuid"]) + nio = vm.reload() + response.set_status(204) diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index 35c61407..8b43d9d0 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -252,6 +252,15 @@ class VPCSVM(BaseVM): self._process = None self._started = False + @asyncio.coroutine + def reload(self): + """ + Reload the VPCS process. (Stop / Start) + """ + + yield from self.stop() + yield from self.start() + def _kill_process(self): """Kill the process if running""" @@ -271,7 +280,6 @@ class VPCSVM(BaseVM): Reads the standard output of the VPCS process. Only use when the process has been stopped or has crashed. """ - # TODO: should be async output = "" if self._vpcs_stdout_file: try: diff --git a/gns3server/web/documentation.py b/gns3server/web/documentation.py index 35aee835..66ddf1f0 100644 --- a/gns3server/web/documentation.py +++ b/gns3server/web/documentation.py @@ -38,7 +38,7 @@ class Documentation(object): f.write('.. contents::\n') for method in handler_doc["methods"]: f.write('\n{} {}\n'.format(method["method"], path.replace("{", '**{').replace("}", "}**"))) - f.write('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n') + f.write('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n') f.write('{}\n\n'.format(method["description"])) if len(method["parameters"]) > 0: diff --git a/tests/api/test_vpcs.py b/tests/api/test_vpcs.py index 527738c4..e8b61981 100644 --- a/tests/api/test_vpcs.py +++ b/tests/api/test_vpcs.py @@ -119,6 +119,13 @@ def test_vpcs_stop(server, vm): assert response.status == 204 +def test_vpcs_reload(server, vm): + with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock: + response = server.post("/vpcs/{}/reload".format(vm["uuid"])) + assert mock.called + assert response.status == 204 + + def test_vpcs_update(server, vm, tmpdir, free_console_port): path = os.path.join(str(tmpdir), 'startup2.vpcs') with open(path, 'w+') as f: diff --git a/tests/modules/vpcs/test_vpcs_vm.py b/tests/modules/vpcs/test_vpcs_vm.py index 635b3834..c7c8518f 100644 --- a/tests/modules/vpcs/test_vpcs_vm.py +++ b/tests/modules/vpcs/test_vpcs_vm.py @@ -87,6 +87,19 @@ def test_stop(loop, vm): process.terminate.assert_called_with() +def test_reload(loop, vm): + process = MagicMock() + with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM._check_requirements", return_value=True): + with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): + nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) + + loop.run_until_complete(asyncio.async(vm.start())) + assert vm.is_running() + loop.run_until_complete(asyncio.async(vm.reload())) + assert vm.is_running() is True + process.terminate.assert_called_with() + + def test_add_nio_binding_udp(vm): nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) assert nio.lport == 4242