From 15380ae80ae54ad3c8a4951b331d2859aec0860e Mon Sep 17 00:00:00 2001 From: Jerry Seutter Date: Tue, 28 Oct 2014 12:11:22 -0600 Subject: [PATCH] Code cleanup --- gns3/cloud/utils.py | 11 ++++---- gns3/graphics_view.py | 17 ------------ gns3/main_window.py | 38 --------------------------- gns3/modules/dynamips/__init__.py | 1 + gns3/modules/dynamips/nodes/router.py | 3 --- gns3/topology.py | 5 ---- scripts/ssh_to_server.py | 9 +++++++ 7 files changed, 15 insertions(+), 69 deletions(-) diff --git a/gns3/cloud/utils.py b/gns3/cloud/utils.py index 04731285..61f2b322 100644 --- a/gns3/cloud/utils.py +++ b/gns3/cloud/utils.py @@ -20,7 +20,7 @@ log = logging.getLogger(__name__) @contextmanager -def ssh_client(host, key_string, retry=False): +def ssh_client(host, key_string): """ Context manager wrapping a SSHClient instance: the client connects on enter and close the connection on exit @@ -117,11 +117,10 @@ class StartGNS3ServerThread(QThread): """ gns3server_started = pyqtSignal(str, str, str) - # Note: The htop package is for troubleshooting. It can safely be removed. +# This is for testing without pushing to github # commands = ''' # DEBIAN_FRONTEND=noninteractive dpkg --configure -a # DEBIAN_FRONTEND=noninteractive apt-get -y update -# DEBIAN_FRONTEND=noninteractive apt-get -y install htop # DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confnew" --force-yes -fuy dist-upgrade # DEBIAN_FRONTEND=noninteractive apt-get -y install git python3-setuptools python3-netifaces python3-pip python3-zmq dynamips # mkdir -p /opt/gns3 @@ -135,12 +134,11 @@ class StartGNS3ServerThread(QThread): commands = ''' DEBIAN_FRONTEND=noninteractive dpkg --configure -a DEBIAN_FRONTEND=noninteractive apt-get -y update -DEBIAN_FRONTEND=noninteractive apt-get -y install htop DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confnew" --force-yes -fuy dist-upgrade DEBIAN_FRONTEND=noninteractive apt-get -y install git python3-setuptools python3-netifaces python3-pip python3-zmq dynamips mkdir -p /opt/gns3 cd /opt/gns3; git clone https://github.com/planctechnologies/gns3-server.git -cd /opt/gns3/gns3-server; git checkout gns-110 +cd /opt/gns3/gns3-server; git checkout gns-110; git pull cd /opt/gns3/gns3-server; pip3 install -r dev-requirements.txt cd /opt/gns3/gns3-server; python3 ./setup.py install ln -sf /usr/bin/dynamips /usr/local/bin/dynamips @@ -196,6 +194,7 @@ killall python3 gns3server gns3dms continue ssh_connected = True + # This is for testing without pushing to github # os.system('rm -rf /tmp/gns3-server') # os.system('cp -a /Users/jseutter/projects/gns3-server /tmp/gns3-server') # os.system('cd /tmp; tar czf /tmp/gns3-server.tgz gns3-server') @@ -322,7 +321,7 @@ class UploadProjectThread(QThread): class UploadFileThread(QThread): """ - Upload an file to cloud files + Upload a file to cloud files """ def __init__(self, cloud_settings, router_settings): super().__init__() diff --git a/gns3/graphics_view.py b/gns3/graphics_view.py index 6f3271c1..e099eb34 100644 --- a/gns3/graphics_view.py +++ b/gns3/graphics_view.py @@ -1130,23 +1130,6 @@ class GraphicsView(QtGui.QGraphicsView): server = Servers.instance().getRemoteServer(host, port) if not server.connected() and ConnectToServer(self, server) is False: return - # if self._topology.resourcesType == "cloud": - # use_cloud = True - # else: - # use_cloud = False - # log.debug("use_cloud is set to {}".format(use_cloud)) - # - # server = node_module.allocateServer(node_class, use_cloud) - # if not server.connected(): - # # connect to server in a non-blocking way. - # self._thread = WaitForConnectionThread(server.host, server.port) - # progress_dialog = ProgressDialog(self._thread, - # "Server", - # "Connecting to server {} on port {}...".format(server.host, server.port), - # "Cancel", busy=True, parent=self) - # progress_dialog.show() - # if progress_dialog.exec_() is False: - # return node = node_module.createNode(node_class, server) node.error_signal.connect(self._main_window.uiConsoleTextEdit.writeError) diff --git a/gns3/main_window.py b/gns3/main_window.py index cf4256f7..dca056b8 100644 --- a/gns3/main_window.py +++ b/gns3/main_window.py @@ -388,24 +388,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self._loadCloudInstances() - # if new_project_settings["project_type"] == "cloud": - # provider = self.cloudProvider - # if provider is None: - # log.error("Unable to get a cloud provider") - # return - - # # create an instance for this project - # default_flavor = self.cloudSettings()['default_flavor'] - # default_image_id = self.cloudSettings()['default_image'] - # instance, keypair = self._create_instance(new_project_settings["project_name"], - # default_flavor, - # default_image_id) - # if instance: - # topology = Topology.instance() - # topology.addInstance(instance.name, instance.id, - # default_flavor, default_image_id, - # keypair.private_key, keypair.public_key) - self._project_settings.update(new_project_settings) self.saveProject(new_project_settings["project_path"]) @@ -1496,26 +1478,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self._saveCloudInstances() - # with open(project) as f: - # old_json_topology = json.load(f) - - # if old_json_topology["resources_type"] != 'cloud': - # # do nothing in case of local projects - # return - - # provider = self.cloudProvider - # if provider is None: - # log.error("Unable to get a cloud provider") - # return - - # for instance in old_json_topology["topology"]["instances"]: - # # shutdown the instance, we can pass to libcloud our namedtuple instead of a Node - # # object because only instance.id is actually accessed - # ti = TopologyInstance(**instance) - # self.cloudProvider.delete_instance(ti) - # # delete keypairs - # self.cloudProvider.delete_key_pair_by_name(instance["name"]) - def project_created(self, project): """ This slot is invoked when a project is created or opened diff --git a/gns3/modules/dynamips/__init__.py b/gns3/modules/dynamips/__init__.py index b74d4adf..004cf32d 100644 --- a/gns3/modules/dynamips/__init__.py +++ b/gns3/modules/dynamips/__init__.py @@ -516,6 +516,7 @@ class Dynamips(Module): settings[wic] = ios_router[wic] if node.server().isCloud(): + settings["cloud_path"] = "images/IOS" node.setup(ios_router["image"], ios_router["ram"], initial_settings=settings) else: node.setup(ios_router["path"], ios_router["ram"], initial_settings=settings) diff --git a/gns3/modules/dynamips/nodes/router.py b/gns3/modules/dynamips/nodes/router.py index 2aa43b31..7432aaaa 100644 --- a/gns3/modules/dynamips/nodes/router.py +++ b/gns3/modules/dynamips/nodes/router.py @@ -263,9 +263,6 @@ class Router(Node): if "chassis" in initial_settings: params["chassis"] = self._settings["chassis"] = initial_settings.pop("chassis") - #TODO: make this only send when dealing with cloud - params["cloud_path"] = "images/IOS" - # other initial settings will be applied when the router has been created if initial_settings: self._inital_settings = initial_settings diff --git a/gns3/topology.py b/gns3/topology.py index e25261a8..892ee621 100644 --- a/gns3/topology.py +++ b/gns3/topology.py @@ -41,11 +41,6 @@ import logging log = logging.getLogger(__name__) -# TopologyInstance = namedtuple("TopologyInstance", -# ["name", "id", "size_id", "image_id", "private_key", "public_key", -# "host", "port", "ssl_ca", "ssl_ca_file"], -# verbose=False) - class TopologyInstance: def __init__(self, name, id, size_id, image_id, private_key, public_key, host=None, port=None, ssl_ca=None, ssl_ca_file=None): diff --git a/scripts/ssh_to_server.py b/scripts/ssh_to_server.py index 36a8f0f6..a80a8aa8 100644 --- a/scripts/ssh_to_server.py +++ b/scripts/ssh_to_server.py @@ -1,3 +1,12 @@ +""" +This script can be used to ssh to a cloud server started by GNS3. It copies +the ssh keys for a server to a temp file on disk and starts ssh using the +keys. + +Right now it only connects to the first cloud server listed in the config +file. +""" + import os from PyQt4 import QtCore, QtGui