1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Add /projects before /project

This commit is contained in:
Julien Duponchelle 2015-02-06 17:42:25 +01:00
parent 27cbfbbdc6
commit e81dcd4bba
6 changed files with 61 additions and 59 deletions

View File

@ -182,10 +182,11 @@ class Config(object):
self._override_config[section] = content self._override_config[section] = content
@staticmethod @staticmethod
def instance(): def instance(files=[]):
""" """
Singleton to return only on instance of Config. Singleton to return only on instance of Config.
:params files: Array of configuration files (optionnal)
:returns: instance of Config :returns: instance of Config
""" """

View File

@ -47,7 +47,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms", r"/projects/{project_id}/virtualbox/vms",
parameters={ parameters={
"project_id": "UUID for the project" "project_id": "UUID for the project"
}, },
@ -78,7 +78,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.get( @Route.get(
r"/{project_id}/virtualbox/vms/{vm_id}", r"/projects/{project_id}/virtualbox/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -98,7 +98,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.put( @Route.put(
r"/{project_id}/virtualbox/vms/{vm_id}", r"/projects/{project_id}/virtualbox/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -126,7 +126,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.delete( @Route.delete(
r"/{project_id}/virtualbox/vms/{vm_id}", r"/projects/{project_id}/virtualbox/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -147,7 +147,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/start", r"/projects/{project_id}/virtualbox/vms/{vm_id}/start",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -167,7 +167,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/stop", r"/projects/{project_id}/virtualbox/vms/{vm_id}/stop",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -187,7 +187,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/suspend", r"/projects/{project_id}/virtualbox/vms/{vm_id}/suspend",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -207,7 +207,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/resume", r"/projects/{project_id}/virtualbox/vms/{vm_id}/resume",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -227,7 +227,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/reload", r"/projects/{project_id}/virtualbox/vms/{vm_id}/reload",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -246,7 +246,7 @@ class VirtualBoxHandler:
response.set_status(204) response.set_status(204)
@Route.post( @Route.post(
r"/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio", r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",
@ -271,7 +271,7 @@ class VirtualBoxHandler:
@classmethod @classmethod
@Route.delete( @Route.delete(
r"/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio", r"/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",
@ -291,7 +291,7 @@ class VirtualBoxHandler:
response.set_status(204) response.set_status(204)
@Route.post( @Route.post(
r"/{project_id}/virtualbox/{vm_id}/capture/{adapter_id:\d+}/start", r"/projects/{project_id}/virtualbox/{vm_id}/capture/{adapter_id:\d+}/start",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",
@ -314,7 +314,7 @@ class VirtualBoxHandler:
response.json({"pcap_file_path": pcap_file_path}) response.json({"pcap_file_path": pcap_file_path})
@Route.post( @Route.post(
r"/{project_id}/virtualbox/{vm_id}/capture/{adapter_id:\d+}/stop", r"/projects/{project_id}/virtualbox/{vm_id}/capture/{adapter_id:\d+}/stop",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",

View File

@ -31,7 +31,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/vpcs/vms", r"/projects/{project_id}/vpcs/vms",
parameters={ parameters={
"project_id": "UUID for the project" "project_id": "UUID for the project"
}, },
@ -56,7 +56,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.get( @Route.get(
r"/{project_id}/vpcs/vms/{vm_id}", r"/projects/{project_id}/vpcs/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -76,7 +76,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.put( @Route.put(
r"/{project_id}/vpcs/vms/{vm_id}", r"/projects/{project_id}/vpcs/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -101,7 +101,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.delete( @Route.delete(
r"/{project_id}/vpcs/vms/{vm_id}", r"/projects/{project_id}/vpcs/vms/{vm_id}",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -119,7 +119,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/vpcs/vms/{vm_id}/start", r"/projects/{project_id}/vpcs/vms/{vm_id}/start",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -139,7 +139,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/vpcs/vms/{vm_id}/stop", r"/projects/{project_id}/vpcs/vms/{vm_id}/stop",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance" "vm_id": "UUID for the instance"
@ -159,7 +159,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.post( @Route.post(
r"/{project_id}/vpcs/vms/{vm_id}/reload", r"/projects/{project_id}/vpcs/vms/{vm_id}/reload",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",
@ -178,7 +178,7 @@ class VPCSHandler:
response.set_status(204) response.set_status(204)
@Route.post( @Route.post(
r"/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio", r"/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",
@ -203,7 +203,7 @@ class VPCSHandler:
@classmethod @classmethod
@Route.delete( @Route.delete(
r"/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio", r"/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
parameters={ parameters={
"project_id": "UUID for the project", "project_id": "UUID for the project",
"vm_id": "UUID for the instance", "vm_id": "UUID for the instance",

View File

@ -78,6 +78,7 @@ def parse_arguments():
parser.add_argument("-v", "--version", help="show the version", action="version", version=__version__) parser.add_argument("-v", "--version", help="show the version", action="version", version=__version__)
parser.add_argument("--host", help="run on the given host/IP address", default="127.0.0.1") parser.add_argument("--host", help="run on the given host/IP address", default="127.0.0.1")
parser.add_argument("--port", help="run on the given port", type=int, default=8000) parser.add_argument("--port", help="run on the given port", type=int, default=8000)
parser.add_argument("--config", help="use this config file", type=str, default=None)
parser.add_argument("--ssl", action="store_true", help="run in SSL mode") parser.add_argument("--ssl", action="store_true", help="run in SSL mode")
parser.add_argument("--certfile", help="SSL cert file", default="") parser.add_argument("--certfile", help="SSL cert file", default="")
parser.add_argument("--certkey", help="SSL key file", default="") parser.add_argument("--certkey", help="SSL key file", default="")

View File

@ -22,7 +22,7 @@ from tests.utils import asyncio_patch
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def vm(server, project): def vm(server, project):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VMTEST", response = server.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VMTEST",
"vmname": "VMTEST", "vmname": "VMTEST",
"linked_clone": False}) "linked_clone": False})
assert mock.called assert mock.called
@ -33,7 +33,7 @@ def vm(server, project):
def test_vbox_create(server, project): def test_vbox_create(server, project):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True): with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
response = server.post("/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VM1", response = server.post("/projects/{project_id}/virtualbox/vms".format(project_id=project.id), {"name": "VM1",
"vmname": "VM1", "vmname": "VM1",
"linked_clone": False}, "linked_clone": False},
example=True) example=True)
@ -43,73 +43,73 @@ def test_vbox_create(server, project):
def test_vbox_get(server, project, vm): def test_vbox_get(server, project, vm):
response = server.get("/{project_id}/virtualbox/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) response = server.get("/projects/{project_id}/virtualbox/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 200 assert response.status == 200
assert response.route == "/{project_id}/virtualbox/vms/{vm_id}" assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}"
assert response.json["name"] == "VMTEST" assert response.json["name"] == "VMTEST"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
def test_vbox_start(server, vm): def test_vbox_start(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/virtualbox/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_vbox_stop(server, vm): def test_vbox_stop(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/stop".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_vbox_suspend(server, vm): def test_vbox_suspend(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/suspend".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/suspend".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_vbox_resume(server, vm): def test_vbox_resume(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/resume".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/resume".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_vbox_reload(server, vm): def test_vbox_reload(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock: with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock:
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/reload".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_vbox_nio_create_udp(server, vm): def test_vbox_nio_create_udp(server, vm):
response = server.post("/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], response = server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"],
vm_id=vm["vm_id"]), {"type": "nio_udp", vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242, "lport": 4242,
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"}, "rhost": "127.0.0.1"},
example=True) example=True)
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio" assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
assert response.json["type"] == "nio_udp" assert response.json["type"] == "nio_udp"
def test_vbox_delete_nio(server, vm): def test_vbox_delete_nio(server, vm):
server.post("/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], server.post("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"],
vm_id=vm["vm_id"]), {"type": "nio_udp", vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242, "lport": 4242,
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"}) "rhost": "127.0.0.1"})
response = server.delete("/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) response = server.delete("/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 204 assert response.status == 204
assert response.route == "/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio" assert response.route == "/projects/{project_id}/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
def test_vbox_update(server, vm, free_console_port): def test_vbox_update(server, vm, free_console_port):
response = server.put("/{project_id}/virtualbox/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test", response = server.put("/projects/{project_id}/virtualbox/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test",
"console": free_console_port}) "console": free_console_port})
assert response.status == 200 assert response.status == 200
assert response.json["name"] == "test" assert response.json["name"] == "test"

View File

@ -23,105 +23,105 @@ from unittest.mock import patch
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def vm(server, project): def vm(server, project):
response = server.post("/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1"}) response = server.post("/projects/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1"})
assert response.status == 201 assert response.status == 201
return response.json return response.json
def test_vpcs_create(server, project): def test_vpcs_create(server, project):
response = server.post("/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1"}, example=True) response = server.post("/projects/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1"}, example=True)
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/vpcs/vms" assert response.route == "/projects/{project_id}/vpcs/vms"
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
def test_vpcs_get(server, project, vm): def test_vpcs_get(server, project, vm):
response = server.get("/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) response = server.get("/projects/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 200 assert response.status == 200
assert response.route == "/{project_id}/vpcs/vms/{vm_id}" assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}"
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
def test_vpcs_create_startup_script(server, project): def test_vpcs_create_startup_script(server, project):
response = server.post("/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1", "startup_script": "ip 192.168.1.2\necho TEST"}) response = server.post("/projects/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1", "startup_script": "ip 192.168.1.2\necho TEST"})
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/vpcs/vms" assert response.route == "/projects/{project_id}/vpcs/vms"
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST" assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST"
def test_vpcs_create_port(server, project, free_console_port): def test_vpcs_create_port(server, project, free_console_port):
response = server.post("/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1", "console": free_console_port}) response = server.post("/projects/{project_id}/vpcs/vms".format(project_id=project.id), {"name": "PC TEST 1", "console": free_console_port})
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/vpcs/vms" assert response.route == "/projects/{project_id}/vpcs/vms"
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == project.id
assert response.json["console"] == free_console_port assert response.json["console"] == free_console_port
def test_vpcs_nio_create_udp(server, vm): def test_vpcs_nio_create_udp(server, vm):
response = server.post("/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp", response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242, "lport": 4242,
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"}, "rhost": "127.0.0.1"},
example=True) example=True)
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio" assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_udp" assert response.json["type"] == "nio_udp"
def test_vpcs_nio_create_tap(server, vm): def test_vpcs_nio_create_tap(server, vm):
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True): with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True):
response = server.post("/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap", response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_tap",
"tap_device": "test"}) "tap_device": "test"})
assert response.status == 201 assert response.status == 201
assert response.route == "/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio" assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_tap" assert response.json["type"] == "nio_tap"
def test_vpcs_delete_nio(server, vm): def test_vpcs_delete_nio(server, vm):
server.post("/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp", server.post("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"type": "nio_udp",
"lport": 4242, "lport": 4242,
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"}) "rhost": "127.0.0.1"})
response = server.delete("/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True) response = server.delete("/projects/{project_id}/vpcs/vms/{vm_id}/ports/0/nio".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
assert response.status == 204 assert response.status == 204
assert response.route == "/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio" assert response.route == "/projects/{project_id}/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
def test_vpcs_start(server, vm): def test_vpcs_start(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock: with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
response = server.post("/{project_id}/vpcs/vms/{vm_id}/start".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/vpcs/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_vpcs_stop(server, vm): def test_vpcs_stop(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock: with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
response = server.post("/{project_id}/vpcs/vms/{vm_id}/stop".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/stop".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_vpcs_reload(server, vm): def test_vpcs_reload(server, vm):
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock: with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.reload", return_value=True) as mock:
response = server.post("/{project_id}/vpcs/vms/{vm_id}/reload".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.post("/projects/{project_id}/vpcs/vms/{vm_id}/reload".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_vpcs_delete(server, vm): def test_vpcs_delete(server, vm):
with asyncio_patch("gns3server.modules.vpcs.VPCS.delete_vm", return_value=True) as mock: with asyncio_patch("gns3server.modules.vpcs.VPCS.delete_vm", return_value=True) as mock:
response = server.delete("/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"])) response = server.delete("/projects/{project_id}/vpcs/vms/{vm_id}".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_vpcs_update(server, vm, tmpdir, free_console_port): def test_vpcs_update(server, vm, tmpdir, free_console_port):
response = server.put("/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test", response = server.put("/projects/{project_id}/vpcs/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test",
"console": free_console_port, "console": free_console_port,
"startup_script": "ip 192.168.1.1"}) "startup_script": "ip 192.168.1.1"})
assert response.status == 200 assert response.status == 200