From f58c7960c901d16c2519a623d220241fea0934ef Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 4 Dec 2014 12:25:49 -0700 Subject: [PATCH] Use bundled Qemu on Windows and OSX by default and checks if remote server are registered. --- gns3server/modules/qemu/__init__.py | 2 ++ scripts/ws_client.py | 46 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 scripts/ws_client.py diff --git a/gns3server/modules/qemu/__init__.py b/gns3server/modules/qemu/__init__.py index c4ad2968..4816dfc8 100644 --- a/gns3server/modules/qemu/__init__.py +++ b/gns3server/modules/qemu/__init__.py @@ -639,6 +639,8 @@ class Qemu(IModule): elif sys.platform.startswith("darwin"): # add specific locations on Mac OS X regardless of what's in $PATH paths.extend(["/usr/local/bin", "/opt/local/bin"]) + if hasattr(sys, "frozen"): + paths.append(os.path.abspath(os.path.join(os.getcwd(), "../../../qemu/bin/"))) for path in paths: try: for f in os.listdir(path): diff --git a/scripts/ws_client.py b/scripts/ws_client.py new file mode 100644 index 00000000..675bc7c3 --- /dev/null +++ b/scripts/ws_client.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2014 GNS3 Technologies Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from ws4py.client.threadedclient import WebSocketClient + + +class WSClient(WebSocketClient): + + def opened(self): + + print("Connection successful with {}:{}".format(self.host, self.port)) + + self.send('{"jsonrpc": 2.0, "method": "dynamips.settings", "params": {"path": "/usr/local/bin/dynamips", "allocate_hypervisor_per_device": true, "working_dir": "/tmp/gns3-1b4grwm3-files", "udp_end_port_range": 20000, "sparse_memory_support": true, "allocate_hypervisor_per_ios_image": true, "aux_start_port_range": 2501, "use_local_server": true, "hypervisor_end_port_range": 7700, "aux_end_port_range": 3000, "mmap_support": true, "console_start_port_range": 2001, "console_end_port_range": 2500, "hypervisor_start_port_range": 7200, "ghost_ios_support": true, "memory_usage_limit_per_hypervisor": 1024, "jit_sharing_support": false, "udp_start_port_range": 10001}}') + self.send('{"jsonrpc": 2.0, "method": "dynamips.vm.create", "id": "e8caf5be-de3d-40dd-80b9-ab6df8029570", "params": {"image": "/home/grossmj/GNS3/images/IOS/c3725-advipservicesk9-mz.124-15.T14.image", "name": "R1", "platform": "c3725", "ram": 256}}') + + def closed(self, code, reason=None): + + print("Closed down. Code: {} Reason: {}".format(code, reason)) + + def received_message(self, m): + + print(m) + if len(m) == 175: + self.close(reason='Bye bye') + +if __name__ == '__main__': + try: + ws = WSClient('ws://localhost:8000/', protocols=['http-only', 'chat']) + ws.connect() + ws.run_forever() + except KeyboardInterrupt: + ws.close() \ No newline at end of file