mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Rename port_id to port_number for VPCS and adapter_id for VirtualBox to avoid confusion.
This commit is contained in:
parent
e7c9139045
commit
22369ade49
@ -24,7 +24,7 @@ class NetworkHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/udp",
|
||||
r"/ports/udp",
|
||||
status_codes={
|
||||
201: "UDP port allocated",
|
||||
},
|
||||
|
@ -227,10 +227,10 @@ class VirtualBoxHandler:
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/ports/{port_id:\d+}/nio",
|
||||
r"/virtualbox/{uuid}/ports/{adapter_id:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port where the nio should be added"
|
||||
"adapter_id": "Adapter where the nio should be added"
|
||||
},
|
||||
status_codes={
|
||||
201: "NIO created",
|
||||
@ -245,16 +245,16 @@ class VirtualBoxHandler:
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
nio = vbox_manager.create_nio(vbox_manager.vboxmanage_path, request.json)
|
||||
vm.port_add_nio_binding(int(request.match_info["port_id"]), nio)
|
||||
vm.port_add_nio_binding(int(request.match_info["adapter_id"]), nio)
|
||||
response.set_status(201)
|
||||
response.json(nio)
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/virtualbox/{uuid}/ports/{port_id:\d+}/nio",
|
||||
r"/virtualbox/{uuid}/ports/{adapter_id:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port from where the nio should be removed"
|
||||
"adapter_id": "Adapter from where the nio should be removed"
|
||||
},
|
||||
status_codes={
|
||||
204: "NIO deleted",
|
||||
@ -266,14 +266,14 @@ class VirtualBoxHandler:
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm.port_remove_nio_binding(int(request.match_info["port_id"]))
|
||||
vm.port_remove_nio_binding(int(request.match_info["adapter_id"]))
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/capture/{port_id:\d+}/start",
|
||||
r"/virtualbox/{uuid}/capture/{adapter_id:\d+}/start",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port to start a packet capture"
|
||||
"adapter_id": "Adapter to start a packet capture"
|
||||
},
|
||||
status_codes={
|
||||
200: "Capture started",
|
||||
@ -286,17 +286,16 @@ class VirtualBoxHandler:
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
port_id = int(request.match_info["port_id"])
|
||||
adapter_id = int(request.match_info["adapter_id"])
|
||||
pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["filename"])
|
||||
vm.start_capture(port_id, pcap_file_path)
|
||||
response.json({"port_id": port_id,
|
||||
"pcap_file_path": pcap_file_path})
|
||||
vm.start_capture(adapter_id, pcap_file_path)
|
||||
response.json({"pcap_file_path": pcap_file_path})
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/capture/{port_id:\d+}/stop",
|
||||
r"/virtualbox/{uuid}/capture/{adapter_id:\d+}/stop",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port to stop a packet capture"
|
||||
"adapter_id": "Adapter to stop a packet capture"
|
||||
},
|
||||
status_codes={
|
||||
204: "Capture stopped",
|
||||
@ -308,5 +307,5 @@ class VirtualBoxHandler:
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm.stop_capture(int(request.match_info["port_id"]))
|
||||
vm.stop_capture(int(request.match_info["adapter_id"]))
|
||||
response.set_status(204)
|
||||
|
@ -168,10 +168,10 @@ class VPCSHandler:
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/ports/{port_id:\d+}/nio",
|
||||
r"/vpcs/{uuid}/ports/{port_number:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port where the nio should be added"
|
||||
"port_number": "Port where the nio should be added"
|
||||
},
|
||||
status_codes={
|
||||
201: "NIO created",
|
||||
@ -186,16 +186,16 @@ class VPCSHandler:
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
nio = vpcs_manager.create_nio(vm.vpcs_path, request.json)
|
||||
vm.port_add_nio_binding(int(request.match_info["port_id"]), nio)
|
||||
vm.port_add_nio_binding(int(request.match_info["port_number"]), nio)
|
||||
response.set_status(201)
|
||||
response.json(nio)
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/vpcs/{uuid}/ports/{port_id:\d+}/nio",
|
||||
r"/vpcs/{uuid}/ports/{port_number:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"port_id": "ID of the port from where the nio should be removed"
|
||||
"port_number": "Port from where the nio should be removed"
|
||||
},
|
||||
status_codes={
|
||||
204: "NIO deleted",
|
||||
@ -207,5 +207,5 @@ class VPCSHandler:
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm.port_remove_nio_binding(int(request.match_info["port_id"]))
|
||||
vm.port_remove_nio_binding(int(request.match_info["port_number"]))
|
||||
response.set_status(204)
|
||||
|
@ -29,8 +29,8 @@ class Adapter(object):
|
||||
self._interfaces = interfaces
|
||||
|
||||
self._ports = {}
|
||||
for port_id in range(0, interfaces):
|
||||
self._ports[port_id] = None
|
||||
for port_number in range(0, interfaces):
|
||||
self._ports[port_number] = None
|
||||
|
||||
def removable(self):
|
||||
"""
|
||||
@ -42,7 +42,7 @@ class Adapter(object):
|
||||
|
||||
return True
|
||||
|
||||
def port_exists(self, port_id):
|
||||
def port_exists(self, port_number):
|
||||
"""
|
||||
Checks if a port exists on this adapter.
|
||||
|
||||
@ -50,39 +50,39 @@ class Adapter(object):
|
||||
False otherwise.
|
||||
"""
|
||||
|
||||
if port_id in self._ports:
|
||||
if port_number in self._ports:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_nio(self, port_id, nio):
|
||||
def add_nio(self, port_number, nio):
|
||||
"""
|
||||
Adds a NIO to a port on this adapter.
|
||||
|
||||
:param port_id: port ID (integer)
|
||||
:param port_number: port number (integer)
|
||||
:param nio: NIO instance
|
||||
"""
|
||||
|
||||
self._ports[port_id] = nio
|
||||
self._ports[port_number] = nio
|
||||
|
||||
def remove_nio(self, port_id):
|
||||
def remove_nio(self, port_number):
|
||||
"""
|
||||
Removes a NIO from a port on this adapter.
|
||||
|
||||
:param port_id: port ID (integer)
|
||||
:param port_number: port number (integer)
|
||||
"""
|
||||
|
||||
self._ports[port_id] = None
|
||||
self._ports[port_number] = None
|
||||
|
||||
def get_nio(self, port_id):
|
||||
def get_nio(self, port_number):
|
||||
"""
|
||||
Returns the NIO assigned to a port.
|
||||
|
||||
:params port_id: port ID (integer)
|
||||
:params port_number: port number (integer)
|
||||
|
||||
:returns: NIO instance
|
||||
"""
|
||||
|
||||
return self._ports[port_id]
|
||||
return self._ports[port_number]
|
||||
|
||||
@property
|
||||
def ports(self):
|
||||
|
@ -152,7 +152,8 @@ class VirtualBoxVM(BaseVM):
|
||||
else:
|
||||
yield from self._create_linked_clone()
|
||||
|
||||
yield from self.set_adapters(self._adapters)
|
||||
if self._adapters:
|
||||
yield from self.set_adapters(self._adapters)
|
||||
|
||||
@asyncio.coroutine
|
||||
def start(self):
|
||||
|
@ -317,47 +317,47 @@ class VPCSVM(BaseVM):
|
||||
return True
|
||||
return False
|
||||
|
||||
def port_add_nio_binding(self, port_id, nio):
|
||||
def port_add_nio_binding(self, port_number, nio):
|
||||
"""
|
||||
Adds a port NIO binding.
|
||||
|
||||
:param port_id: port ID
|
||||
:param port_number: port number
|
||||
:param nio: NIO instance to add to the slot/port
|
||||
"""
|
||||
|
||||
if not self._ethernet_adapter.port_exists(port_id):
|
||||
raise VPCSError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
|
||||
port_id=port_id))
|
||||
if not self._ethernet_adapter.port_exists(port_number):
|
||||
raise VPCSError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
|
||||
port_number=port_number))
|
||||
|
||||
self._ethernet_adapter.add_nio(port_id, nio)
|
||||
log.info("VPCS {name} {uuid}]: {nio} added to port {port_id}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
nio=nio,
|
||||
port_id=port_id))
|
||||
self._ethernet_adapter.add_nio(port_number, nio)
|
||||
log.info("VPCS {name} {uuid}]: {nio} added to port {port_number}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
return nio
|
||||
|
||||
def port_remove_nio_binding(self, port_id):
|
||||
def port_remove_nio_binding(self, port_number):
|
||||
"""
|
||||
Removes a port NIO binding.
|
||||
|
||||
:param port_id: port ID
|
||||
:param port_number: port number
|
||||
|
||||
:returns: NIO instance
|
||||
"""
|
||||
|
||||
if not self._ethernet_adapter.port_exists(port_id):
|
||||
raise VPCSError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
|
||||
port_id=port_id))
|
||||
if not self._ethernet_adapter.port_exists(port_number):
|
||||
raise VPCSError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
|
||||
port_number=port_number))
|
||||
|
||||
nio = self._ethernet_adapter.get_nio(port_id)
|
||||
nio = self._ethernet_adapter.get_nio(port_number)
|
||||
if str(nio) == "NIO UDP":
|
||||
self.manager.port_manager.release_udp_port(nio.lport)
|
||||
self._ethernet_adapter.remove_nio(port_id)
|
||||
self._ethernet_adapter.remove_nio(port_number)
|
||||
|
||||
log.info("VPCS {name} [{uuid}]: {nio} removed from port {port_id}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
nio=nio,
|
||||
port_id=port_id))
|
||||
log.info("VPCS {name} [{uuid}]: {nio} removed from port {port_number}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
return nio
|
||||
|
||||
def _build_command(self):
|
||||
|
@ -94,7 +94,7 @@ def test_vbox_nio_create_udp(server, vm):
|
||||
"rhost": "127.0.0.1"},
|
||||
example=True)
|
||||
assert response.status == 201
|
||||
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
|
||||
assert response.route == "/virtualbox/{uuid}/ports/{adapter_id:\d+}/nio"
|
||||
assert response.json["type"] == "nio_udp"
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ def test_vbox_delete_nio(server, vm):
|
||||
"rhost": "127.0.0.1"})
|
||||
response = server.delete("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||
assert response.status == 204
|
||||
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
|
||||
assert response.route == "/virtualbox/{uuid}/ports/{adapter_id:\d+}/nio"
|
||||
|
||||
|
||||
def test_vpcs_update(server, vm, free_console_port):
|
||||
|
@ -82,7 +82,7 @@ def test_vpcs_nio_create_udp(server, vm):
|
||||
"rhost": "127.0.0.1"},
|
||||
example=True)
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
assert response.json["type"] == "nio_udp"
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ def test_vpcs_nio_create_tap(server, vm):
|
||||
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_tap",
|
||||
"tap_device": "test"})
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
assert response.json["type"] == "nio_tap"
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ def test_vpcs_delete_nio(server, vm):
|
||||
"rhost": "127.0.0.1"})
|
||||
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||
assert response.status == 204
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
|
||||
|
||||
def test_vpcs_start(server, vm):
|
||||
|
@ -41,7 +41,6 @@ def test_vm(project, manager):
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert vm.vmname == "test"
|
||||
assert vm.linked_clone is False
|
||||
|
||||
|
||||
def test_vm_valid_virtualbox_api_version(loop, project, manager):
|
||||
|
Loading…
Reference in New Issue
Block a user