mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
VPCS reload
This commit is contained in:
parent
1a43ff118c
commit
8d3ea60404
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /project
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Create a project on the server
|
||||
|
||||
Response status codes
|
||||
|
@ -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
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /virtualbox
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Create a new VirtualBox VM instance
|
||||
|
||||
Response status codes
|
||||
@ -19,9 +19,9 @@ Input
|
||||
|
||||
<table>
|
||||
<tr> <th>Name</th> <th>Mandatory</th> <th>Type</th> <th>Description</th> </tr>
|
||||
<tr><td>linked_clone</td> <td> </td> <td>boolean</td> <td>either the VM is a linked clone or not</td> </tr>
|
||||
<tr><td>linked_clone</td> <td>✔</td> <td>boolean</td> <td>either the VM is a linked clone or not</td> </tr>
|
||||
<tr><td>name</td> <td>✔</td> <td>string</td> <td>VirtualBox VM instance name</td> </tr>
|
||||
<tr><td>project_uuid</td> <td> </td> <td>string</td> <td>Project UUID</td> </tr>
|
||||
<tr><td>project_uuid</td> <td>✔</td> <td>string</td> <td>Project UUID</td> </tr>
|
||||
<tr><td>uuid</td> <td> </td> <td>string</td> <td>VirtualBox VM instance UUID</td> </tr>
|
||||
<tr><td>vbox_id</td> <td> </td> <td>integer</td> <td>VirtualBox VM instance ID (for project created before GNS3 1.3)</td> </tr>
|
||||
<tr><td>vmname</td> <td>✔</td> <td>string</td> <td>VirtualBox VM name (in VirtualBox itself)</td> </tr>
|
||||
@ -35,7 +35,7 @@ Output
|
||||
<tr> <th>Name</th> <th>Mandatory</th> <th>Type</th> <th>Description</th> </tr>
|
||||
<tr><td>console</td> <td> </td> <td>integer</td> <td>console TCP port</td> </tr>
|
||||
<tr><td>name</td> <td>✔</td> <td>string</td> <td>VirtualBox VM instance name</td> </tr>
|
||||
<tr><td>project_uuid</td> <td> </td> <td>string</td> <td>Project UUID</td> </tr>
|
||||
<tr><td>project_uuid</td> <td>✔</td> <td>string</td> <td>Project UUID</td> </tr>
|
||||
<tr><td>uuid</td> <td>✔</td> <td>string</td> <td>VirtualBox VM instance UUID</td> </tr>
|
||||
</table>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /virtualbox/**{uuid}**/start
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Start a VirtualBox VM instance
|
||||
|
||||
Parameters
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /virtualbox/**{uuid}**/stop
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Stop a VirtualBox VM instance
|
||||
|
||||
Parameters
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /vpcs
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Create a new VPCS instance
|
||||
|
||||
Response status codes
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /vpcs/**{uuid}**/start
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Start a VPCS instance
|
||||
|
||||
Parameters
|
||||
|
@ -4,7 +4,7 @@
|
||||
.. contents::
|
||||
|
||||
POST /vpcs/**{uuid}**/stop
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Stop a VPCS instance
|
||||
|
||||
Parameters
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user