Code cleanup

This commit is contained in:
Jerry Seutter
2014-10-28 12:11:22 -06:00
parent e39c1f9579
commit 15380ae80a
7 changed files with 15 additions and 69 deletions

View File

@@ -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__()

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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):

View File

@@ -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