From 90f71e7581c90c5549268d5ac6e0301161214960 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 19 Feb 2015 19:14:30 -0700 Subject: [PATCH] Idle-PC proposals for Dynamips. --- gns3server/handlers/dynamips_vm_handler.py | 21 +++++++++++++++++++++ gns3server/modules/dynamips/__init__.py | 13 ++++++++----- gns3server/modules/dynamips/nodes/router.py | 6 +++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/gns3server/handlers/dynamips_vm_handler.py b/gns3server/handlers/dynamips_vm_handler.py index 4b284a0c..bd3c4d4c 100644 --- a/gns3server/handlers/dynamips_vm_handler.py +++ b/gns3server/handlers/dynamips_vm_handler.py @@ -349,3 +349,24 @@ class DynamipsVMHandler: response.set_status(200) response.json({"startup_config_content": startup_config_content, "private_config_content": private_config_content}) + + @Route.get( + r"/projects/{project_id}/dynamips/vms/{vm_id}/idlepc_proposals", + status_codes={ + 200: "Idle-PCs retrieved", + 400: "Invalid request", + 404: "Instance doesn't exist" + }, + description="Retrieve the idlepc proposals") + def get_idlepcs(request, response): + + dynamips_manager = Dynamips.instance() + vm = dynamips_manager.get_vm(request.match_info["vm_id"], + project_id=request.match_info["project_id"]) + + yield from vm.set_idlepc("0x0") + idlepcs = yield from vm.get_idle_pc_prop() + + #idlepcs = yield from vm.show_idle_pc_prop() + response.set_status(200) + response.json({"idlepcs": idlepcs}) diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index fc0eb7d8..c03ada14 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -409,6 +409,10 @@ class Dynamips(BaseManager): if not vm.mmap: raise DynamipsError("mmap support is required to enable ghost IOS support") + if vm.platform == "c7200" and vm.npe == "npe-g2": + log.warning("Ghost IOS is not support for c7200 with NPE-G2") + return + ghost_file = vm.formatted_ghost_file() ghost_file_path = os.path.join(vm.hypervisor.working_dir, ghost_file) if ghost_file_path not in self._ghost_files: @@ -418,9 +422,6 @@ class Dynamips(BaseManager): try: yield from ghost.create() yield from ghost.set_image(vm.image) - # for 7200s, the NPE must be set when using an NPE-G2. - if vm.platform == "c7200": - yield from ghost.set_npe(vm.npe) yield from ghost.set_ghost_status(1) yield from ghost.set_ghost_file(ghost_file) yield from ghost.set_ram(vm.ram) @@ -463,7 +464,8 @@ class Dynamips(BaseManager): adapter = ADAPTER_MATRIX[adapter_name]() if vm.slots[slot_id] and type(vm.slots[slot_id]) != type(adapter): yield from vm.slot_remove_binding(slot_id) - yield from vm.slot_add_binding(slot_id, adapter) + if type(vm.slots[slot_id]) != type(adapter): + yield from vm.slot_add_binding(slot_id, adapter) elif name.startswith("slot") and value is None: slot_id = int(name[-1]) if vm.slots[slot_id]: @@ -474,7 +476,8 @@ class Dynamips(BaseManager): wic = WIC_MATRIX[wic_name]() if vm.slots[0].wics[wic_slot_id] and type(vm.slots[0].wics[wic_slot_id]) != type(wic): yield from vm.uninstall_wic(wic_slot_id) - yield from vm.install_wic(wic_slot_id, wic) + if type(vm.slots[0].wics[wic_slot_id]) != type(wic): + yield from vm.install_wic(wic_slot_id, wic) elif name.startswith("wic") and value is None: wic_slot_id = int(name[-1]) if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]: diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index 36db166d..92f14c02 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -305,6 +305,9 @@ class Router(BaseVM): # router is already closed return + if self._dynamips_id in self._dynamips_ids[self._project.id]: + self._dynamips_ids[self._project.id].remove(self._dynamips_id) + self._hypervisor.devices.remove(self) if self._hypervisor and not self._hypervisor.devices: try: @@ -323,9 +326,6 @@ class Router(BaseVM): self._manager.port_manager.release_console_port(self._aux) self._aux = None - if self._dynamips_id in self._dynamips_ids[self._project.id]: - self._dynamips_ids[self._project.id].remove(self._dynamips_id) - self._closed = True @property