mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Explicit ID names, remove {uuid} from URLs and add vms in URLs for VMs.
This commit is contained in:
parent
568e203580
commit
1bea78194c
@ -33,7 +33,7 @@ class ProjectHandler:
|
||||
pm = ProjectManager.instance()
|
||||
p = pm.create_project(
|
||||
location=request.json.get("location"),
|
||||
uuid=request.json.get("project_id"),
|
||||
project_id=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False)
|
||||
)
|
||||
response.json(p)
|
||||
|
@ -33,7 +33,7 @@ class VirtualBoxHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/virtualbox/vms",
|
||||
r"/virtualbox/vms_tmp",
|
||||
status_codes={
|
||||
200: "Success",
|
||||
},
|
||||
@ -46,10 +46,10 @@ class VirtualBoxHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox",
|
||||
r"/virtualbox/vms",
|
||||
status_codes={
|
||||
201: "Instance created",
|
||||
400: "Invalid project UUID",
|
||||
400: "Invalid project ID",
|
||||
409: "Conflict"
|
||||
},
|
||||
description="Create a new VirtualBox VM instance",
|
||||
@ -60,7 +60,7 @@ class VirtualBoxHandler:
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = yield from vbox_manager.create_vm(request.json.pop("name"),
|
||||
request.json.pop("project_id"),
|
||||
request.json.get("uuid"),
|
||||
request.json.get("vm_id"),
|
||||
request.json.pop("vmname"),
|
||||
request.json.pop("linked_clone"),
|
||||
adapters=request.json.get("adapters", 0))
|
||||
@ -74,9 +74,9 @@ class VirtualBoxHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/virtualbox/{uuid}",
|
||||
r"/virtualbox/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
200: "Success",
|
||||
@ -87,14 +87,14 @@ class VirtualBoxHandler:
|
||||
def show(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
response.json(vm)
|
||||
|
||||
@classmethod
|
||||
@Route.put(
|
||||
r"/virtualbox/{uuid}",
|
||||
r"/virtualbox/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
200: "Instance updated",
|
||||
@ -107,7 +107,7 @@ class VirtualBoxHandler:
|
||||
def update(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
|
||||
for name, value in request.json.items():
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
@ -118,9 +118,9 @@ class VirtualBoxHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/virtualbox/{uuid}",
|
||||
r"/virtualbox/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance deleted",
|
||||
@ -129,14 +129,14 @@ class VirtualBoxHandler:
|
||||
description="Delete a VirtualBox VM instance")
|
||||
def delete(request, response):
|
||||
|
||||
yield from VirtualBox.instance().delete_vm(request.match_info["uuid"])
|
||||
yield from VirtualBox.instance().delete_vm(request.match_info["vm_id"])
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/start",
|
||||
r"/virtualbox/vms/{vm_id}/start",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance started",
|
||||
@ -147,15 +147,15 @@ class VirtualBoxHandler:
|
||||
def start(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.start()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/stop",
|
||||
r"/virtualbox/vms/{vm_id}/stop",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance stopped",
|
||||
@ -166,15 +166,15 @@ class VirtualBoxHandler:
|
||||
def stop(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.stop()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/suspend",
|
||||
r"/virtualbox/vms/{vm_id}/suspend",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance suspended",
|
||||
@ -185,15 +185,15 @@ class VirtualBoxHandler:
|
||||
def suspend(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.suspend()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/resume",
|
||||
r"/virtualbox/vms/{vm_id}/resume",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance resumed",
|
||||
@ -204,15 +204,15 @@ class VirtualBoxHandler:
|
||||
def suspend(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.resume()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/reload",
|
||||
r"/virtualbox/vms/{vm_id}/reload",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance reloaded",
|
||||
@ -223,14 +223,14 @@ class VirtualBoxHandler:
|
||||
def suspend(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.reload()
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/adapters/{adapter_id:\d+}/nio",
|
||||
r"/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"adapter_id": "Adapter where the nio should be added"
|
||||
},
|
||||
status_codes={
|
||||
@ -244,7 +244,7 @@ class VirtualBoxHandler:
|
||||
def create_nio(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
nio = vbox_manager.create_nio(vbox_manager.vboxmanage_path, request.json)
|
||||
vm.port_add_nio_binding(int(request.match_info["adapter_id"]), nio)
|
||||
response.set_status(201)
|
||||
@ -252,9 +252,9 @@ class VirtualBoxHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/virtualbox/{uuid}/adapters/{adapter_id:\d+}/nio",
|
||||
r"/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"adapter_id": "Adapter from where the nio should be removed"
|
||||
},
|
||||
status_codes={
|
||||
@ -266,14 +266,14 @@ class VirtualBoxHandler:
|
||||
def delete_nio(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
vm.port_remove_nio_binding(int(request.match_info["adapter_id"]))
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/capture/{adapter_id:\d+}/start",
|
||||
r"/virtualbox/{vm_id}/capture/{adapter_id:\d+}/start",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"adapter_id": "Adapter to start a packet capture"
|
||||
},
|
||||
status_codes={
|
||||
@ -286,16 +286,16 @@ class VirtualBoxHandler:
|
||||
def start_capture(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_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(adapter_id, pcap_file_path)
|
||||
response.json({"pcap_file_path": pcap_file_path})
|
||||
|
||||
@Route.post(
|
||||
r"/virtualbox/{uuid}/capture/{adapter_id:\d+}/stop",
|
||||
r"/virtualbox/{vm_id}/capture/{adapter_id:\d+}/stop",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"adapter_id": "Adapter to stop a packet capture"
|
||||
},
|
||||
status_codes={
|
||||
@ -307,6 +307,6 @@ class VirtualBoxHandler:
|
||||
def start_capture(request, response):
|
||||
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vbox_manager.get_vm(request.match_info["vm_id"])
|
||||
vm.stop_capture(int(request.match_info["adapter_id"]))
|
||||
response.set_status(204)
|
||||
|
@ -31,7 +31,7 @@ class VPCSHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/vpcs",
|
||||
r"/vpcs/vms",
|
||||
status_codes={
|
||||
201: "Instance created",
|
||||
400: "Invalid project UUID",
|
||||
@ -45,7 +45,7 @@ class VPCSHandler:
|
||||
vpcs = VPCS.instance()
|
||||
vm = yield from vpcs.create_vm(request.json["name"],
|
||||
request.json["project_id"],
|
||||
request.json.get("uuid"),
|
||||
request.json.get("vm_id"),
|
||||
console=request.json.get("console"),
|
||||
startup_script=request.json.get("startup_script"))
|
||||
response.set_status(201)
|
||||
@ -53,9 +53,9 @@ class VPCSHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/vpcs/{uuid}",
|
||||
r"/vpcs/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
200: "Success",
|
||||
@ -66,14 +66,14 @@ class VPCSHandler:
|
||||
def show(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
response.json(vm)
|
||||
|
||||
@classmethod
|
||||
@Route.put(
|
||||
r"/vpcs/{uuid}",
|
||||
r"/vpcs/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
200: "Instance updated",
|
||||
@ -86,7 +86,7 @@ class VPCSHandler:
|
||||
def update(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
vm.name = request.json.get("name", vm.name)
|
||||
vm.console = request.json.get("console", vm.console)
|
||||
vm.startup_script = request.json.get("startup_script", vm.startup_script)
|
||||
@ -94,9 +94,9 @@ class VPCSHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/vpcs/{uuid}",
|
||||
r"/vpcs/vms/{vm_id}",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance deleted",
|
||||
@ -105,14 +105,14 @@ class VPCSHandler:
|
||||
description="Delete a VPCS instance")
|
||||
def delete(request, response):
|
||||
|
||||
yield from VPCS.instance().delete_vm(request.match_info["uuid"])
|
||||
yield from VPCS.instance().delete_vm(request.match_info["vm_id"])
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/start",
|
||||
r"/vpcs/vms/{vm_id}/start",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance started",
|
||||
@ -123,15 +123,15 @@ class VPCSHandler:
|
||||
def start(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.start()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/stop",
|
||||
r"/vpcs/vms/{vm_id}/stop",
|
||||
parameters={
|
||||
"uuid": "Instance UUID"
|
||||
"vm_id": "UUID for the instance"
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance stopped",
|
||||
@ -142,15 +142,15 @@ class VPCSHandler:
|
||||
def stop(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.stop()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/reload",
|
||||
r"/vpcs/vms/{vm_id}/reload",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
},
|
||||
status_codes={
|
||||
204: "Instance reloaded",
|
||||
@ -161,14 +161,14 @@ class VPCSHandler:
|
||||
def reload(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
yield from vm.reload()
|
||||
response.set_status(204)
|
||||
|
||||
@Route.post(
|
||||
r"/vpcs/{uuid}/ports/{port_number:\d+}/nio",
|
||||
r"/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"port_number": "Port where the nio should be added"
|
||||
},
|
||||
status_codes={
|
||||
@ -182,7 +182,7 @@ class VPCSHandler:
|
||||
def create_nio(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
nio = vpcs_manager.create_nio(vm.vpcs_path, request.json)
|
||||
vm.port_add_nio_binding(int(request.match_info["port_number"]), nio)
|
||||
response.set_status(201)
|
||||
@ -190,9 +190,9 @@ class VPCSHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/vpcs/{uuid}/ports/{port_number:\d+}/nio",
|
||||
r"/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio",
|
||||
parameters={
|
||||
"uuid": "Instance UUID",
|
||||
"vm_id": "UUID for the instance",
|
||||
"port_number": "Port from where the nio should be removed"
|
||||
},
|
||||
status_codes={
|
||||
@ -204,6 +204,6 @@ class VPCSHandler:
|
||||
def delete_nio(request, response):
|
||||
|
||||
vpcs_manager = VPCS.instance()
|
||||
vm = vpcs_manager.get_vm(request.match_info["uuid"])
|
||||
vm = vpcs_manager.get_vm(request.match_info["vm_id"])
|
||||
vm.port_remove_nio_binding(int(request.match_info["port_number"]))
|
||||
response.set_status(204)
|
||||
|
@ -97,71 +97,72 @@ class BaseManager:
|
||||
@asyncio.coroutine
|
||||
def unload(self):
|
||||
|
||||
for uuid in self._vms.keys():
|
||||
for vm_id in self._vms.keys():
|
||||
try:
|
||||
yield from self.close_vm(uuid)
|
||||
yield from self.close_vm(vm_id)
|
||||
except Exception as e:
|
||||
log.error("Could not delete VM {}: {}".format(uuid, e), exc_info=1)
|
||||
log.error("Could not delete VM {}: {}".format(vm_id, e), exc_info=1)
|
||||
continue
|
||||
|
||||
if hasattr(BaseManager, "_instance"):
|
||||
BaseManager._instance = None
|
||||
log.debug("Module {} unloaded".format(self.module_name))
|
||||
|
||||
def get_vm(self, uuid):
|
||||
def get_vm(self, vm_id):
|
||||
"""
|
||||
Returns a VM instance.
|
||||
|
||||
:param uuid: VM UUID
|
||||
:param vm_id: VM identifier
|
||||
|
||||
:returns: VM instance
|
||||
"""
|
||||
|
||||
try:
|
||||
UUID(uuid, version=4)
|
||||
UUID(vm_id, version=4)
|
||||
except ValueError:
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(uuid))
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(vm_id))
|
||||
|
||||
if uuid not in self._vms:
|
||||
raise aiohttp.web.HTTPNotFound(text="UUID {} doesn't exist".format(uuid))
|
||||
return self._vms[uuid]
|
||||
if vm_id not in self._vms:
|
||||
raise aiohttp.web.HTTPNotFound(text="ID {} doesn't exist".format(vm_id))
|
||||
return self._vms[vm_id]
|
||||
|
||||
@asyncio.coroutine
|
||||
def create_vm(self, name, project_uuid, uuid, *args, **kwargs):
|
||||
def create_vm(self, name, project_id, vm_id, *args, **kwargs):
|
||||
"""
|
||||
Create a new VM
|
||||
|
||||
:param name: VM name
|
||||
:param project_uuid: UUID of Project
|
||||
:param uuid: restore a VM UUID
|
||||
:param project_id: Project identifier
|
||||
:param vm_id: restore a VM identifier
|
||||
"""
|
||||
|
||||
project = ProjectManager.instance().get_project(project_uuid)
|
||||
project = ProjectManager.instance().get_project(project_id)
|
||||
|
||||
# TODO: support for old projects VM with normal IDs.
|
||||
|
||||
if not uuid:
|
||||
uuid = str(uuid4())
|
||||
if not vm_id:
|
||||
vm_id = str(uuid4())
|
||||
|
||||
vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs)
|
||||
vm = self._VM_CLASS(name, vm_id, project, self, *args, **kwargs)
|
||||
if asyncio.iscoroutinefunction(vm.create):
|
||||
yield from vm.create()
|
||||
else:
|
||||
vm.create()
|
||||
self._vms[vm.uuid] = vm
|
||||
self._vms[vm.id] = vm
|
||||
project.add_vm(vm)
|
||||
return vm
|
||||
|
||||
@asyncio.coroutine
|
||||
def close_vm(self, uuid):
|
||||
def close_vm(self, vm_id):
|
||||
"""
|
||||
Delete a VM
|
||||
|
||||
:param uuid: VM UUID
|
||||
:param vm_id: VM identifier
|
||||
|
||||
:returns: VM instance
|
||||
"""
|
||||
|
||||
vm = self.get_vm(uuid)
|
||||
vm = self.get_vm(vm_id)
|
||||
if asyncio.iscoroutinefunction(vm.close):
|
||||
yield from vm.close()
|
||||
else:
|
||||
@ -169,18 +170,18 @@ class BaseManager:
|
||||
return vm
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_vm(self, uuid):
|
||||
def delete_vm(self, vm_id):
|
||||
"""
|
||||
Delete a VM. VM working directory will be destroy when
|
||||
we receive a commit.
|
||||
|
||||
:param uuid: VM UUID
|
||||
:param vm_id: VM identifier
|
||||
:returns: VM instance
|
||||
"""
|
||||
|
||||
vm = yield from self.close_vm(uuid)
|
||||
vm = yield from self.close_vm(vm_id)
|
||||
vm.project.mark_vm_for_destruction(vm)
|
||||
del self._vms[vm.uuid]
|
||||
del self._vms[vm.id]
|
||||
return vm
|
||||
|
||||
@staticmethod
|
||||
|
@ -21,16 +21,16 @@ log = logging.getLogger(__name__)
|
||||
|
||||
class BaseVM:
|
||||
|
||||
def __init__(self, name, uuid, project, manager):
|
||||
def __init__(self, name, vm_id, project, manager):
|
||||
|
||||
self._name = name
|
||||
self._uuid = uuid
|
||||
self._id = vm_id
|
||||
self._project = project
|
||||
self._manager = manager
|
||||
|
||||
log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name,
|
||||
log.debug("{module}: {name} [{id}] initialized".format(module=self.manager.module_name,
|
||||
name=self.name,
|
||||
uuid=self.uuid))
|
||||
id=self.id))
|
||||
|
||||
def __del__(self):
|
||||
|
||||
@ -64,21 +64,21 @@ class BaseVM:
|
||||
:param new_name: name
|
||||
"""
|
||||
|
||||
log.info("{module}: {name} [{uuid}] renamed to {new_name}".format(module=self.manager.module_name,
|
||||
log.info("{module}: {name} [{id}] renamed to {new_name}".format(module=self.manager.module_name,
|
||||
name=self.name,
|
||||
uuid=self.uuid,
|
||||
id=self.id,
|
||||
new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
def uuid(self):
|
||||
def id(self):
|
||||
"""
|
||||
Returns the UUID for this VM.
|
||||
Returns the ID for this VM.
|
||||
|
||||
:returns: uuid (string)
|
||||
:returns: VM identifier (string)
|
||||
"""
|
||||
|
||||
return self._uuid
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def manager(self):
|
||||
@ -103,9 +103,9 @@ class BaseVM:
|
||||
Creates the VM.
|
||||
"""
|
||||
|
||||
log.info("{module}: {name} [{uuid}] created".format(module=self.manager.module_name,
|
||||
log.info("{module}: {name} [{id}] created".format(module=self.manager.module_name,
|
||||
name=self.name,
|
||||
uuid=self.uuid))
|
||||
id=self.id))
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
|
@ -34,21 +34,21 @@ class Project:
|
||||
A project contains a list of VM.
|
||||
In theory VM are isolated project/project.
|
||||
|
||||
:param uuid: Force project uuid (None by default auto generate an UUID)
|
||||
:param project_id: Force project identifier (None by default auto generate an UUID)
|
||||
:param location: Parent path of the project. (None should create a tmp directory)
|
||||
:param temporary: Boolean the project is a temporary project (destroy when closed)
|
||||
"""
|
||||
|
||||
def __init__(self, uuid=None, location=None, temporary=False):
|
||||
def __init__(self, project_id=None, location=None, temporary=False):
|
||||
|
||||
if uuid is None:
|
||||
self._uuid = str(uuid4())
|
||||
if project_id is None:
|
||||
self._id = str(uuid4())
|
||||
else:
|
||||
try:
|
||||
UUID(uuid, version=4)
|
||||
UUID(project_id, version=4)
|
||||
except ValueError:
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(uuid))
|
||||
self._uuid = uuid
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(project_id))
|
||||
self._id = project_id
|
||||
|
||||
config = Config.instance().get_section_config("Server")
|
||||
self._location = location
|
||||
@ -60,13 +60,13 @@ class Project:
|
||||
|
||||
self._vms = set()
|
||||
self._vms_to_destroy = set()
|
||||
self._path = os.path.join(self._location, self._uuid)
|
||||
self._path = os.path.join(self._location, self._id)
|
||||
try:
|
||||
os.makedirs(os.path.join(self._path, "vms"), exist_ok=True)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
||||
self.temporary = temporary
|
||||
log.debug("Create project {uuid} in directory {path}".format(path=self._path, uuid=self._uuid))
|
||||
log.debug("Create project {id} in directory {path}".format(path=self._path, id=self._id))
|
||||
|
||||
@classmethod
|
||||
def _get_default_project_directory(cls):
|
||||
@ -83,9 +83,9 @@ class Project:
|
||||
return path
|
||||
|
||||
@property
|
||||
def uuid(self):
|
||||
def id(self):
|
||||
|
||||
return self._uuid
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def location(self):
|
||||
@ -134,7 +134,7 @@ class Project:
|
||||
:returns: A string with a VM working directory
|
||||
"""
|
||||
|
||||
workdir = os.path.join(self._path, vm.manager.module_name.lower(), vm.uuid)
|
||||
workdir = os.path.join(self._path, vm.manager.module_name.lower(), vm.id)
|
||||
try:
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
except OSError as e:
|
||||
@ -166,7 +166,7 @@ class Project:
|
||||
def __json__(self):
|
||||
|
||||
return {
|
||||
"project_id": self._uuid,
|
||||
"project_id": self._id,
|
||||
"location": self._location,
|
||||
"temporary": self._temporary
|
||||
}
|
||||
|
@ -42,23 +42,23 @@ class ProjectManager:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def get_project(self, uuid):
|
||||
def get_project(self, project_id):
|
||||
"""
|
||||
Returns a Project instance.
|
||||
|
||||
:param uuid: Project UUID
|
||||
:param project_id: Project identifier
|
||||
|
||||
:returns: Project instance
|
||||
"""
|
||||
|
||||
try:
|
||||
UUID(uuid, version=4)
|
||||
UUID(project_id, version=4)
|
||||
except ValueError:
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(uuid))
|
||||
raise aiohttp.web.HTTPBadRequest(text="{} is not a valid UUID".format(project_id))
|
||||
|
||||
if uuid not in self._projects:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project UUID {} doesn't exist".format(uuid))
|
||||
return self._projects[uuid]
|
||||
if project_id not in self._projects:
|
||||
raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't exist".format(project_id))
|
||||
return self._projects[project_id]
|
||||
|
||||
def create_project(self, **kwargs):
|
||||
"""
|
||||
@ -68,5 +68,5 @@ class ProjectManager:
|
||||
"""
|
||||
|
||||
project = Project(**kwargs)
|
||||
self._projects[project.uuid] = project
|
||||
self._projects[project.id] = project
|
||||
return project
|
||||
|
@ -119,7 +119,7 @@ class VirtualBox(BaseManager):
|
||||
vms = []
|
||||
result = yield from self.execute("list", ["vms"])
|
||||
for line in result:
|
||||
vmname, uuid = line.rsplit(' ', 1)
|
||||
vmname, _ = line.rsplit(' ', 1)
|
||||
vmname = vmname.strip('"')
|
||||
if vmname == "<inaccessible>":
|
||||
continue # ignore inaccessible VMs
|
||||
|
@ -48,9 +48,9 @@ class VirtualBoxVM(BaseVM):
|
||||
VirtualBox VM implementation.
|
||||
"""
|
||||
|
||||
def __init__(self, name, uuid, project, manager, vmname, linked_clone, adapters=0):
|
||||
def __init__(self, name, vm_id, project, manager, vmname, linked_clone, adapters=0):
|
||||
|
||||
super().__init__(name, uuid, project, manager)
|
||||
super().__init__(name, vm_id, project, manager)
|
||||
|
||||
self._maximum_adapters = 8
|
||||
self._linked_clone = linked_clone
|
||||
@ -77,9 +77,9 @@ class VirtualBoxVM(BaseVM):
|
||||
def __json__(self):
|
||||
|
||||
return {"name": self.name,
|
||||
"uuid": self.uuid,
|
||||
"vm_id": self.id,
|
||||
"console": self.console,
|
||||
"project_id": self.project.uuid,
|
||||
"project_id": self.project.id,
|
||||
"vmname": self.vmname,
|
||||
"headless": self.headless,
|
||||
"enable_remote_console": self.enable_remote_console,
|
||||
@ -144,10 +144,10 @@ class VirtualBoxVM(BaseVM):
|
||||
yield from self._get_system_properties()
|
||||
if parse_version(self._system_properties["API version"]) < parse_version("4_3"):
|
||||
raise VirtualBoxError("The VirtualBox API version is lower than 4.3")
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] created".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] created".format(name=self.name, id=self.id))
|
||||
|
||||
if self._linked_clone:
|
||||
if self.uuid and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
|
||||
if self.id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
|
||||
vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")
|
||||
yield from self.manager.execute("registervm", [vbox_file])
|
||||
yield from self._reattach_hdds()
|
||||
@ -180,7 +180,7 @@ class VirtualBoxVM(BaseVM):
|
||||
if self._headless:
|
||||
args.extend(["--type", "headless"])
|
||||
result = yield from self.manager.execute("startvm", args)
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] started".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] started".format(name=self.name, id=self.id))
|
||||
log.debug("Start result: {}".format(result))
|
||||
|
||||
# add a guest property to let the VM know about the GNS3 name
|
||||
@ -202,7 +202,7 @@ class VirtualBoxVM(BaseVM):
|
||||
if vm_state == "running" or vm_state == "paused" or vm_state == "stuck":
|
||||
# power off the VM
|
||||
result = yield from self._control_vm("poweroff")
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] stopped".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
||||
log.debug("Stop result: {}".format(result))
|
||||
|
||||
yield from asyncio.sleep(0.5) # give some time for VirtualBox to unlock the VM
|
||||
@ -228,10 +228,10 @@ class VirtualBoxVM(BaseVM):
|
||||
vm_state = yield from self._get_vm_state()
|
||||
if vm_state == "running":
|
||||
yield from self._control_vm("pause")
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] suspended".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] suspended".format(name=self.name, id=self.id))
|
||||
else:
|
||||
log.warn("VirtualBox VM '{name}' [{uuid}] cannot be suspended, current state: {state}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.warn("VirtualBox VM '{name}' [{id}] cannot be suspended, current state: {state}".format(name=self.name,
|
||||
id=self.id,
|
||||
state=vm_state))
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -241,7 +241,7 @@ class VirtualBoxVM(BaseVM):
|
||||
"""
|
||||
|
||||
yield from self._control_vm("resume")
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] resumed".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
||||
|
||||
@asyncio.coroutine
|
||||
def reload(self):
|
||||
@ -250,7 +250,7 @@ class VirtualBoxVM(BaseVM):
|
||||
"""
|
||||
|
||||
result = yield from self._control_vm("reset")
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] reloaded".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] reloaded".format(name=self.name, id=self.id))
|
||||
log.debug("Reload result: {}".format(result))
|
||||
|
||||
@property
|
||||
@ -275,8 +275,8 @@ class VirtualBoxVM(BaseVM):
|
||||
self._manager.port_manager.release_console_port(self._console)
|
||||
|
||||
self._console = self._manager.port_manager.reserve_console_port(console)
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: console port set to {port}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: console port set to {port}".format(name=self.name,
|
||||
id=self.id,
|
||||
port=console))
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -306,8 +306,8 @@ class VirtualBoxVM(BaseVM):
|
||||
for hdd_info in hdd_table:
|
||||
hdd_file = os.path.join(self.working_dir, self._vmname, "Snapshots", hdd_info["hdd"])
|
||||
if os.path.exists(hdd_file):
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] attaching HDD {controller} {port} {device} {medium}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}] attaching HDD {controller} {port} {device} {medium}".format(name=self.name,
|
||||
id=self.id,
|
||||
controller=hdd_info["controller"],
|
||||
port=hdd_info["port"],
|
||||
device=hdd_info["device"],
|
||||
@ -345,8 +345,8 @@ class VirtualBoxVM(BaseVM):
|
||||
port = match.group(2)
|
||||
device = match.group(3)
|
||||
if value in hdd_files:
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] detaching HDD {controller} {port} {device}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}] detaching HDD {controller} {port} {device}".format(name=self.name,
|
||||
id=self.id,
|
||||
controller=controller,
|
||||
port=port,
|
||||
device=device))
|
||||
@ -360,7 +360,7 @@ class VirtualBoxVM(BaseVM):
|
||||
}
|
||||
)
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] unregistering".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] unregistering".format(name=self.name, id=self.id))
|
||||
yield from self.manager.execute("unregistervm", [self._name])
|
||||
|
||||
if hdd_table:
|
||||
@ -369,12 +369,11 @@ class VirtualBoxVM(BaseVM):
|
||||
with open(hdd_info_file, "w") as f:
|
||||
json.dump(hdd_table, f, indent=4)
|
||||
except OSError as e:
|
||||
log.warning("VirtualBox VM '{name}' [{uuid}] could not write HHD info file: {error}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.warning("VirtualBox VM '{name}' [{id}] could not write HHD info file: {error}".format(name=self.name,
|
||||
id=self.id,
|
||||
error=e.strerror))
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] closed".format(name=self.name,
|
||||
uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] closed".format(name=self.name, id=self.id))
|
||||
self._closed = True
|
||||
|
||||
@property
|
||||
@ -396,9 +395,9 @@ class VirtualBoxVM(BaseVM):
|
||||
"""
|
||||
|
||||
if headless:
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has enabled the headless mode".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] has enabled the headless mode".format(name=self.name, id=self.id))
|
||||
else:
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has disabled the headless mode".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] has disabled the headless mode".format(name=self.name, id=self.id))
|
||||
self._headless = headless
|
||||
|
||||
@property
|
||||
@ -420,10 +419,10 @@ class VirtualBoxVM(BaseVM):
|
||||
"""
|
||||
|
||||
if enable_remote_console:
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has enabled the console".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] has enabled the console".format(name=self.name, id=self.id))
|
||||
# self._start_remote_console()
|
||||
else:
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has disabled the console".format(name=self.name, uuid=self.uuid))
|
||||
log.info("VirtualBox VM '{name}' [{id}] has disabled the console".format(name=self.name, id=self.id))
|
||||
# self._stop_remote_console()
|
||||
self._enable_remote_console = enable_remote_console
|
||||
|
||||
@ -445,7 +444,7 @@ class VirtualBoxVM(BaseVM):
|
||||
:param vmname: VirtualBox VM name
|
||||
"""
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has set the VM name to '{vmname}'".format(name=self.name, uuid=self.uuid, vmname=vmname))
|
||||
log.info("VirtualBox VM '{name}' [{id}] has set the VM name to '{vmname}'".format(name=self.name, id=self.id, vmname=vmname))
|
||||
# TODO: test linked clone
|
||||
# if self._linked_clone:
|
||||
# yield from self._modify_vm('--name "{}"'.format(vmname))
|
||||
@ -472,8 +471,8 @@ class VirtualBoxVM(BaseVM):
|
||||
self._ethernet_adapters.append(EthernetAdapter())
|
||||
|
||||
self._adapters = len(self._ethernet_adapters)
|
||||
log.info("VirtualBox VM '{name}' [{uuid}] has changed the number of Ethernet adapters to {adapters}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}] has changed the number of Ethernet adapters to {adapters}".format(name=self.name,
|
||||
id=self.id,
|
||||
adapters=adapters))
|
||||
|
||||
@property
|
||||
@ -496,8 +495,8 @@ class VirtualBoxVM(BaseVM):
|
||||
|
||||
self._adapter_start_index = adapter_start_index
|
||||
self.adapters = self.adapters # this forces to recreate the adapter list with the correct index
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: adapter start index changed to {index}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: adapter start index changed to {index}".format(name=self.name,
|
||||
id=self.id,
|
||||
index=adapter_start_index))
|
||||
|
||||
@property
|
||||
@ -520,8 +519,8 @@ class VirtualBoxVM(BaseVM):
|
||||
|
||||
self._adapter_type = adapter_type
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: adapter type changed to {adapter_type}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: adapter type changed to {adapter_type}".format(name=self.name,
|
||||
id=self.id,
|
||||
adapter_type=adapter_type))
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -779,8 +778,8 @@ class VirtualBoxVM(BaseVM):
|
||||
yield from self._control_vm("setlinkstate{} on".format(adapter_id + 1))
|
||||
|
||||
adapter.add_nio(0, nio)
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: {nio} added to adapter {adapter_id}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: {nio} added to adapter {adapter_id}".format(name=self.name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
adapter_id=adapter_id))
|
||||
|
||||
@ -811,8 +810,8 @@ class VirtualBoxVM(BaseVM):
|
||||
self.manager.port_manager.release_udp_port(nio.lport)
|
||||
adapter.remove_nio(0)
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: {nio} removed from adapter {adapter_id}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: {nio} removed from adapter {adapter_id}".format(name=self.name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
adapter_id=adapter_id))
|
||||
return nio
|
||||
@ -836,8 +835,8 @@ class VirtualBoxVM(BaseVM):
|
||||
raise VirtualBoxError("Packet capture is already activated on adapter {adapter_id}".format(adapter_id=adapter_id))
|
||||
|
||||
nio.startPacketCapture(output_file)
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: starting packet capture on adapter {adapter_id}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: starting packet capture on adapter {adapter_id}".format(name=self.name,
|
||||
id=self.id,
|
||||
adapter_id=adapter_id))
|
||||
|
||||
def stop_capture(self, adapter_id):
|
||||
@ -856,6 +855,6 @@ class VirtualBoxVM(BaseVM):
|
||||
nio = adapter.get_nio(0)
|
||||
nio.stopPacketCapture()
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{uuid}]: stopping packet capture on adapter {adapter_id}".format(name=self.name,
|
||||
uuid=self.uuid,
|
||||
log.info("VirtualBox VM '{name}' [{id}]: stopping packet capture on adapter {adapter_id}".format(name=self.name,
|
||||
id=self.id,
|
||||
adapter_id=adapter_id))
|
||||
|
@ -38,28 +38,28 @@ class VPCS(BaseManager):
|
||||
def create_vm(self, *args, **kwargs):
|
||||
|
||||
vm = yield from super().create_vm(*args, **kwargs)
|
||||
self._free_mac_ids.setdefault(vm.project.uuid, list(range(0, 255)))
|
||||
self._free_mac_ids.setdefault(vm.project.id, list(range(0, 255)))
|
||||
try:
|
||||
self._used_mac_ids[vm.uuid] = self._free_mac_ids[vm.project.uuid].pop(0)
|
||||
self._used_mac_ids[vm.id] = self._free_mac_ids[vm.project.id].pop(0)
|
||||
except IndexError:
|
||||
raise VPCSError("No mac address available")
|
||||
return vm
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_vm(self, uuid, *args, **kwargs):
|
||||
def delete_vm(self, vm_id, *args, **kwargs):
|
||||
|
||||
vm = self.get_vm(uuid)
|
||||
i = self._used_mac_ids[uuid]
|
||||
self._free_mac_ids[vm.project.uuid].insert(0, i)
|
||||
del self._used_mac_ids[uuid]
|
||||
yield from super().delete_vm(uuid, *args, **kwargs)
|
||||
vm = self.get_vm(vm_id)
|
||||
i = self._used_mac_ids[vm_id]
|
||||
self._free_mac_ids[vm.project.id].insert(0, i)
|
||||
del self._used_mac_ids[vm_id]
|
||||
yield from super().delete_vm(vm_id, *args, **kwargs)
|
||||
|
||||
def get_mac_id(self, vm_uuid):
|
||||
def get_mac_id(self, vm_id):
|
||||
"""
|
||||
Get an unique VPCS mac id
|
||||
|
||||
:param vm_uuid: UUID of the VPCS vm
|
||||
:returns: VPCS Mac id
|
||||
:param vm_id: ID of the VPCS VM
|
||||
:returns: VPCS MAC id
|
||||
"""
|
||||
|
||||
return self._used_mac_ids.get(vm_uuid, 1)
|
||||
return self._used_mac_ids.get(vm_id, 1)
|
||||
|
@ -45,7 +45,7 @@ class VPCSVM(BaseVM):
|
||||
VPCS vm implementation.
|
||||
|
||||
:param name: name of this VPCS vm
|
||||
:param uuid: VPCS instance UUID
|
||||
:param vm_id: VPCS instance identifier
|
||||
:param project: Project instance
|
||||
:param manager: parent VM Manager
|
||||
:param console: TCP console port
|
||||
@ -53,9 +53,9 @@ class VPCSVM(BaseVM):
|
||||
:param startup_script: Content of vpcs startup script file
|
||||
"""
|
||||
|
||||
def __init__(self, name, uuid, project, manager, console=None, script_file=None, startup_script=None):
|
||||
def __init__(self, name, vm_id, project, manager, console=None, script_file=None, startup_script=None):
|
||||
|
||||
super().__init__(name, uuid, project, manager)
|
||||
super().__init__(name, vm_id, project, manager)
|
||||
|
||||
self._path = manager.config.get_section_config("VPCS").get("vpcs_path", "vpcs")
|
||||
self._console = console
|
||||
@ -105,9 +105,9 @@ class VPCSVM(BaseVM):
|
||||
def __json__(self):
|
||||
|
||||
return {"name": self.name,
|
||||
"uuid": self.uuid,
|
||||
"vm_id": self.id,
|
||||
"console": self._console,
|
||||
"project_id": self.project.uuid,
|
||||
"project_id": self.project.id,
|
||||
"script_file": self.script_file,
|
||||
"startup_script": self.startup_script}
|
||||
|
||||
@ -329,8 +329,8 @@ class VPCSVM(BaseVM):
|
||||
port_number=port_number))
|
||||
|
||||
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,
|
||||
log.info("VPCS {name} {id}]: {nio} added to port {port_number}".format(name=self._name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
return nio
|
||||
@ -353,8 +353,8 @@ class VPCSVM(BaseVM):
|
||||
self.manager.port_manager.release_udp_port(nio.lport)
|
||||
self._ethernet_adapter.remove_nio(port_number)
|
||||
|
||||
log.info("VPCS {name} [{uuid}]: {nio} removed from port {port_number}".format(name=self._name,
|
||||
uuid=self.uuid,
|
||||
log.info("VPCS {name} [{id}]: {nio} removed from port {port_number}".format(name=self._name,
|
||||
id=self.id,
|
||||
nio=nio,
|
||||
port_number=port_number))
|
||||
return nio
|
||||
@ -411,7 +411,7 @@ class VPCSVM(BaseVM):
|
||||
command.extend(["-e"])
|
||||
command.extend(["-d", nio.tap_vm])
|
||||
|
||||
command.extend(["-m", str(self._manager.get_mac_id(self._uuid))]) # the unique ID is used to set the MAC address offset
|
||||
command.extend(["-m", str(self._manager.get_mac_id(self.id))]) # the unique ID is used to set the MAC address offset
|
||||
command.extend(["-i", "1"]) # option to start only one VPC instance
|
||||
command.extend(["-F"]) # option to avoid the daemonization of VPCS
|
||||
if self._script_file:
|
||||
|
@ -21,16 +21,12 @@ VBOX_CREATE_SCHEMA = {
|
||||
"description": "Request validation to create a new VirtualBox VM instance",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uuid": {
|
||||
"description": "VirtualBox VM instance UUID",
|
||||
"vm_id": {
|
||||
"description": "VirtualBox VM instance identifier",
|
||||
"type": "string",
|
||||
"minLength": 36,
|
||||
"maxLength": 36,
|
||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
||||
},
|
||||
"vbox_id": {
|
||||
"description": "VirtualBox VM instance ID (for project created before GNS3 1.3)",
|
||||
"type": "integer"
|
||||
"pattern": "(^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}|\d+)$"
|
||||
},
|
||||
"project_id": {
|
||||
"description": "Project UUID",
|
||||
@ -204,7 +200,7 @@ VBOX_OBJECT_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"uuid": {
|
||||
"vm_id": {
|
||||
"description": "VirtualBox VM instance UUID",
|
||||
"type": "string",
|
||||
"minLength": 36,
|
||||
@ -256,5 +252,5 @@ VBOX_OBJECT_SCHEMA = {
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name", "uuid", "project_id"]
|
||||
"required": ["name", "vm_id", "project_id"]
|
||||
}
|
||||
|
@ -22,20 +22,16 @@ VPCS_CREATE_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "VPCS device name",
|
||||
"description": "VPCS VM name",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"vpcs_id": {
|
||||
"description": "VPCS device instance ID (for project created before GNS3 1.3)",
|
||||
"type": "integer"
|
||||
},
|
||||
"uuid": {
|
||||
"description": "VPCS device UUID",
|
||||
"vm_id": {
|
||||
"description": "VPCS VM identifier",
|
||||
"type": "string",
|
||||
"minLength": 36,
|
||||
"maxLength": 36,
|
||||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
|
||||
"pattern": "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}|\d+)$"
|
||||
},
|
||||
"project_id": {
|
||||
"description": "Project UUID",
|
||||
@ -65,7 +61,7 @@ VPCS_UPDATE_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "VPCS device name",
|
||||
"description": "VPCS VM name",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
@ -145,12 +141,12 @@ VPCS_OBJECT_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"description": "VPCS device name",
|
||||
"description": "VPCS VM name",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"uuid": {
|
||||
"description": "VPCS device UUID",
|
||||
"vm_id": {
|
||||
"description": "VPCS VM UUID",
|
||||
"type": "string",
|
||||
"minLength": 36,
|
||||
"maxLength": 36,
|
||||
@ -179,5 +175,5 @@ VPCS_OBJECT_SCHEMA = {
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name", "uuid", "console", "project_id"]
|
||||
"required": ["name", "vm_id", "console", "project_id"]
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ def test_update_temporary_project(server):
|
||||
|
||||
def test_commit_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock:
|
||||
response = server.post("/projects/{project_id}/commit".format(project_id=project.uuid), example=True)
|
||||
response = server.post("/projects/{project_id}/commit".format(project_id=project.id), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
@ -92,7 +92,7 @@ def test_commit_project_invalid_uuid(server):
|
||||
|
||||
def test_delete_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.delete", return_value=True) as mock:
|
||||
response = server.delete("/projects/{project_id}".format(project_id=project.uuid), example=True)
|
||||
response = server.delete("/projects/{project_id}".format(project_id=project.id), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
@ -104,7 +104,7 @@ def test_delete_project_invalid_uuid(server):
|
||||
|
||||
def test_close_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock:
|
||||
response = server.post("/projects/{project_id}/close".format(project_id=project.uuid), example=True)
|
||||
response = server.post("/projects/{project_id}/close".format(project_id=project.id), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
@ -22,10 +22,10 @@ from tests.utils import asyncio_patch
|
||||
@pytest.fixture(scope="module")
|
||||
def vm(server, project):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
|
||||
response = server.post("/virtualbox", {"name": "VMTEST",
|
||||
response = server.post("/virtualbox/vms", {"name": "VMTEST",
|
||||
"vmname": "VMTEST",
|
||||
"linked_clone": False,
|
||||
"project_id": project.uuid})
|
||||
"project_id": project.id})
|
||||
assert mock.called
|
||||
assert response.status == 201
|
||||
return response.json
|
||||
@ -34,82 +34,82 @@ def vm(server, project):
|
||||
def test_vbox_create(server, project):
|
||||
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True):
|
||||
response = server.post("/virtualbox", {"name": "VM1",
|
||||
response = server.post("/virtualbox/vms", {"name": "VM1",
|
||||
"vmname": "VM1",
|
||||
"linked_clone": False,
|
||||
"project_id": project.uuid},
|
||||
"project_id": project.id},
|
||||
example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == "VM1"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
|
||||
|
||||
def test_vbox_get(server, project, vm):
|
||||
response = server.get("/virtualbox/{}".format(vm["uuid"]), example=True)
|
||||
response = server.get("/virtualbox/vms/{}".format(vm["vm_id"]), example=True)
|
||||
assert response.status == 200
|
||||
assert response.route == "/virtualbox/{uuid}"
|
||||
assert response.route == "/virtualbox/vms/{vm_id}"
|
||||
assert response.json["name"] == "VMTEST"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
|
||||
|
||||
def test_vbox_start(server, vm):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
|
||||
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
|
||||
response = server.post("/virtualbox/vms/{}/start".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vbox_stop(server, vm):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.stop", return_value=True) as mock:
|
||||
response = server.post("/virtualbox/{}/stop".format(vm["uuid"]))
|
||||
response = server.post("/virtualbox/vms/{}/stop".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vbox_suspend(server, vm):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.suspend", return_value=True) as mock:
|
||||
response = server.post("/virtualbox/{}/suspend".format(vm["uuid"]))
|
||||
response = server.post("/virtualbox/vms/{}/suspend".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vbox_resume(server, vm):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.resume", return_value=True) as mock:
|
||||
response = server.post("/virtualbox/{}/resume".format(vm["uuid"]))
|
||||
response = server.post("/virtualbox/vms/{}/resume".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vbox_reload(server, vm):
|
||||
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.reload", return_value=True) as mock:
|
||||
response = server.post("/virtualbox/{}/reload".format(vm["uuid"]))
|
||||
response = server.post("/virtualbox/vms/{}/reload".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vbox_nio_create_udp(server, vm):
|
||||
response = server.post("/virtualbox/{}/adapters/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||
response = server.post("/virtualbox/vms/{}/adapters/0/nio".format(vm["vm_id"]), {"type": "nio_udp",
|
||||
"lport": 4242,
|
||||
"rport": 4343,
|
||||
"rhost": "127.0.0.1"},
|
||||
example=True)
|
||||
assert response.status == 201
|
||||
assert response.route == "/virtualbox/{uuid}/adapters/{adapter_id:\d+}/nio"
|
||||
assert response.route == "/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
|
||||
assert response.json["type"] == "nio_udp"
|
||||
|
||||
|
||||
def test_vbox_delete_nio(server, vm):
|
||||
server.post("/virtualbox/{}/adapters/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||
server.post("/virtualbox/vms/{}/adapters/0/nio".format(vm["vm_id"]), {"type": "nio_udp",
|
||||
"lport": 4242,
|
||||
"rport": 4343,
|
||||
"rhost": "127.0.0.1"})
|
||||
response = server.delete("/virtualbox/{}/adapters/0/nio".format(vm["uuid"]), example=True)
|
||||
response = server.delete("/virtualbox/vms/{}/adapters/0/nio".format(vm["vm_id"]), example=True)
|
||||
assert response.status == 204
|
||||
assert response.route == "/virtualbox/{uuid}/adapters/{adapter_id:\d+}/nio"
|
||||
assert response.route == "/virtualbox/vms/{vm_id}/adapters/{adapter_id:\d+}/nio"
|
||||
|
||||
|
||||
def test_vpcs_update(server, vm, free_console_port):
|
||||
response = server.put("/virtualbox/{}".format(vm["uuid"]), {"name": "test",
|
||||
response = server.put("/virtualbox/vms/{}".format(vm["vm_id"]), {"name": "test",
|
||||
"console": free_console_port})
|
||||
assert response.status == 200
|
||||
assert response.json["name"] == "test"
|
||||
|
@ -23,106 +23,106 @@ from unittest.mock import patch
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vm(server, project):
|
||||
response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid})
|
||||
response = server.post("/vpcs/vms", {"name": "PC TEST 1", "project_id": project.id})
|
||||
assert response.status == 201
|
||||
return response.json
|
||||
|
||||
|
||||
def test_vpcs_create(server, project):
|
||||
response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid}, example=True)
|
||||
response = server.post("/vpcs/vms", {"name": "PC TEST 1", "project_id": project.id}, example=True)
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs"
|
||||
assert response.route == "/vpcs/vms"
|
||||
assert response.json["name"] == "PC TEST 1"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
assert response.json["script_file"] is None
|
||||
|
||||
|
||||
def test_vpcs_get(server, project, vm):
|
||||
response = server.get("/vpcs/{}".format(vm["uuid"]), example=True)
|
||||
response = server.get("/vpcs/vms/{}".format(vm["vm_id"]), example=True)
|
||||
assert response.status == 200
|
||||
assert response.route == "/vpcs/{uuid}"
|
||||
assert response.route == "/vpcs/vms/{vm_id}"
|
||||
assert response.json["name"] == "PC TEST 1"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
|
||||
|
||||
def test_vpcs_create_startup_script(server, project):
|
||||
response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid, "startup_script": "ip 192.168.1.2\necho TEST"})
|
||||
response = server.post("/vpcs/vms", {"name": "PC TEST 1", "project_id": project.id, "startup_script": "ip 192.168.1.2\necho TEST"})
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs"
|
||||
assert response.route == "/vpcs/vms"
|
||||
assert response.json["name"] == "PC TEST 1"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
assert response.json["startup_script"] == "ip 192.168.1.2\necho TEST"
|
||||
|
||||
|
||||
def test_vpcs_create_port(server, project, free_console_port):
|
||||
response = server.post("/vpcs", {"name": "PC TEST 1", "project_id": project.uuid, "console": free_console_port})
|
||||
response = server.post("/vpcs/vms", {"name": "PC TEST 1", "project_id": project.id, "console": free_console_port})
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs"
|
||||
assert response.route == "/vpcs/vms"
|
||||
assert response.json["name"] == "PC TEST 1"
|
||||
assert response.json["project_id"] == project.uuid
|
||||
assert response.json["project_id"] == project.id
|
||||
assert response.json["console"] == free_console_port
|
||||
|
||||
|
||||
def test_vpcs_nio_create_udp(server, vm):
|
||||
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||
response = server.post("/vpcs/vms/{}/ports/0/nio".format(vm["vm_id"]), {"type": "nio_udp",
|
||||
"lport": 4242,
|
||||
"rport": 4343,
|
||||
"rhost": "127.0.0.1"},
|
||||
example=True)
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
assert response.route == "/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
|
||||
assert response.json["type"] == "nio_udp"
|
||||
|
||||
|
||||
def test_vpcs_nio_create_tap(server, vm):
|
||||
with patch("gns3server.modules.base_manager.BaseManager._has_privileged_access", return_value=True):
|
||||
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_tap",
|
||||
response = server.post("/vpcs/vms/{}/ports/0/nio".format(vm["vm_id"]), {"type": "nio_tap",
|
||||
"tap_device": "test"})
|
||||
assert response.status == 201
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
assert response.route == "/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
|
||||
assert response.json["type"] == "nio_tap"
|
||||
|
||||
|
||||
def test_vpcs_delete_nio(server, vm):
|
||||
server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
|
||||
server.post("/vpcs/vms/{}/ports/0/nio".format(vm["vm_id"]), {"type": "nio_udp",
|
||||
"lport": 4242,
|
||||
"rport": 4343,
|
||||
"rhost": "127.0.0.1"})
|
||||
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
|
||||
response = server.delete("/vpcs/vms/{}/ports/0/nio".format(vm["vm_id"]), example=True)
|
||||
assert response.status == 204
|
||||
assert response.route == "/vpcs/{uuid}/ports/{port_number:\d+}/nio"
|
||||
assert response.route == "/vpcs/vms/{vm_id}/ports/{port_number:\d+}/nio"
|
||||
|
||||
|
||||
def test_vpcs_start(server, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.start", return_value=True) as mock:
|
||||
response = server.post("/vpcs/{}/start".format(vm["uuid"]))
|
||||
response = server.post("/vpcs/vms/{}/start".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vpcs_stop(server, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.vpcs_vm.VPCSVM.stop", return_value=True) as mock:
|
||||
response = server.post("/vpcs/{}/stop".format(vm["uuid"]))
|
||||
response = server.post("/vpcs/vms/{}/stop".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
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"]))
|
||||
response = server.post("/vpcs/vms/{}/reload".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vpcs_delete(server, vm):
|
||||
with asyncio_patch("gns3server.modules.vpcs.VPCS.delete_vm", return_value=True) as mock:
|
||||
response = server.delete("/vpcs/{}".format(vm["uuid"]))
|
||||
response = server.delete("/vpcs/vms/{}".format(vm["vm_id"]))
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
|
||||
|
||||
def test_vpcs_update(server, vm, tmpdir, free_console_port):
|
||||
response = server.put("/vpcs/{}".format(vm["uuid"]), {"name": "test",
|
||||
response = server.put("/vpcs/vms/{}".format(vm["vm_id"]), {"name": "test",
|
||||
"console": free_console_port,
|
||||
"startup_script": "ip 192.168.1.1"})
|
||||
assert response.status == 200
|
||||
|
@ -84,7 +84,7 @@ def server(request, loop, port_manager):
|
||||
def project():
|
||||
"""A GNS3 lab"""
|
||||
|
||||
return ProjectManager.instance().create_project(uuid="a1e920ca-338a-4e9f-b363-aa607b09dd80")
|
||||
return ProjectManager.instance().create_project(project_id="a1e920ca-338a-4e9f-b363-aa607b09dd80")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
|
@ -42,18 +42,18 @@ def vm(project, manager):
|
||||
|
||||
def test_affect_uuid():
|
||||
p = Project()
|
||||
assert len(p.uuid) == 36
|
||||
assert len(p.id) == 36
|
||||
|
||||
p = Project(uuid='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
assert p.uuid == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
p = Project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
assert p.id == '00010203-0405-0607-0809-0a0b0c0d0e0f'
|
||||
|
||||
|
||||
def test_path(tmpdir):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.path == os.path.join(str(tmpdir), p.uuid)
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid))
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms'))
|
||||
assert p.path == os.path.join(str(tmpdir), p.id)
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.id, 'vms'))
|
||||
assert not os.path.exists(os.path.join(p.path, '.gns3_temporary'))
|
||||
|
||||
|
||||
@ -79,14 +79,14 @@ def test_changing_location_not_allowed(tmpdir):
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project()
|
||||
assert p.__json__() == {"location": p.location, "project_id": p.uuid, "temporary": False}
|
||||
assert p.__json__() == {"location": p.location, "project_id": p.id, "temporary": False}
|
||||
|
||||
|
||||
def test_vm_working_directory(tmpdir, vm):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert os.path.exists(p.vm_working_directory(vm))
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, vm.module_name, vm.uuid))
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.id, vm.module_name, vm.id))
|
||||
|
||||
|
||||
def test_mark_vm_for_destruction(vm):
|
||||
|
@ -22,7 +22,7 @@ from gns3server.modules.project_manager import ProjectManager
|
||||
|
||||
def test_create_project():
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.create_project(uuid='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
project = pm.create_project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
assert project == pm.get_project('00010203-0405-0607-0809-0a0b0c0d0e0f')
|
||||
|
||||
|
||||
|
@ -39,7 +39,7 @@ def vm(project, manager):
|
||||
def test_vm(project, manager):
|
||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert vm.vmname == "test"
|
||||
|
||||
|
||||
|
@ -30,17 +30,17 @@ def test_get_mac_id(loop, project, port_manager):
|
||||
VPCS._instance = None
|
||||
vpcs = VPCS.instance()
|
||||
vpcs.port_manager = port_manager
|
||||
vm1_uuid = str(uuid.uuid4())
|
||||
vm2_uuid = str(uuid.uuid4())
|
||||
vm3_uuid = str(uuid.uuid4())
|
||||
loop.run_until_complete(vpcs.create_vm("PC 1", project.uuid, vm1_uuid))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project.uuid, vm2_uuid))
|
||||
assert vpcs.get_mac_id(vm1_uuid) == 0
|
||||
assert vpcs.get_mac_id(vm1_uuid) == 0
|
||||
assert vpcs.get_mac_id(vm2_uuid) == 1
|
||||
loop.run_until_complete(vpcs.delete_vm(vm1_uuid))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 3", project.uuid, vm3_uuid))
|
||||
assert vpcs.get_mac_id(vm3_uuid) == 0
|
||||
vm1_id = str(uuid.uuid4())
|
||||
vm2_id = str(uuid.uuid4())
|
||||
vm3_id = str(uuid.uuid4())
|
||||
loop.run_until_complete(vpcs.create_vm("PC 1", project.id, vm1_id))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project.id, vm2_id))
|
||||
assert vpcs.get_mac_id(vm1_id) == 0
|
||||
assert vpcs.get_mac_id(vm1_id) == 0
|
||||
assert vpcs.get_mac_id(vm2_id) == 1
|
||||
loop.run_until_complete(vpcs.delete_vm(vm1_id))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 3", project.id, vm3_id))
|
||||
assert vpcs.get_mac_id(vm3_id) == 0
|
||||
|
||||
|
||||
def test_get_mac_id_multiple_project(loop, port_manager):
|
||||
@ -48,17 +48,17 @@ def test_get_mac_id_multiple_project(loop, port_manager):
|
||||
VPCS._instance = None
|
||||
vpcs = VPCS.instance()
|
||||
vpcs.port_manager = port_manager
|
||||
vm1_uuid = str(uuid.uuid4())
|
||||
vm2_uuid = str(uuid.uuid4())
|
||||
vm3_uuid = str(uuid.uuid4())
|
||||
vm1_id = str(uuid.uuid4())
|
||||
vm2_id = str(uuid.uuid4())
|
||||
vm3_id = str(uuid.uuid4())
|
||||
project1 = ProjectManager.instance().create_project()
|
||||
project2 = ProjectManager.instance().create_project()
|
||||
loop.run_until_complete(vpcs.create_vm("PC 1", project1.uuid, vm1_uuid))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project1.uuid, vm2_uuid))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project2.uuid, vm3_uuid))
|
||||
assert vpcs.get_mac_id(vm1_uuid) == 0
|
||||
assert vpcs.get_mac_id(vm2_uuid) == 1
|
||||
assert vpcs.get_mac_id(vm3_uuid) == 0
|
||||
loop.run_until_complete(vpcs.create_vm("PC 1", project1.id, vm1_id))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project1.id, vm2_id))
|
||||
loop.run_until_complete(vpcs.create_vm("PC 2", project2.id, vm3_id))
|
||||
assert vpcs.get_mac_id(vm1_id) == 0
|
||||
assert vpcs.get_mac_id(vm2_id) == 1
|
||||
assert vpcs.get_mac_id(vm3_id) == 0
|
||||
|
||||
|
||||
def test_get_mac_id_no_id_available(loop, project, port_manager):
|
||||
@ -68,6 +68,6 @@ def test_get_mac_id_no_id_available(loop, project, port_manager):
|
||||
vpcs.port_manager = port_manager
|
||||
with pytest.raises(VPCSError):
|
||||
for i in range(0, 256):
|
||||
vm_uuid = str(uuid.uuid4())
|
||||
loop.run_until_complete(vpcs.create_vm("PC {}".format(i), project.uuid, vm_uuid))
|
||||
assert vpcs.get_mac_id(vm_uuid) == i
|
||||
vm_id = str(uuid.uuid4())
|
||||
loop.run_until_complete(vpcs.create_vm("PC {}".format(i), project.id, vm_id))
|
||||
assert vpcs.get_mac_id(vm_id) == i
|
||||
|
@ -43,7 +43,7 @@ def vm(project, manager):
|
||||
def test_vm(project, manager):
|
||||
vm = VPCSVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
def test_vm_invalid_vpcs_version(loop, project, manager):
|
||||
@ -54,7 +54,7 @@ def test_vm_invalid_vpcs_version(loop, project, manager):
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
@patch("gns3server.config.Config.get_section_config", return_value={"vpcs_path": "/bin/test_fake"})
|
||||
@ -65,7 +65,7 @@ def test_vm_invalid_vpcs_path(project, manager, loop):
|
||||
vm.port_add_nio_binding(0, nio)
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
|
||||
|
||||
|
||||
def test_start(loop, vm):
|
||||
|
Loading…
Reference in New Issue
Block a user