From f5ed9fbcf189ac0d7989d23a90840fd58bbaefff Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 20 Jan 2015 13:24:00 +0100 Subject: [PATCH] PEP 8 clean thanks to auto pep8 --- cloud-image/create_image.py | 2 +- docs/conf.py | 4 +- gns3dms/cloud/base_cloud_ctrl.py | 1 - gns3dms/cloud/exceptions.py | 22 +++++++ gns3dms/main.py | 66 +++++++++---------- gns3dms/modules/__init__.py | 2 +- gns3dms/modules/daemon.py | 22 ++++--- gns3dms/modules/rackspace_cloud.py | 7 +- gns3server/config.py | 3 +- gns3server/handlers/auth_handler.py | 33 ++++++---- gns3server/handlers/file_upload_handler.py | 1 + gns3server/handlers/project_handler.py | 1 + gns3server/handlers/virtualbox_handler.py | 1 + gns3server/handlers/vpcs_handler.py | 1 + gns3server/main.py | 8 +-- gns3server/modules/adapters/adapter.py | 1 + .../modules/adapters/ethernet_adapter.py | 1 + gns3server/modules/base_manager.py | 1 + gns3server/modules/dynamips/__init__.py | 7 +- .../modules/dynamips/adapters/adapter.py | 1 + .../modules/dynamips/adapters/c1700_mb_1fe.py | 1 + .../dynamips/adapters/c1700_mb_wic1.py | 1 + .../modules/dynamips/adapters/c2600_mb_1e.py | 1 + .../modules/dynamips/adapters/c2600_mb_1fe.py | 1 + .../modules/dynamips/adapters/c2600_mb_2e.py | 1 + .../modules/dynamips/adapters/c2600_mb_2fe.py | 1 + .../modules/dynamips/adapters/c7200_io_2fe.py | 1 + .../modules/dynamips/adapters/c7200_io_fe.py | 1 + .../dynamips/adapters/c7200_io_ge_e.py | 1 + .../modules/dynamips/adapters/leopard_2fe.py | 1 + .../modules/dynamips/adapters/nm_16esw.py | 1 + gns3server/modules/dynamips/adapters/nm_1e.py | 1 + .../modules/dynamips/adapters/nm_1fe_tx.py | 1 + gns3server/modules/dynamips/adapters/nm_4e.py | 1 + gns3server/modules/dynamips/adapters/nm_4t.py | 1 + .../modules/dynamips/adapters/pa_2fe_tx.py | 1 + gns3server/modules/dynamips/adapters/pa_4e.py | 1 + gns3server/modules/dynamips/adapters/pa_4t.py | 1 + gns3server/modules/dynamips/adapters/pa_8e.py | 1 + gns3server/modules/dynamips/adapters/pa_8t.py | 1 + gns3server/modules/dynamips/adapters/pa_a1.py | 1 + .../modules/dynamips/adapters/pa_fe_tx.py | 1 + gns3server/modules/dynamips/adapters/pa_ge.py | 1 + .../modules/dynamips/adapters/pa_pos_oc3.py | 1 + .../modules/dynamips/adapters/wic_1enet.py | 1 + .../modules/dynamips/adapters/wic_1t.py | 1 + .../modules/dynamips/adapters/wic_2t.py | 1 + gns3server/modules/dynamips/backends/vm.py | 6 +- .../modules/dynamips/dynamips_hypervisor.py | 1 + gns3server/modules/dynamips/hypervisor.py | 1 + .../modules/dynamips/hypervisor_manager.py | 1 + gns3server/modules/dynamips/nios/nio.py | 1 + gns3server/modules/dynamips/nios/nio_fifo.py | 1 + .../dynamips/nios/nio_generic_ethernet.py | 1 + .../dynamips/nios/nio_linux_ethernet.py | 1 + gns3server/modules/dynamips/nios/nio_mcast.py | 3 +- gns3server/modules/dynamips/nios/nio_null.py | 1 + gns3server/modules/dynamips/nios/nio_tap.py | 1 + gns3server/modules/dynamips/nios/nio_udp.py | 1 + .../modules/dynamips/nios/nio_udp_auto.py | 1 + gns3server/modules/dynamips/nios/nio_unix.py | 1 + gns3server/modules/dynamips/nios/nio_vde.py | 1 + .../modules/dynamips/nodes/atm_bridge.py | 3 +- .../modules/dynamips/nodes/atm_switch.py | 1 + gns3server/modules/dynamips/nodes/bridge.py | 1 + gns3server/modules/dynamips/nodes/c1700.py | 1 + gns3server/modules/dynamips/nodes/c2600.py | 1 + gns3server/modules/dynamips/nodes/c2691.py | 1 + gns3server/modules/dynamips/nodes/c3600.py | 1 + gns3server/modules/dynamips/nodes/c3725.py | 1 + gns3server/modules/dynamips/nodes/c3745.py | 1 + gns3server/modules/dynamips/nodes/c7200.py | 7 +- .../modules/dynamips/nodes/ethernet_switch.py | 7 +- .../dynamips/nodes/frame_relay_switch.py | 1 + gns3server/modules/dynamips/nodes/hub.py | 1 + gns3server/modules/dynamips/nodes/router.py | 3 +- gns3server/modules/dynamips/schemas/ethsw.py | 30 ++++----- gns3server/modules/dynamips/schemas/vm.py | 2 +- gns3server/modules/iou/__init__.py | 3 +- gns3server/modules/iou/adapters/adapter.py | 1 + .../modules/iou/adapters/ethernet_adapter.py | 1 + .../modules/iou/adapters/serial_adapter.py | 1 + gns3server/modules/iou/iou_device.py | 1 + gns3server/modules/iou/ioucon.py | 33 +++++----- gns3server/modules/iou/nios/nio.py | 1 + .../modules/iou/nios/nio_generic_ethernet.py | 1 + gns3server/modules/iou/nios/nio_tap.py | 1 + gns3server/modules/iou/nios/nio_udp.py | 1 + gns3server/modules/nios/nio_tap.py | 1 + gns3server/modules/nios/nio_udp.py | 1 + gns3server/modules/port_manager.py | 1 + gns3server/modules/project.py | 1 + gns3server/modules/project_manager.py | 1 + gns3server/modules/qemu/__init__.py | 3 +- gns3server/modules/qemu/adapters/adapter.py | 1 + .../modules/qemu/adapters/ethernet_adapter.py | 1 + gns3server/modules/qemu/nios/nio.py | 1 + gns3server/modules/qemu/nios/nio_udp.py | 1 + gns3server/modules/qemu/qemu_vm.py | 45 +++++++------ .../modules/virtualbox/telnet_server.py | 54 +++++++-------- .../modules/virtualbox/virtualbox_vm.py | 8 +-- gns3server/modules/vpcs/vpcs_vm.py | 2 + gns3server/server.py | 10 +-- gns3server/start_server.py | 14 ++-- gns3server/version.py | 1 - gns3server/web/documentation.py | 2 + gns3server/web/response.py | 1 + gns3server/web/route.py | 1 + old_tests/dynamips/test_c1700.py | 2 +- old_tests/dynamips/test_c2600.py | 2 +- old_tests/dynamips/test_c2691.py | 2 +- old_tests/dynamips/test_c3600.py | 2 +- old_tests/dynamips/test_c3725.py | 2 +- old_tests/dynamips/test_c3745.py | 2 +- old_tests/dynamips/test_c7200.py | 4 +- old_tests/dynamips/test_hypervisor_manager.py | 2 +- old_tests/dynamips/test_nios.py | 2 +- old_tests/dynamips/test_router.py | 6 +- old_tests/dynamips/test_vmhandler.py | 26 ++++---- old_tests/test_jsonrpc.py | 1 + scripts/ws_client.py | 2 +- setup.py | 2 +- tests/api/base.py | 1 + tests/utils.py | 2 + 124 files changed, 340 insertions(+), 210 deletions(-) diff --git a/cloud-image/create_image.py b/cloud-image/create_image.py index b7b1fec1..b1021f34 100644 --- a/cloud-image/create_image.py +++ b/cloud-image/create_image.py @@ -103,7 +103,7 @@ def main(): instance.change_password(passwd) # wait for the password change to be processed. Continuing while # a password change is processing will cause image creation to fail. - sleep(POLL_SEC*6) + sleep(POLL_SEC * 6) env.host_string = str(instance.accessIPv4) env.user = "root" diff --git a/docs/conf.py b/docs/conf.py index 73bef3c9..7fe6d119 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -103,9 +103,9 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' -#html_theme = 'nature' +# html_theme = 'nature' -#If uncommented it's turn off the default read the doc style +# If uncommented it's turn off the default read the doc style html_style = "/default.css" # Theme options are theme-specific and customize the look and feel of a theme diff --git a/gns3dms/cloud/base_cloud_ctrl.py b/gns3dms/cloud/base_cloud_ctrl.py index 236cdccc..0ad74af1 100644 --- a/gns3dms/cloud/base_cloud_ctrl.py +++ b/gns3dms/cloud/base_cloud_ctrl.py @@ -175,7 +175,6 @@ class BaseCloudCtrl(object): except Exception as e: log.error("list_instances returned an error: {}".format(e)) - def create_key_pair(self, name): """ Create and return a new Key Pair. """ diff --git a/gns3dms/cloud/exceptions.py b/gns3dms/cloud/exceptions.py index beeb598d..65d65f9f 100644 --- a/gns3dms/cloud/exceptions.py +++ b/gns3dms/cloud/exceptions.py @@ -1,45 +1,67 @@ """ Exception classes for CloudCtrl classes. """ + class ApiError(Exception): + """ Raised when the server returns 500 Compute Error. """ pass + class BadRequest(Exception): + """ Raised when the server returns 400 Bad Request. """ pass + class ComputeFault(Exception): + """ Raised when the server returns 400|500 Compute Fault. """ pass + class Forbidden(Exception): + """ Raised when the server returns 403 Forbidden. """ pass + class ItemNotFound(Exception): + """ Raised when the server returns 404 Not Found. """ pass + class KeyPairExists(Exception): + """ Raised when the server returns 409 Conflict Key pair exists. """ pass + class MethodNotAllowed(Exception): + """ Raised when the server returns 405 Method Not Allowed. """ pass + class OverLimit(Exception): + """ Raised when the server returns 413 Over Limit. """ pass + class ServerCapacityUnavailable(Exception): + """ Raised when the server returns 503 Server Capacity Uavailable. """ pass + class ServiceUnavailable(Exception): + """ Raised when the server returns 503 Service Unavailable. """ pass + class Unauthorized(Exception): + """ Raised when the server returns 401 Unauthorized. """ pass diff --git a/gns3dms/main.py b/gns3dms/main.py index 6cdad64e..d7d0fc30 100644 --- a/gns3dms/main.py +++ b/gns3dms/main.py @@ -41,7 +41,7 @@ from os.path import expanduser SCRIPT_NAME = os.path.basename(__file__) -#Is the full path when used as an import +# Is the full path when used as an import SCRIPT_PATH = os.path.dirname(__file__) if not SCRIPT_PATH: @@ -98,6 +98,8 @@ Options: """ % (SCRIPT_NAME) # Parse cmd line options + + def parse_cmd_line(argv): """ Parse command line arguments @@ -107,22 +109,22 @@ def parse_cmd_line(argv): short_args = "dvhk" long_args = ("debug", - "verbose", - "help", - "cloud_user_name=", - "cloud_api_key=", - "instance_id=", - "region=", - "dead_time=", - "init-wait=", - "check-interval=", - "file=", - "background", - ) + "verbose", + "help", + "cloud_user_name=", + "cloud_api_key=", + "instance_id=", + "region=", + "dead_time=", + "init-wait=", + "check-interval=", + "file=", + "background", + ) try: opts, extra_opts = getopt.getopt(argv[1:], short_args, long_args) except getopt.GetoptError as e: - print("Unrecognized command line option or missing required argument: %s" %(e)) + print("Unrecognized command line option or missing required argument: %s" % (e)) print(usage) sys.exit(2) @@ -133,7 +135,7 @@ def parse_cmd_line(argv): cmd_line_option_list["cloud_api_key"] = None cmd_line_option_list["instance_id"] = None cmd_line_option_list["region"] = None - cmd_line_option_list["dead_time"] = 60 * 60 #minutes + cmd_line_option_list["dead_time"] = 60 * 60 # minutes cmd_line_option_list["check-interval"] = None cmd_line_option_list["init-wait"] = 5 * 60 cmd_line_option_list["file"] = None @@ -146,8 +148,7 @@ def parse_cmd_line(argv): elif sys.platform == "osx": cmd_line_option_list['syslog'] = "/var/run/syslog" else: - cmd_line_option_list['syslog'] = ('localhost',514) - + cmd_line_option_list['syslog'] = ('localhost', 514) get_gns3secrets(cmd_line_option_list) cmd_line_option_list["dead_time"] = int(cmd_line_option_list["dead_time"]) @@ -181,7 +182,7 @@ def parse_cmd_line(argv): elif (opt in ("--background")): cmd_line_option_list["daemon"] = True - if cmd_line_option_list["shutdown"] == False: + if cmd_line_option_list["shutdown"] is False: if cmd_line_option_list["check-interval"] is None: cmd_line_option_list["check-interval"] = cmd_line_option_list["dead_time"] + 120 @@ -211,9 +212,9 @@ def parse_cmd_line(argv): print(usage) sys.exit(2) - return cmd_line_option_list + def get_gns3secrets(cmd_line_option_list): """ Load cloud credentials from .gns3secrets @@ -248,10 +249,10 @@ def set_logging(cmd_options): log_level = logging.INFO log_level_console = logging.WARNING - if cmd_options['verbose'] == True: + if cmd_options['verbose']: log_level_console = logging.INFO - if cmd_options['debug'] == True: + if cmd_options['debug']: log_level_console = logging.DEBUG log_level = logging.DEBUG @@ -275,6 +276,7 @@ def set_logging(cmd_options): return log + def send_shutdown(pid_file): """ Sends the daemon process a kill signal @@ -291,8 +293,9 @@ def send_shutdown(pid_file): def _get_file_age(filename): return datetime.datetime.fromtimestamp( - os.path.getmtime(filename) - ) + os.path.getmtime(filename) + ) + def monitor_loop(options): """ @@ -307,7 +310,7 @@ def monitor_loop(options): terminate_attempts = 0 - while options['shutdown'] == False: + while options['shutdown'] is False: log.debug("In monitor_loop for : %s" % ( datetime.datetime.now() - options['starttime']) ) @@ -320,15 +323,15 @@ def monitor_loop(options): if delta.seconds > options["dead_time"]: log.warning("Dead time exceeded, terminating instance ...") - #Terminate involves many layers of HTTP / API calls, lots of - #different errors types could occur here. + # Terminate involves many layers of HTTP / API calls, lots of + # different errors types could occur here. try: rksp = Rackspace(options) rksp.terminate() except Exception as e: log.critical("Exception during terminate: %s" % (e)) - terminate_attempts+=1 + terminate_attempts += 1 log.warning("Termination sent, attempt: %s" % (terminate_attempts)) time.sleep(600) else: @@ -372,14 +375,13 @@ def main(): for key, value in iter(sorted(options.items())): log.debug("%s : %s" % (key, value)) - log.debug("Checking file ....") - if os.path.isfile(options["file"]) == False: + if os.path.isfile(options["file"]) is False: log.critical("File does not exist!!!") sys.exit(1) test_acess = _get_file_age(options["file"]) - if type(test_acess) is not datetime.datetime: + if not isinstance(test_acess, datetime.datetime): log.critical("Can't get file modification time!!!") sys.exit(1) @@ -390,13 +392,11 @@ def main(): class MyDaemon(daemon.daemon): + def run(self): monitor_loop(self.options) - if __name__ == "__main__": result = main() sys.exit(result) - - diff --git a/gns3dms/modules/__init__.py b/gns3dms/modules/__init__.py index 885d6fa0..0950e877 100644 --- a/gns3dms/modules/__init__.py +++ b/gns3dms/modules/__init__.py @@ -21,4 +21,4 @@ # three numbers are the components of the version number. The fourth # is zero for an official release, positive for a development branch, # or negative for a release candidate or beta (after the base version -# number has been incremented) \ No newline at end of file +# number has been incremented) diff --git a/gns3dms/modules/daemon.py b/gns3dms/modules/daemon.py index c7245335..cfc5539f 100644 --- a/gns3dms/modules/daemon.py +++ b/gns3dms/modules/daemon.py @@ -1,8 +1,14 @@ """Generic linux daemon base class for python 3.x.""" -import sys, os, time, atexit, signal +import sys +import os +import time +import atexit +import signal + class daemon: + """A generic daemon class. Usage: subclass the daemon class and override the run() method.""" @@ -54,7 +60,7 @@ class daemon: atexit.register(self.delpid) pid = str(os.getpid()) - with open(self.pidfile,'w+') as f: + with open(self.pidfile, 'w+') as f: f.write(pid + '\n') def delpid(self): @@ -74,7 +80,7 @@ class daemon: # Check for a pidfile to see if the daemon already runs try: - with open(self.pidfile,'r') as pf: + with open(self.pidfile, 'r') as pf: pid = int(pf.read().strip()) except IOError: @@ -101,20 +107,20 @@ class daemon: # Get the pid from the pidfile try: - with open(self.pidfile,'r') as pf: + with open(self.pidfile, 'r') as pf: pid = int(pf.read().strip()) except IOError: pid = None if not pid: message = "pidfile {0} does not exist. " + \ - "Daemon not running?\n" + "Daemon not running?\n" sys.stderr.write(message.format(self.pidfile)) - return # not an error in a restart + return # not an error in a restart # Try killing the daemon process try: - while 1: + while True: os.kill(pid, signal.SIGTERM) time.sleep(0.1) except OSError as err: @@ -123,7 +129,7 @@ class daemon: if os.path.exists(self.pidfile): os.remove(self.pidfile) else: - print (str(err.args)) + print(str(err.args)) sys.exit(1) def restart(self): diff --git a/gns3dms/modules/rackspace_cloud.py b/gns3dms/modules/rackspace_cloud.py index 487e6f9f..06f81046 100644 --- a/gns3dms/modules/rackspace_cloud.py +++ b/gns3dms/modules/rackspace_cloud.py @@ -23,7 +23,8 @@ # or negative for a release candidate or beta (after the base version # number has been incremented) -import os, sys +import os +import sys import json import logging import socket @@ -34,7 +35,9 @@ from gns3dms.cloud.rackspace_ctrl import RackspaceCtrl LOG_NAME = "gns3dms.rksp" log = logging.getLogger("%s" % (LOG_NAME)) + class Rackspace(object): + def __init__(self, options): self.username = options["cloud_user_name"] self.apikey = options["cloud_api_key"] @@ -54,7 +57,7 @@ class Rackspace(object): for region in self.rksp.list_regions(): log.debug("Rackspace regions: %s" % (region)) - + log.debug("Checking region: %s" % (self.region)) self.rksp.set_region(self.region) for server in self.rksp.list_instances(): diff --git a/gns3server/config.py b/gns3server/config.py index d851c49c..57d61180 100644 --- a/gns3server/config.py +++ b/gns3server/config.py @@ -30,6 +30,7 @@ CLOUD_SERVER = 'CLOUD_SERVER' class Config(object): + """ Configuration file management using configparser. """ @@ -117,7 +118,7 @@ class Config(object): :returns: configparser section """ - if not section in self._config: + if section is not in self._config: return self._config["DEFAULT"] return self._config[section] diff --git a/gns3server/handlers/auth_handler.py b/gns3server/handlers/auth_handler.py index 6db9f4ec..b479e533 100644 --- a/gns3server/handlers/auth_handler.py +++ b/gns3server/handlers/auth_handler.py @@ -27,32 +27,37 @@ import tornado.websocket import logging log = logging.getLogger(__name__) + class GNS3BaseHandler(tornado.web.RequestHandler): + def get_current_user(self): if 'required_user' not in self.settings: return "FakeUser" user = self.get_secure_cookie("user") if not user: - return None + return None if self.settings['required_user'] == user.decode("utf-8"): - return user + return user + class GNS3WebSocketBaseHandler(tornado.websocket.WebSocketHandler): + def get_current_user(self): if 'required_user' not in self.settings: return "FakeUser" user = self.get_secure_cookie("user") if not user: - return None + return None if self.settings['required_user'] == user.decode("utf-8"): - return user + return user class LoginHandler(tornado.web.RequestHandler): + def get(self): self.write('
' 'Name: ' @@ -61,10 +66,10 @@ class LoginHandler(tornado.web.RequestHandler): '
') try: - redirect_to = self.get_argument("next") - self.set_secure_cookie("login_success_redirect_to", redirect_to) + redirect_to = self.get_argument("next") + self.set_secure_cookie("login_success_redirect_to", redirect_to) except tornado.web.MissingArgumentError: - pass + pass def post(self): @@ -72,21 +77,21 @@ class LoginHandler(tornado.web.RequestHandler): password = self.get_argument("password") if self.settings['required_user'] == user and self.settings['required_pass'] == password: - self.set_secure_cookie("user", user) - auth_status = "successful" + self.set_secure_cookie("user", user) + auth_status = "successful" else: - self.set_secure_cookie("user", "None") - auth_status = "failure" + self.set_secure_cookie("user", "None") + auth_status = "failure" log.info("Authentication attempt {}: {}, {}".format(auth_status, user, password)) try: - redirect_to = self.get_secure_cookie("login_success_redirect_to") + redirect_to = self.get_secure_cookie("login_success_redirect_to") except tornado.web.MissingArgumentError: - redirect_to = "/" + redirect_to = "/" if redirect_to is None: self.write({'result': auth_status}) else: log.info('Redirecting to {}'.format(redirect_to)) - self.redirect(redirect_to) \ No newline at end of file + self.redirect(redirect_to) diff --git a/gns3server/handlers/file_upload_handler.py b/gns3server/handlers/file_upload_handler.py index d4e33200..7c8fd862 100644 --- a/gns3server/handlers/file_upload_handler.py +++ b/gns3server/handlers/file_upload_handler.py @@ -34,6 +34,7 @@ log = logging.getLogger(__name__) class FileUploadHandler(GNS3BaseHandler): + """ File upload handler. diff --git a/gns3server/handlers/project_handler.py b/gns3server/handlers/project_handler.py index a3a7bf35..79d1b68e 100644 --- a/gns3server/handlers/project_handler.py +++ b/gns3server/handlers/project_handler.py @@ -22,6 +22,7 @@ from aiohttp.web import HTTPConflict class ProjectHandler: + @classmethod @Route.post( r"/project", diff --git a/gns3server/handlers/virtualbox_handler.py b/gns3server/handlers/virtualbox_handler.py index 2b8714dd..01c20b3e 100644 --- a/gns3server/handlers/virtualbox_handler.py +++ b/gns3server/handlers/virtualbox_handler.py @@ -22,6 +22,7 @@ from ..modules.virtualbox import VirtualBox class VirtualBoxHandler: + """ API entry points for VirtualBox. """ diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index e18d40fa..3eb9b46d 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -23,6 +23,7 @@ from ..modules.vpcs import VPCS class VPCSHandler: + """ API entry points for VPCS. """ diff --git a/gns3server/main.py b/gns3server/main.py index 88411826..65993058 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -27,6 +27,7 @@ from gns3server.version import __version__ import logging log = logging.getLogger(__name__) + def locale_check(): """ Checks if this application runs with a correct locale (i.e. supports UTF-8 encoding) and attempt to fix @@ -71,11 +72,10 @@ def main(): Entry point for GNS3 server """ - #TODO: migrate command line options to argparse (don't forget the quiet mode). + # TODO: migrate command line options to argparse (don't forget the quiet mode). current_year = datetime.date.today().year - # TODO: Renable the test when we will have command line # user_log = logging.getLogger('user_facing') # if not options.quiet: @@ -95,7 +95,7 @@ def main(): user_log.info("GNS3 server version {}".format(__version__)) user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) - #TODO: end todo + # TODO: end todo # we only support Python 3 version >= 3.3 if sys.version_info < (3, 3): @@ -115,7 +115,7 @@ def main(): return # TODO: Renable console_bind_to_any when we will have command line parsing - #server = Server(options.host, options.port, options.console_bind_to_any) + # server = Server(options.host, options.port, options.console_bind_to_any) server = Server("127.0.0.1", 8000, False) server.run() diff --git a/gns3server/modules/adapters/adapter.py b/gns3server/modules/adapters/adapter.py index cf439427..ade660f9 100644 --- a/gns3server/modules/adapters/adapter.py +++ b/gns3server/modules/adapters/adapter.py @@ -17,6 +17,7 @@ class Adapter(object): + """ Base class for adapters. diff --git a/gns3server/modules/adapters/ethernet_adapter.py b/gns3server/modules/adapters/ethernet_adapter.py index bbca7f40..9d3ee003 100644 --- a/gns3server/modules/adapters/ethernet_adapter.py +++ b/gns3server/modules/adapters/ethernet_adapter.py @@ -19,6 +19,7 @@ from .adapter import Adapter class EthernetAdapter(Adapter): + """ VPCS Ethernet adapter. """ diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 3f211c98..c90a2bab 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -24,6 +24,7 @@ from .project_manager import ProjectManager class BaseManager: + """ Base class for all Manager. Responsible of management of a VM pool diff --git a/gns3server/modules/dynamips/__init__.py b/gns3server/modules/dynamips/__init__.py index b04aeaa5..26347094 100644 --- a/gns3server/modules/dynamips/__init__.py +++ b/gns3server/modules/dynamips/__init__.py @@ -95,6 +95,7 @@ log = logging.getLogger(__name__) class Dynamips(IModule): + """ Dynamips module. @@ -140,7 +141,7 @@ class Dynamips(IModule): self._console_host = dynamips_config.get("console_host", kwargs["console_host"]) if not sys.platform.startswith("win32"): - #FIXME: pickle issues Windows + # FIXME: pickle issues Windows self._callback = self.add_periodic_callback(self._check_hypervisors, 5000) self._callback.start() @@ -323,7 +324,7 @@ class Dynamips(IModule): log.debug("received request {}".format(request)) - #TODO: JSON schema validation + # TODO: JSON schema validation if not self._hypervisor_manager: if "path" in request: @@ -407,7 +408,7 @@ class Dynamips(IModule): rhost = request["nio"]["rhost"] rport = request["nio"]["rport"] try: - #TODO: handle IPv6 + # TODO: handle IPv6 with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: sock.connect((rhost, rport)) except OSError as e: diff --git a/gns3server/modules/dynamips/adapters/adapter.py b/gns3server/modules/dynamips/adapters/adapter.py index d963933e..40d82c7e 100644 --- a/gns3server/modules/dynamips/adapters/adapter.py +++ b/gns3server/modules/dynamips/adapters/adapter.py @@ -17,6 +17,7 @@ class Adapter(object): + """ Base class for adapters. diff --git a/gns3server/modules/dynamips/adapters/c1700_mb_1fe.py b/gns3server/modules/dynamips/adapters/c1700_mb_1fe.py index 3c67f3df..c94f551d 100644 --- a/gns3server/modules/dynamips/adapters/c1700_mb_1fe.py +++ b/gns3server/modules/dynamips/adapters/c1700_mb_1fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C1700_MB_1FE(Adapter): + """ Integrated 1 port FastEthernet adapter for c1700 platform. """ diff --git a/gns3server/modules/dynamips/adapters/c1700_mb_wic1.py b/gns3server/modules/dynamips/adapters/c1700_mb_wic1.py index eca72358..9c6d2190 100644 --- a/gns3server/modules/dynamips/adapters/c1700_mb_wic1.py +++ b/gns3server/modules/dynamips/adapters/c1700_mb_wic1.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C1700_MB_WIC1(Adapter): + """ Fake module to provide a placeholder for slot 1 interfaces when WICs are inserted into WIC slot 1. diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_1e.py b/gns3server/modules/dynamips/adapters/c2600_mb_1e.py index 26fe5497..bebe7fa9 100644 --- a/gns3server/modules/dynamips/adapters/c2600_mb_1e.py +++ b/gns3server/modules/dynamips/adapters/c2600_mb_1e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C2600_MB_1E(Adapter): + """ Integrated 1 port Ethernet adapter for the c2600 platform. """ diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_1fe.py b/gns3server/modules/dynamips/adapters/c2600_mb_1fe.py index 768d9c95..1ad294f2 100644 --- a/gns3server/modules/dynamips/adapters/c2600_mb_1fe.py +++ b/gns3server/modules/dynamips/adapters/c2600_mb_1fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C2600_MB_1FE(Adapter): + """ Integrated 1 port FastEthernet adapter for the c2600 platform. """ diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_2e.py b/gns3server/modules/dynamips/adapters/c2600_mb_2e.py index c2ca7442..1e42d5dd 100644 --- a/gns3server/modules/dynamips/adapters/c2600_mb_2e.py +++ b/gns3server/modules/dynamips/adapters/c2600_mb_2e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C2600_MB_2E(Adapter): + """ Integrated 2 port Ethernet adapter for the c2600 platform. """ diff --git a/gns3server/modules/dynamips/adapters/c2600_mb_2fe.py b/gns3server/modules/dynamips/adapters/c2600_mb_2fe.py index a7e6df14..dcd96581 100644 --- a/gns3server/modules/dynamips/adapters/c2600_mb_2fe.py +++ b/gns3server/modules/dynamips/adapters/c2600_mb_2fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C2600_MB_2FE(Adapter): + """ Integrated 2 port FastEthernet adapter for the c2600 platform. """ diff --git a/gns3server/modules/dynamips/adapters/c7200_io_2fe.py b/gns3server/modules/dynamips/adapters/c7200_io_2fe.py index 0b8ae8a4..8b545e99 100644 --- a/gns3server/modules/dynamips/adapters/c7200_io_2fe.py +++ b/gns3server/modules/dynamips/adapters/c7200_io_2fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C7200_IO_2FE(Adapter): + """ C7200-IO-2FE FastEthernet Input/Ouput controller. """ diff --git a/gns3server/modules/dynamips/adapters/c7200_io_fe.py b/gns3server/modules/dynamips/adapters/c7200_io_fe.py index 56e86cf1..784b154d 100644 --- a/gns3server/modules/dynamips/adapters/c7200_io_fe.py +++ b/gns3server/modules/dynamips/adapters/c7200_io_fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C7200_IO_FE(Adapter): + """ C7200-IO-FE FastEthernet Input/Ouput controller. """ diff --git a/gns3server/modules/dynamips/adapters/c7200_io_ge_e.py b/gns3server/modules/dynamips/adapters/c7200_io_ge_e.py index 12ebaed6..f233dffd 100644 --- a/gns3server/modules/dynamips/adapters/c7200_io_ge_e.py +++ b/gns3server/modules/dynamips/adapters/c7200_io_ge_e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class C7200_IO_GE_E(Adapter): + """ C7200-IO-GE-E GigabitEthernet Input/Ouput controller. """ diff --git a/gns3server/modules/dynamips/adapters/leopard_2fe.py b/gns3server/modules/dynamips/adapters/leopard_2fe.py index 0afa95c0..db6ad9c2 100644 --- a/gns3server/modules/dynamips/adapters/leopard_2fe.py +++ b/gns3server/modules/dynamips/adapters/leopard_2fe.py @@ -19,6 +19,7 @@ from .adapter import Adapter class Leopard_2FE(Adapter): + """ Integrated 2 port FastEthernet adapter for c3660 router. """ diff --git a/gns3server/modules/dynamips/adapters/nm_16esw.py b/gns3server/modules/dynamips/adapters/nm_16esw.py index fc3755cd..31e74565 100644 --- a/gns3server/modules/dynamips/adapters/nm_16esw.py +++ b/gns3server/modules/dynamips/adapters/nm_16esw.py @@ -19,6 +19,7 @@ from .adapter import Adapter class NM_16ESW(Adapter): + """ NM-16ESW FastEthernet network module. """ diff --git a/gns3server/modules/dynamips/adapters/nm_1e.py b/gns3server/modules/dynamips/adapters/nm_1e.py index ac200247..59ac5569 100644 --- a/gns3server/modules/dynamips/adapters/nm_1e.py +++ b/gns3server/modules/dynamips/adapters/nm_1e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class NM_1E(Adapter): + """ NM-1E Ethernet network module. """ diff --git a/gns3server/modules/dynamips/adapters/nm_1fe_tx.py b/gns3server/modules/dynamips/adapters/nm_1fe_tx.py index 9723f703..26568306 100644 --- a/gns3server/modules/dynamips/adapters/nm_1fe_tx.py +++ b/gns3server/modules/dynamips/adapters/nm_1fe_tx.py @@ -19,6 +19,7 @@ from .adapter import Adapter class NM_1FE_TX(Adapter): + """ NM-1FE-TX FastEthernet network module. """ diff --git a/gns3server/modules/dynamips/adapters/nm_4e.py b/gns3server/modules/dynamips/adapters/nm_4e.py index ae6a51ed..086b04ee 100644 --- a/gns3server/modules/dynamips/adapters/nm_4e.py +++ b/gns3server/modules/dynamips/adapters/nm_4e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class NM_4E(Adapter): + """ NM-4E Ethernet network module. """ diff --git a/gns3server/modules/dynamips/adapters/nm_4t.py b/gns3server/modules/dynamips/adapters/nm_4t.py index df6db299..77c3ecc8 100644 --- a/gns3server/modules/dynamips/adapters/nm_4t.py +++ b/gns3server/modules/dynamips/adapters/nm_4t.py @@ -19,6 +19,7 @@ from .adapter import Adapter class NM_4T(Adapter): + """ NM-4T Serial network module. """ diff --git a/gns3server/modules/dynamips/adapters/pa_2fe_tx.py b/gns3server/modules/dynamips/adapters/pa_2fe_tx.py index 8589ff2e..09b677f3 100644 --- a/gns3server/modules/dynamips/adapters/pa_2fe_tx.py +++ b/gns3server/modules/dynamips/adapters/pa_2fe_tx.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_2FE_TX(Adapter): + """ PA-2FE-TX FastEthernet port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_4e.py b/gns3server/modules/dynamips/adapters/pa_4e.py index 32564992..d5981860 100644 --- a/gns3server/modules/dynamips/adapters/pa_4e.py +++ b/gns3server/modules/dynamips/adapters/pa_4e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_4E(Adapter): + """ PA-4E Ethernet port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_4t.py b/gns3server/modules/dynamips/adapters/pa_4t.py index 6a098a24..5a1393bc 100644 --- a/gns3server/modules/dynamips/adapters/pa_4t.py +++ b/gns3server/modules/dynamips/adapters/pa_4t.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_4T(Adapter): + """ PA-4T+ Serial port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_8e.py b/gns3server/modules/dynamips/adapters/pa_8e.py index a6b5075f..96684055 100644 --- a/gns3server/modules/dynamips/adapters/pa_8e.py +++ b/gns3server/modules/dynamips/adapters/pa_8e.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_8E(Adapter): + """ PA-8E Ethernet port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_8t.py b/gns3server/modules/dynamips/adapters/pa_8t.py index 600a5c29..723e026f 100644 --- a/gns3server/modules/dynamips/adapters/pa_8t.py +++ b/gns3server/modules/dynamips/adapters/pa_8t.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_8T(Adapter): + """ PA-8T Serial port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_a1.py b/gns3server/modules/dynamips/adapters/pa_a1.py index 21d51f15..469d9ce4 100644 --- a/gns3server/modules/dynamips/adapters/pa_a1.py +++ b/gns3server/modules/dynamips/adapters/pa_a1.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_A1(Adapter): + """ PA-A1 ATM port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_fe_tx.py b/gns3server/modules/dynamips/adapters/pa_fe_tx.py index 70ce8489..6434d2b4 100644 --- a/gns3server/modules/dynamips/adapters/pa_fe_tx.py +++ b/gns3server/modules/dynamips/adapters/pa_fe_tx.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_FE_TX(Adapter): + """ PA-FE-TX FastEthernet port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_ge.py b/gns3server/modules/dynamips/adapters/pa_ge.py index f0287408..e466d905 100644 --- a/gns3server/modules/dynamips/adapters/pa_ge.py +++ b/gns3server/modules/dynamips/adapters/pa_ge.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_GE(Adapter): + """ PA-GE GigabitEthernet port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/pa_pos_oc3.py b/gns3server/modules/dynamips/adapters/pa_pos_oc3.py index b120de97..de0bc5d1 100644 --- a/gns3server/modules/dynamips/adapters/pa_pos_oc3.py +++ b/gns3server/modules/dynamips/adapters/pa_pos_oc3.py @@ -19,6 +19,7 @@ from .adapter import Adapter class PA_POS_OC3(Adapter): + """ PA-POS-OC3 port adapter. """ diff --git a/gns3server/modules/dynamips/adapters/wic_1enet.py b/gns3server/modules/dynamips/adapters/wic_1enet.py index dac79b6b..2d5e62b7 100644 --- a/gns3server/modules/dynamips/adapters/wic_1enet.py +++ b/gns3server/modules/dynamips/adapters/wic_1enet.py @@ -17,6 +17,7 @@ class WIC_1ENET(object): + """ WIC-1ENET Ethernet """ diff --git a/gns3server/modules/dynamips/adapters/wic_1t.py b/gns3server/modules/dynamips/adapters/wic_1t.py index 0f7cb3ad..2067246d 100644 --- a/gns3server/modules/dynamips/adapters/wic_1t.py +++ b/gns3server/modules/dynamips/adapters/wic_1t.py @@ -17,6 +17,7 @@ class WIC_1T(object): + """ WIC-1T Serial """ diff --git a/gns3server/modules/dynamips/adapters/wic_2t.py b/gns3server/modules/dynamips/adapters/wic_2t.py index 2bf2d565..b5af954e 100644 --- a/gns3server/modules/dynamips/adapters/wic_2t.py +++ b/gns3server/modules/dynamips/adapters/wic_2t.py @@ -17,6 +17,7 @@ class WIC_2T(object): + """ WIC-2T Serial """ diff --git a/gns3server/modules/dynamips/backends/vm.py b/gns3server/modules/dynamips/backends/vm.py index 8348a231..e40e79d6 100644 --- a/gns3server/modules/dynamips/backends/vm.py +++ b/gns3server/modules/dynamips/backends/vm.py @@ -466,7 +466,7 @@ class VM(object): adapter_name = value adapter = ADAPTER_MATRIX[adapter_name]() try: - if router.slots[slot_id] and type(router.slots[slot_id]) != type(adapter): + if router.slots[slot_id] and not isinstance(router.slots[slot_id], type(adapter)): router.slot_remove_binding(slot_id) router.slot_add_binding(slot_id, adapter) response[name] = value @@ -487,14 +487,14 @@ class VM(object): wic_name = value wic = WIC_MATRIX[wic_name]() try: - if router.slots[0].wics[wic_slot_id] and type(router.slots[0].wics[wic_slot_id]) != type(wic): + if router.slots[0].wics[wic_slot_id] and not isinstance(router.slots[0].wics[wic_slot_id], type(wic)): router.uninstall_wic(wic_slot_id) router.install_wic(wic_slot_id, wic) response[name] = value except DynamipsError as e: self.send_custom_error(str(e)) return - elif name.startswith("wic") and value == None: + elif name.startswith("wic") and value is None: wic_slot_id = int(name[-1]) if router.slots[0].wics and router.slots[0].wics[wic_slot_id]: try: diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 7c93f775..1ac01ee1 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -30,6 +30,7 @@ log = logging.getLogger(__name__) class DynamipsHypervisor(object): + """ Creates a new connection to a Dynamips server (also called hypervisor) diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index 88c577d7..ffce2935 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -32,6 +32,7 @@ log = logging.getLogger(__name__) class Hypervisor(DynamipsHypervisor): + """ Hypervisor. diff --git a/gns3server/modules/dynamips/hypervisor_manager.py b/gns3server/modules/dynamips/hypervisor_manager.py index 3106d98c..a9be6ed0 100644 --- a/gns3server/modules/dynamips/hypervisor_manager.py +++ b/gns3server/modules/dynamips/hypervisor_manager.py @@ -34,6 +34,7 @@ log = logging.getLogger(__name__) class HypervisorManager(object): + """ Manages Dynamips hypervisors. diff --git a/gns3server/modules/dynamips/nios/nio.py b/gns3server/modules/dynamips/nios/nio.py index 1fd61bf9..3b66d54f 100644 --- a/gns3server/modules/dynamips/nios/nio.py +++ b/gns3server/modules/dynamips/nios/nio.py @@ -27,6 +27,7 @@ log = logging.getLogger(__name__) class NIO(object): + """ Base NIO class diff --git a/gns3server/modules/dynamips/nios/nio_fifo.py b/gns3server/modules/dynamips/nios/nio_fifo.py index a67f863d..c85b679d 100644 --- a/gns3server/modules/dynamips/nios/nio_fifo.py +++ b/gns3server/modules/dynamips/nios/nio_fifo.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_FIFO(NIO): + """ Dynamips FIFO NIO. diff --git a/gns3server/modules/dynamips/nios/nio_generic_ethernet.py b/gns3server/modules/dynamips/nios/nio_generic_ethernet.py index 58e6ec7f..2a8b1443 100644 --- a/gns3server/modules/dynamips/nios/nio_generic_ethernet.py +++ b/gns3server/modules/dynamips/nios/nio_generic_ethernet.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_GenericEthernet(NIO): + """ Dynamips generic Ethernet NIO. diff --git a/gns3server/modules/dynamips/nios/nio_linux_ethernet.py b/gns3server/modules/dynamips/nios/nio_linux_ethernet.py index a199c264..25988aa8 100644 --- a/gns3server/modules/dynamips/nios/nio_linux_ethernet.py +++ b/gns3server/modules/dynamips/nios/nio_linux_ethernet.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_LinuxEthernet(NIO): + """ Dynamips Linux Ethernet NIO. diff --git a/gns3server/modules/dynamips/nios/nio_mcast.py b/gns3server/modules/dynamips/nios/nio_mcast.py index 4d939d5a..bcd42670 100644 --- a/gns3server/modules/dynamips/nios/nio_mcast.py +++ b/gns3server/modules/dynamips/nios/nio_mcast.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_Mcast(NIO): + """ Dynamips Linux Ethernet NIO. @@ -103,5 +104,5 @@ class NIO_Mcast(NIO): """ self._hypervisor.send("nio set_mcast_ttl {name} {ttl}".format(name=self._name, - ttl=ttl)) + ttl=ttl)) self._ttl = ttl diff --git a/gns3server/modules/dynamips/nios/nio_null.py b/gns3server/modules/dynamips/nios/nio_null.py index b9350c07..1cde2a52 100644 --- a/gns3server/modules/dynamips/nios/nio_null.py +++ b/gns3server/modules/dynamips/nios/nio_null.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_Null(NIO): + """ Dynamips NULL NIO. diff --git a/gns3server/modules/dynamips/nios/nio_tap.py b/gns3server/modules/dynamips/nios/nio_tap.py index 9ee16abb..d24e9109 100644 --- a/gns3server/modules/dynamips/nios/nio_tap.py +++ b/gns3server/modules/dynamips/nios/nio_tap.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_TAP(NIO): + """ Dynamips TAP NIO. diff --git a/gns3server/modules/dynamips/nios/nio_udp.py b/gns3server/modules/dynamips/nios/nio_udp.py index bcfd9e4d..d9e2d294 100644 --- a/gns3server/modules/dynamips/nios/nio_udp.py +++ b/gns3server/modules/dynamips/nios/nio_udp.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_UDP(NIO): + """ Dynamips UDP NIO. diff --git a/gns3server/modules/dynamips/nios/nio_udp_auto.py b/gns3server/modules/dynamips/nios/nio_udp_auto.py index ccefce2b..03d290d6 100644 --- a/gns3server/modules/dynamips/nios/nio_udp_auto.py +++ b/gns3server/modules/dynamips/nios/nio_udp_auto.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_UDP_auto(NIO): + """ Dynamips auto UDP NIO. diff --git a/gns3server/modules/dynamips/nios/nio_unix.py b/gns3server/modules/dynamips/nios/nio_unix.py index f699eead..af100d2e 100644 --- a/gns3server/modules/dynamips/nios/nio_unix.py +++ b/gns3server/modules/dynamips/nios/nio_unix.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_UNIX(NIO): + """ Dynamips UNIX NIO. diff --git a/gns3server/modules/dynamips/nios/nio_vde.py b/gns3server/modules/dynamips/nios/nio_vde.py index 79af96d7..7157834f 100644 --- a/gns3server/modules/dynamips/nios/nio_vde.py +++ b/gns3server/modules/dynamips/nios/nio_vde.py @@ -26,6 +26,7 @@ log = logging.getLogger(__name__) class NIO_VDE(NIO): + """ Dynamips VDE NIO. diff --git a/gns3server/modules/dynamips/nodes/atm_bridge.py b/gns3server/modules/dynamips/nodes/atm_bridge.py index 10abe1b2..bfed0b78 100644 --- a/gns3server/modules/dynamips/nodes/atm_bridge.py +++ b/gns3server/modules/dynamips/nodes/atm_bridge.py @@ -24,6 +24,7 @@ from ..dynamips_error import DynamipsError class ATMBridge(object): + """ Dynamips bridge switch. @@ -33,7 +34,7 @@ class ATMBridge(object): def __init__(self, hypervisor, name): - #FIXME: instance tracking + # FIXME: instance tracking self._hypervisor = hypervisor self._name = '"' + name + '"' # put name into quotes to protect spaces self._hypervisor.send("atm_bridge create {}".format(self._name)) diff --git a/gns3server/modules/dynamips/nodes/atm_switch.py b/gns3server/modules/dynamips/nodes/atm_switch.py index 0c382c44..aa0dba3e 100644 --- a/gns3server/modules/dynamips/nodes/atm_switch.py +++ b/gns3server/modules/dynamips/nodes/atm_switch.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class ATMSwitch(object): + """ Dynamips ATM switch. diff --git a/gns3server/modules/dynamips/nodes/bridge.py b/gns3server/modules/dynamips/nodes/bridge.py index a87ba029..fcac17b9 100644 --- a/gns3server/modules/dynamips/nodes/bridge.py +++ b/gns3server/modules/dynamips/nodes/bridge.py @@ -22,6 +22,7 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L538 class Bridge(object): + """ Dynamips bridge. diff --git a/gns3server/modules/dynamips/nodes/c1700.py b/gns3server/modules/dynamips/nodes/c1700.py index 906abe3e..249ab508 100644 --- a/gns3server/modules/dynamips/nodes/c1700.py +++ b/gns3server/modules/dynamips/nodes/c1700.py @@ -29,6 +29,7 @@ log = logging.getLogger(__name__) class C1700(Router): + """ Dynamips c1700 router. diff --git a/gns3server/modules/dynamips/nodes/c2600.py b/gns3server/modules/dynamips/nodes/c2600.py index b5e46e89..083bbce6 100644 --- a/gns3server/modules/dynamips/nodes/c2600.py +++ b/gns3server/modules/dynamips/nodes/c2600.py @@ -31,6 +31,7 @@ log = logging.getLogger(__name__) class C2600(Router): + """ Dynamips c2600 router. diff --git a/gns3server/modules/dynamips/nodes/c2691.py b/gns3server/modules/dynamips/nodes/c2691.py index 0dc0ef28..fca62624 100644 --- a/gns3server/modules/dynamips/nodes/c2691.py +++ b/gns3server/modules/dynamips/nodes/c2691.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class C2691(Router): + """ Dynamips c2691 router. diff --git a/gns3server/modules/dynamips/nodes/c3600.py b/gns3server/modules/dynamips/nodes/c3600.py index 32e2bbe7..8b9e8966 100644 --- a/gns3server/modules/dynamips/nodes/c3600.py +++ b/gns3server/modules/dynamips/nodes/c3600.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class C3600(Router): + """ Dynamips c3600 router. diff --git a/gns3server/modules/dynamips/nodes/c3725.py b/gns3server/modules/dynamips/nodes/c3725.py index 9317a393..76ba4d9f 100644 --- a/gns3server/modules/dynamips/nodes/c3725.py +++ b/gns3server/modules/dynamips/nodes/c3725.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class C3725(Router): + """ Dynamips c3725 router. diff --git a/gns3server/modules/dynamips/nodes/c3745.py b/gns3server/modules/dynamips/nodes/c3745.py index 8002909a..0903b789 100644 --- a/gns3server/modules/dynamips/nodes/c3745.py +++ b/gns3server/modules/dynamips/nodes/c3745.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class C3745(Router): + """ Dynamips c3745 router. diff --git a/gns3server/modules/dynamips/nodes/c7200.py b/gns3server/modules/dynamips/nodes/c7200.py index 21ab4aa6..8ba10f8e 100644 --- a/gns3server/modules/dynamips/nodes/c7200.py +++ b/gns3server/modules/dynamips/nodes/c7200.py @@ -30,6 +30,7 @@ log = logging.getLogger(__name__) class C7200(Router): + """ Dynamips c7200 router (model is 7206). @@ -227,9 +228,9 @@ class C7200(Router): powered_on=power_supply)) log.info("router {name} [id={id}]: power supply {power_supply_id} state updated to {powered_on}".format(name=self._name, - id=self._id, - power_supply_id=power_supply_id, - powered_on=power_supply)) + id=self._id, + power_supply_id=power_supply_id, + powered_on=power_supply)) power_supply_id += 1 self._power_supplies = power_supplies diff --git a/gns3server/modules/dynamips/nodes/ethernet_switch.py b/gns3server/modules/dynamips/nodes/ethernet_switch.py index 45cc25c0..a88346dc 100644 --- a/gns3server/modules/dynamips/nodes/ethernet_switch.py +++ b/gns3server/modules/dynamips/nodes/ethernet_switch.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class EthernetSwitch(object): + """ Dynamips Ethernet switch. @@ -268,9 +269,9 @@ class EthernetSwitch(object): outer_vlan=outer_vlan)) log.info("Ethernet switch {name} [id={id}]: port {port} set as a QinQ port with outer VLAN {vlan_id}".format(name=self._name, - id=self._id, - port=port, - vlan_id=outer_vlan)) + id=self._id, + port=port, + vlan_id=outer_vlan)) self._mapping[port] = ("qinq", outer_vlan) def get_mac_addr_table(self): diff --git a/gns3server/modules/dynamips/nodes/frame_relay_switch.py b/gns3server/modules/dynamips/nodes/frame_relay_switch.py index 0b44fbea..8a309301 100644 --- a/gns3server/modules/dynamips/nodes/frame_relay_switch.py +++ b/gns3server/modules/dynamips/nodes/frame_relay_switch.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class FrameRelaySwitch(object): + """ Dynamips Frame Relay switch. diff --git a/gns3server/modules/dynamips/nodes/hub.py b/gns3server/modules/dynamips/nodes/hub.py index 6f7f0e59..18cedbe1 100644 --- a/gns3server/modules/dynamips/nodes/hub.py +++ b/gns3server/modules/dynamips/nodes/hub.py @@ -28,6 +28,7 @@ log = logging.getLogger(__name__) class Hub(Bridge): + """ Dynamips hub (based on Bridge) diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index d0d1aef3..18d8db8d 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -33,6 +33,7 @@ log = logging.getLogger(__name__) class Router(object): + """ Dynamips router implementation. @@ -575,7 +576,7 @@ class Router(object): try: reply = self._hypervisor.send("vm extract_config {}".format(self._name))[0].rsplit(' ', 2)[-2:] except IOError: - #for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file. + # for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file. return None, None startup_config = reply[0][1:-1] # get statup-config and remove single quotes private_config = reply[1][1:-1] # get private-config and remove single quotes diff --git a/gns3server/modules/dynamips/schemas/ethsw.py b/gns3server/modules/dynamips/schemas/ethsw.py index aeac7023..33559f28 100644 --- a/gns3server/modules/dynamips/schemas/ethsw.py +++ b/gns3server/modules/dynamips/schemas/ethsw.py @@ -44,7 +44,7 @@ ETHSW_DELETE_SCHEMA = { "required": ["id"] } -#TODO: ports {'1': {'vlan': 1, 'type': 'qinq'} +# TODO: ports {'1': {'vlan': 1, 'type': 'qinq'} ETHSW_UPDATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Request validation to update an Ethernet switch instance", @@ -59,20 +59,20 @@ ETHSW_UPDATE_SCHEMA = { "type": "string", "minLength": 1, }, -# "ports": { -# "type": "object", -# "properties": { -# "type": { -# "description": "Port type", -# "enum": ["access", "dot1q", "qinq"], -# }, -# "vlan": { -# "description": "VLAN number", -# "type": "integer", -# "minimum": 1 -# }, -# }, -# }, + # "ports": { + # "type": "object", + # "properties": { + # "type": { + # "description": "Port type", + # "enum": ["access", "dot1q", "qinq"], + # }, + # "vlan": { + # "description": "VLAN number", + # "type": "integer", + # "minimum": 1 + # }, + # }, + # }, }, #"additionalProperties": False, "required": ["id"] diff --git a/gns3server/modules/dynamips/schemas/vm.py b/gns3server/modules/dynamips/schemas/vm.py index ae261ffa..adb380e4 100644 --- a/gns3server/modules/dynamips/schemas/vm.py +++ b/gns3server/modules/dynamips/schemas/vm.py @@ -147,7 +147,7 @@ VM_RELOAD_SCHEMA = { "required": ["id"] } -#TODO: improve platform specific properties (dependencies?) +# TODO: improve platform specific properties (dependencies?) VM_UPDATE_SCHEMA = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Request validation to update a VM instance", diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 4a6ceec6..04c7e4c0 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -56,6 +56,7 @@ log = logging.getLogger(__name__) class IOU(IModule): + """ IOU module. @@ -635,7 +636,7 @@ class IOU(IModule): rhost = request["nio"]["rhost"] rport = request["nio"]["rport"] try: - #TODO: handle IPv6 + # TODO: handle IPv6 with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: sock.connect((rhost, rport)) except OSError as e: diff --git a/gns3server/modules/iou/adapters/adapter.py b/gns3server/modules/iou/adapters/adapter.py index 4d2f4053..06645e56 100644 --- a/gns3server/modules/iou/adapters/adapter.py +++ b/gns3server/modules/iou/adapters/adapter.py @@ -17,6 +17,7 @@ class Adapter(object): + """ Base class for adapters. diff --git a/gns3server/modules/iou/adapters/ethernet_adapter.py b/gns3server/modules/iou/adapters/ethernet_adapter.py index 312ef848..bf96362f 100644 --- a/gns3server/modules/iou/adapters/ethernet_adapter.py +++ b/gns3server/modules/iou/adapters/ethernet_adapter.py @@ -19,6 +19,7 @@ from .adapter import Adapter class EthernetAdapter(Adapter): + """ IOU Ethernet adapter. """ diff --git a/gns3server/modules/iou/adapters/serial_adapter.py b/gns3server/modules/iou/adapters/serial_adapter.py index 9f2851a5..ca7d3200 100644 --- a/gns3server/modules/iou/adapters/serial_adapter.py +++ b/gns3server/modules/iou/adapters/serial_adapter.py @@ -19,6 +19,7 @@ from .adapter import Adapter class SerialAdapter(Adapter): + """ IOU Serial adapter. """ diff --git a/gns3server/modules/iou/iou_device.py b/gns3server/modules/iou/iou_device.py index dec395bb..ff8ff2c3 100644 --- a/gns3server/modules/iou/iou_device.py +++ b/gns3server/modules/iou/iou_device.py @@ -43,6 +43,7 @@ log = logging.getLogger(__name__) class IOUDevice(object): + """ IOU device implementation. diff --git a/gns3server/modules/iou/ioucon.py b/gns3server/modules/iou/ioucon.py index cb280fa1..9a0e980e 100644 --- a/gns3server/modules/iou/ioucon.py +++ b/gns3server/modules/iou/ioucon.py @@ -56,22 +56,22 @@ EXIT_ABORT = 2 # Mostly from: # https://code.google.com/p/miniboa/source/browse/trunk/miniboa/telnet.py #--[ Telnet Commands ]--------------------------------------------------------- -SE = 240 # End of sub-negotiation parameters -NOP = 241 # No operation -DATMK = 242 # Data stream portion of a sync. -BREAK = 243 # NVT Character BRK -IP = 244 # Interrupt Process -AO = 245 # Abort Output -AYT = 246 # Are you there -EC = 247 # Erase Character -EL = 248 # Erase Line -GA = 249 # The Go Ahead Signal -SB = 250 # Sub-option to follow -WILL = 251 # Will; request or confirm option begin -WONT = 252 # Wont; deny option request -DO = 253 # Do = Request or confirm remote option -DONT = 254 # Don't = Demand or confirm option halt -IAC = 255 # Interpret as Command +SE = 240 # End of sub-negotiation parameters +NOP = 241 # No operation +DATMK = 242 # Data stream portion of a sync. +BREAK = 243 # NVT Character BRK +IP = 244 # Interrupt Process +AO = 245 # Abort Output +AYT = 246 # Are you there +EC = 247 # Erase Character +EL = 248 # Erase Line +GA = 249 # The Go Ahead Signal +SB = 250 # Sub-option to follow +WILL = 251 # Will; request or confirm option begin +WONT = 252 # Wont; deny option request +DO = 253 # Do = Request or confirm remote option +DONT = 254 # Don't = Demand or confirm option halt +IAC = 255 # Interpret as Command SEND = 1 # Sub-process negotiation SEND command IS = 0 # Sub-process negotiation IS command #--[ Telnet Options ]---------------------------------------------------------- @@ -154,6 +154,7 @@ class FileLock: class Console: + def fileno(self): raise NotImplementedError("Only routers have fileno()") diff --git a/gns3server/modules/iou/nios/nio.py b/gns3server/modules/iou/nios/nio.py index 059d56a3..0c8e610e 100644 --- a/gns3server/modules/iou/nios/nio.py +++ b/gns3server/modules/iou/nios/nio.py @@ -21,6 +21,7 @@ Base interface for NIOs. class NIO(object): + """ Network Input/Output. """ diff --git a/gns3server/modules/iou/nios/nio_generic_ethernet.py b/gns3server/modules/iou/nios/nio_generic_ethernet.py index 068e9fc3..709e6474 100644 --- a/gns3server/modules/iou/nios/nio_generic_ethernet.py +++ b/gns3server/modules/iou/nios/nio_generic_ethernet.py @@ -23,6 +23,7 @@ from .nio import NIO class NIO_GenericEthernet(NIO): + """ Generic Ethernet NIO. diff --git a/gns3server/modules/iou/nios/nio_tap.py b/gns3server/modules/iou/nios/nio_tap.py index 95ec631d..f6b1663f 100644 --- a/gns3server/modules/iou/nios/nio_tap.py +++ b/gns3server/modules/iou/nios/nio_tap.py @@ -23,6 +23,7 @@ from .nio import NIO class NIO_TAP(NIO): + """ TAP NIO. diff --git a/gns3server/modules/iou/nios/nio_udp.py b/gns3server/modules/iou/nios/nio_udp.py index 2c850351..3b25f0c4 100644 --- a/gns3server/modules/iou/nios/nio_udp.py +++ b/gns3server/modules/iou/nios/nio_udp.py @@ -23,6 +23,7 @@ from .nio import NIO class NIO_UDP(NIO): + """ UDP NIO. diff --git a/gns3server/modules/nios/nio_tap.py b/gns3server/modules/nios/nio_tap.py index 85d89990..e533c32a 100644 --- a/gns3server/modules/nios/nio_tap.py +++ b/gns3server/modules/nios/nio_tap.py @@ -21,6 +21,7 @@ Interface for TAP NIOs (UNIX based OSes only). class NIO_TAP(object): + """ TAP NIO. diff --git a/gns3server/modules/nios/nio_udp.py b/gns3server/modules/nios/nio_udp.py index f499ca7e..bc6252bb 100644 --- a/gns3server/modules/nios/nio_udp.py +++ b/gns3server/modules/nios/nio_udp.py @@ -21,6 +21,7 @@ Interface for UDP NIOs. class NIO_UDP(object): + """ UDP NIO. diff --git a/gns3server/modules/port_manager.py b/gns3server/modules/port_manager.py index b0188802..4ea2cac5 100644 --- a/gns3server/modules/port_manager.py +++ b/gns3server/modules/port_manager.py @@ -21,6 +21,7 @@ import asyncio class PortManager: + """ :param host: IP address to bind for console connections """ diff --git a/gns3server/modules/project.py b/gns3server/modules/project.py index fa427027..d03f090f 100644 --- a/gns3server/modules/project.py +++ b/gns3server/modules/project.py @@ -21,6 +21,7 @@ from uuid import uuid4 class Project: + """ A project contains a list of VM. In theory VM are isolated project/project. diff --git a/gns3server/modules/project_manager.py b/gns3server/modules/project_manager.py index f2a75e4a..cad199c4 100644 --- a/gns3server/modules/project_manager.py +++ b/gns3server/modules/project_manager.py @@ -20,6 +20,7 @@ from .project import Project class ProjectManager: + """ This singleton keeps track of available projects. """ diff --git a/gns3server/modules/qemu/__init__.py b/gns3server/modules/qemu/__init__.py index beaac4ef..01b3c72e 100644 --- a/gns3server/modules/qemu/__init__.py +++ b/gns3server/modules/qemu/__init__.py @@ -49,6 +49,7 @@ log = logging.getLogger(__name__) class Qemu(IModule): + """ QEMU module. @@ -551,7 +552,7 @@ class Qemu(IModule): rhost = request["nio"]["rhost"] rport = request["nio"]["rport"] try: - #TODO: handle IPv6 + # TODO: handle IPv6 with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: sock.connect((rhost, rport)) except OSError as e: diff --git a/gns3server/modules/qemu/adapters/adapter.py b/gns3server/modules/qemu/adapters/adapter.py index cf439427..ade660f9 100644 --- a/gns3server/modules/qemu/adapters/adapter.py +++ b/gns3server/modules/qemu/adapters/adapter.py @@ -17,6 +17,7 @@ class Adapter(object): + """ Base class for adapters. diff --git a/gns3server/modules/qemu/adapters/ethernet_adapter.py b/gns3server/modules/qemu/adapters/ethernet_adapter.py index 27426ec2..2064bb68 100644 --- a/gns3server/modules/qemu/adapters/ethernet_adapter.py +++ b/gns3server/modules/qemu/adapters/ethernet_adapter.py @@ -19,6 +19,7 @@ from .adapter import Adapter class EthernetAdapter(Adapter): + """ QEMU Ethernet adapter. """ diff --git a/gns3server/modules/qemu/nios/nio.py b/gns3server/modules/qemu/nios/nio.py index eee5f1d5..3c8a6b9e 100644 --- a/gns3server/modules/qemu/nios/nio.py +++ b/gns3server/modules/qemu/nios/nio.py @@ -21,6 +21,7 @@ Base interface for NIOs. class NIO(object): + """ Network Input/Output. """ diff --git a/gns3server/modules/qemu/nios/nio_udp.py b/gns3server/modules/qemu/nios/nio_udp.py index 2c850351..3b25f0c4 100644 --- a/gns3server/modules/qemu/nios/nio_udp.py +++ b/gns3server/modules/qemu/nios/nio_udp.py @@ -23,6 +23,7 @@ from .nio import NIO class NIO_UDP(NIO): + """ UDP NIO. diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 5ae6fad7..25ce78bb 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -43,6 +43,7 @@ log = logging.getLogger(__name__) class QemuVM(object): + """ QEMU VM implementation. @@ -462,7 +463,6 @@ class QemuVM(object): disk_image=hdb_disk_image)) self._hdb_disk_image = hdb_disk_image - @property def adapters(self): """ @@ -586,7 +586,6 @@ class QemuVM(object): priority=process_priority)) self._process_priority = process_priority - @property def ram(self): """ @@ -999,18 +998,18 @@ class QemuVM(object): if self._legacy_networking: self._control_vm("host_net_remove {} gns3-{}".format(adapter_id, adapter_id)) self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_id, - adapter_id, - nio.lport, - nio.rport, - nio.rhost)) + adapter_id, + nio.lport, + nio.rport, + nio.rhost)) else: self._control_vm("host_net_remove {} gns3-{}".format(adapter_id, adapter_id)) self._control_vm("host_net_add socket vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_id, - adapter_id, - nio.rhost, - nio.rport, - self._host, - nio.lport)) + adapter_id, + nio.rhost, + nio.rport, + self._host, + nio.lport)) adapter.add_nio(0, nio) log.info("QEMU VM {name} [id={id}]: {nio} added to adapter {adapter_id}".format(name=self._name, @@ -1154,8 +1153,8 @@ class QemuVM(object): if not os.path.exists(hdb_disk): try: retcode = subprocess.call([qemu_img_path, "create", "-o", - "backing_file={}".format(self._hdb_disk_image), - "-f", "qcow2", hdb_disk]) + "backing_file={}".format(self._hdb_disk_image), + "-f", "qcow2", hdb_disk]) log.info("{} returned with {}".format(qemu_img_path, retcode)) except (OSError, subprocess.SubprocessError) as e: raise QemuError("Could not create disk image {}".format(e)) @@ -1190,24 +1189,24 @@ class QemuVM(object): network_options = [] adapter_id = 0 for adapter in self._ethernet_adapters: - #TODO: let users specify a base mac address + # TODO: let users specify a base mac address mac = "00:00:ab:%02x:%02x:%02d" % (random.randint(0x00, 0xff), random.randint(0x00, 0xff), adapter_id) network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_id, mac, self._adapter_type)]) nio = adapter.get_nio(0) if nio and isinstance(nio, NIO_UDP): if self._legacy_networking: network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_id, - adapter_id, - nio.lport, - nio.rport, - nio.rhost)]) + adapter_id, + nio.lport, + nio.rport, + nio.rhost)]) else: network_options.extend(["-net", "socket,vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_id, - adapter_id, - nio.rhost, - nio.rport, - self._host, - nio.lport)]) + adapter_id, + nio.rhost, + nio.rport, + self._host, + nio.lport)]) else: network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_id, adapter_id)]) adapter_id += 1 diff --git a/gns3server/modules/virtualbox/telnet_server.py b/gns3server/modules/virtualbox/telnet_server.py index 0ccde367..b5e214a5 100644 --- a/gns3server/modules/virtualbox/telnet_server.py +++ b/gns3server/modules/virtualbox/telnet_server.py @@ -31,6 +31,7 @@ if sys.platform.startswith("win"): class TelnetServer(threading.Thread): + """ Mini Telnet Server. @@ -226,37 +227,38 @@ class TelnetServer(threading.Thread): # Mostly from https://code.google.com/p/miniboa/source/browse/trunk/miniboa/telnet.py # Telnet Commands -SE = 240 # End of sub-negotiation parameters -NOP = 241 # No operation -DATMK = 242 # Data stream portion of a sync. -BREAK = 243 # NVT Character BRK -IP = 244 # Interrupt Process -AO = 245 # Abort Output -AYT = 246 # Are you there -EC = 247 # Erase Character -EL = 248 # Erase Line -GA = 249 # The Go Ahead Signal -SB = 250 # Sub-option to follow -WILL = 251 # Will; request or confirm option begin -WONT = 252 # Wont; deny option request -DO = 253 # Do = Request or confirm remote option -DONT = 254 # Don't = Demand or confirm option halt -IAC = 255 # Interpret as Command -SEND = 1 # Sub-process negotiation SEND command -IS = 0 # Sub-process negotiation IS command +SE = 240 # End of sub-negotiation parameters +NOP = 241 # No operation +DATMK = 242 # Data stream portion of a sync. +BREAK = 243 # NVT Character BRK +IP = 244 # Interrupt Process +AO = 245 # Abort Output +AYT = 246 # Are you there +EC = 247 # Erase Character +EL = 248 # Erase Line +GA = 249 # The Go Ahead Signal +SB = 250 # Sub-option to follow +WILL = 251 # Will; request or confirm option begin +WONT = 252 # Wont; deny option request +DO = 253 # Do = Request or confirm remote option +DONT = 254 # Don't = Demand or confirm option halt +IAC = 255 # Interpret as Command +SEND = 1 # Sub-process negotiation SEND command +IS = 0 # Sub-process negotiation IS command # Telnet Options -BINARY = 0 # Transmit Binary -ECHO = 1 # Echo characters back to sender -RECON = 2 # Reconnection -SGA = 3 # Suppress Go-Ahead -TMARK = 6 # Timing Mark -TTYPE = 24 # Terminal Type -NAWS = 31 # Negotiate About Window Size -LINEMO = 34 # Line Mode +BINARY = 0 # Transmit Binary +ECHO = 1 # Echo characters back to sender +RECON = 2 # Reconnection +SGA = 3 # Suppress Go-Ahead +TMARK = 6 # Timing Mark +TTYPE = 24 # Terminal Type +NAWS = 31 # Negotiate About Window Size +LINEMO = 34 # Line Mode class TelnetClient(object): + """ Represents a Telnet client connection. diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index 12dfb934..8fd95bf1 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -45,6 +45,7 @@ log = logging.getLogger(__name__) class VirtualBoxVM(BaseVM): + """ VirtualBox VM implementation. """ @@ -58,7 +59,7 @@ class VirtualBoxVM(BaseVM): self._system_properties = {} - #FIXME: harcoded values + # FIXME: harcoded values if sys.platform.startswith("win"): self._vboxmanage_path = r"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" else: @@ -367,7 +368,6 @@ class VirtualBoxVM(BaseVM): except OSError as e: raise VirtualBoxError("Could not write HDD info file: {}".format(e)) - log.info("VirtualBox VM {name} [id={id}] has been deleted".format(name=self._name, id=self._id)) @@ -386,9 +386,9 @@ class VirtualBoxVM(BaseVM): if self._linked_clone: self._execute("unregistervm", [self._vmname, "--delete"]) - #try: + # try: # shutil.rmtree(self._working_dir) - #except OSError as e: + # except OSError as e: # log.error("could not delete VirtualBox VM {name} [id={id}]: {error}".format(name=self._name, # id=self._id, # error=e)) diff --git a/gns3server/modules/vpcs/vpcs_vm.py b/gns3server/modules/vpcs/vpcs_vm.py index a1ffdd57..5184d5e1 100644 --- a/gns3server/modules/vpcs/vpcs_vm.py +++ b/gns3server/modules/vpcs/vpcs_vm.py @@ -43,6 +43,7 @@ log = logging.getLogger(__name__) class VPCSVM(BaseVM): + """ VPCS vm implementation. @@ -53,6 +54,7 @@ class VPCSVM(BaseVM): :param working_dir: path to a working directory :param console: TCP console port """ + def __init__(self, name, uuid, project, manager, working_dir=None, console=None): super().__init__(name, uuid, project, manager) diff --git a/gns3server/server.py b/gns3server/server.py index d476a003..e428b508 100644 --- a/gns3server/server.py +++ b/gns3server/server.py @@ -33,7 +33,7 @@ from .config import Config from .modules import MODULES from .modules.port_manager import PortManager -#TODO: get rid of * have something generic to automatically import handlers so the routes can be found +# TODO: get rid of * have something generic to automatically import handlers so the routes can be found from gns3server.handlers import * from gns3server.handlers.virtualbox_handler import VirtualBoxHandler @@ -51,7 +51,7 @@ class Server: self._start_time = time.time() self._port_manager = PortManager(host, console_bind_to_any) - #TODO: server config file support, to be reviewed + # TODO: server config file support, to be reviewed # # get the projects and temp directories from the configuration file (passed to the modules) # config = Config.instance() # server_config = config.get_default_section() @@ -78,7 +78,7 @@ class Server: Cleanup the modules (shutdown running emulators etc.) """ - #TODO: clean everything from here + # TODO: clean everything from here self._loop.stop() def _signal_handling(self): @@ -133,7 +133,7 @@ class Server: Starts the server. """ - #TODO: SSL support for Rackspace cloud integration (here or with nginx for instance). + # TODO: SSL support for Rackspace cloud integration (here or with nginx for instance). self._loop = asyncio.get_event_loop() app = aiohttp.web.Application() for method, route, handler in Route.get_routes(): @@ -148,7 +148,7 @@ class Server: self._loop.run_until_complete(self._run_application(app)) self._signal_handling() - #FIXME: remove it in production or in tests + # FIXME: remove it in production or in tests self._loop.call_later(1, self._reload_hook) try: self._loop.run_forever() diff --git a/gns3server/start_server.py b/gns3server/start_server.py index 952703c0..c603a2b9 100644 --- a/gns3server/start_server.py +++ b/gns3server/start_server.py @@ -80,15 +80,15 @@ def parse_cmd_line(argv): short_args = "dvh" long_args = ("debug", - "ip=", - "verbose", - "help", - "data=", - ) + "ip=", + "verbose", + "help", + "data=", + ) try: opts, extra_opts = getopt.getopt(argv[1:], short_args, long_args) except getopt.GetoptError as e: - print("Unrecognized command line option or missing required argument: %s" %(e)) + print("Unrecognized command line option or missing required argument: %s" % (e)) print(usage) sys.exit(2) @@ -99,7 +99,7 @@ def parse_cmd_line(argv): elif sys.platform == "osx": cmd_line_option_list['syslog'] = "/var/run/syslog" else: - cmd_line_option_list['syslog'] = ('localhost',514) + cmd_line_option_list['syslog'] = ('localhost', 514) for opt, val in opts: if opt in ("-h", "--help"): diff --git a/gns3server/version.py b/gns3server/version.py index ed60edd9..f650a7bf 100644 --- a/gns3server/version.py +++ b/gns3server/version.py @@ -25,4 +25,3 @@ __version__ = "1.3.dev1" __version_info__ = (1, 3, 0, 0) - diff --git a/gns3server/web/documentation.py b/gns3server/web/documentation.py index 2a2d212c..b699f9dd 100644 --- a/gns3server/web/documentation.py +++ b/gns3server/web/documentation.py @@ -22,7 +22,9 @@ from gns3server.web.route import Route class Documentation(object): + """Extract API documentation as Sphinx compatible files""" + def __init__(self, route): self._documentation = route.get_documentation() diff --git a/gns3server/web/response.py b/gns3server/web/response.py index e5cd6912..2a0b3911 100644 --- a/gns3server/web/response.py +++ b/gns3server/web/response.py @@ -38,6 +38,7 @@ class Response(aiohttp.web.Response): :param anwser The response as a Python object """ + def json(self, answer): """Pass a Python object and return a JSON as answer""" diff --git a/gns3server/web/route.py b/gns3server/web/route.py index 086a6b50..4cc6a863 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -49,6 +49,7 @@ def parse_request(request, input_schema): class Route(object): + """ Decorator adding: * json schema verification * routing inside handlers diff --git a/old_tests/dynamips/test_c1700.py b/old_tests/dynamips/test_c1700.py index 4ed3a2d2..222d5a8f 100644 --- a/old_tests/dynamips/test_c1700.py +++ b/old_tests/dynamips/test_c1700.py @@ -89,7 +89,7 @@ def test_iomem(router_c1700): def test_mac_addr(router_c1700): - assert router_c1700.mac_addr != None + assert router_c1700.mac_addr is not None router_c1700.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c1700.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c2600.py b/old_tests/dynamips/test_c2600.py index ae94f1b4..53bfb0db 100644 --- a/old_tests/dynamips/test_c2600.py +++ b/old_tests/dynamips/test_c2600.py @@ -165,7 +165,7 @@ def test_iomem(router_c2600): def test_mac_addr(router_c2600): - assert router_c2600.mac_addr != None + assert router_c2600.mac_addr is not None router_c2600.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c2600.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c2691.py b/old_tests/dynamips/test_c2691.py index 64acc6c1..282b183b 100644 --- a/old_tests/dynamips/test_c2691.py +++ b/old_tests/dynamips/test_c2691.py @@ -29,7 +29,7 @@ def test_iomem(router_c2691): def test_mac_addr(router_c2691): - assert router_c2691.mac_addr != None + assert router_c2691.mac_addr is not None router_c2691.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c2691.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c3600.py b/old_tests/dynamips/test_c3600.py index 435f1b27..cd05add3 100644 --- a/old_tests/dynamips/test_c3600.py +++ b/old_tests/dynamips/test_c3600.py @@ -60,7 +60,7 @@ def test_iomem(router_c3600): def test_mac_addr(router_c3600): - assert router_c3600.mac_addr != None + assert router_c3600.mac_addr is not None router_c3600.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c3600.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c3725.py b/old_tests/dynamips/test_c3725.py index a4a923cf..bc3ffcbf 100644 --- a/old_tests/dynamips/test_c3725.py +++ b/old_tests/dynamips/test_c3725.py @@ -29,7 +29,7 @@ def test_iomem(router_c3725): def test_mac_addr(router_c3725): - assert router_c3725.mac_addr != None + assert router_c3725.mac_addr is not None router_c3725.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c3725.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c3745.py b/old_tests/dynamips/test_c3745.py index c58b5c2e..13d88583 100644 --- a/old_tests/dynamips/test_c3745.py +++ b/old_tests/dynamips/test_c3745.py @@ -29,7 +29,7 @@ def test_iomem(router_c3745): def test_mac_addr(router_c3745): - assert router_c3745.mac_addr != None + assert router_c3745.mac_addr is not None router_c3745.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c3745.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_c7200.py b/old_tests/dynamips/test_c7200.py index 7b74cc7f..48f1eb00 100644 --- a/old_tests/dynamips/test_c7200.py +++ b/old_tests/dynamips/test_c7200.py @@ -57,7 +57,7 @@ def test_power_supplies(router_c7200): def test_mac_addr(router_c7200): - assert router_c7200.mac_addr != None + assert router_c7200.mac_addr is not None router_c7200.mac_addr = "aa:aa:aa:aa:aa:aa" assert router_c7200.mac_addr == "aa:aa:aa:aa:aa:aa" @@ -162,7 +162,7 @@ def test_slot_remove_adapter(router_c7200): adapter = PA_FE_TX() router_c7200.slot_add_binding(1, adapter) router_c7200.slot_remove_binding(1) - assert router_c7200.slots[1] == None + assert router_c7200.slots[1] is None def test_slot_add_remove_nio_binding(router_c7200): diff --git a/old_tests/dynamips/test_hypervisor_manager.py b/old_tests/dynamips/test_hypervisor_manager.py index adaa79a2..c7e42734 100644 --- a/old_tests/dynamips/test_hypervisor_manager.py +++ b/old_tests/dynamips/test_hypervisor_manager.py @@ -11,7 +11,7 @@ def hypervisor_manager(request): print("\nStarting Dynamips Hypervisor: {}".format(dynamips_path)) manager = HypervisorManager(dynamips_path, "/tmp", "127.0.0.1") - #manager.start_new_hypervisor() + # manager.start_new_hypervisor() def stop(): print("\nStopping Dynamips Hypervisor") diff --git a/old_tests/dynamips/test_nios.py b/old_tests/dynamips/test_nios.py index 0538c298..691dac49 100644 --- a/old_tests/dynamips/test_nios.py +++ b/old_tests/dynamips/test_nios.py @@ -133,7 +133,7 @@ def test_reset_stats(hypervisor): def test_set_bandwidth(hypervisor): nio = NIO_Null(hypervisor) - assert nio.bandwidth == None # no constraint by default + assert nio.bandwidth is None # no constraint by default nio.set_bandwidth(1000) # bandwidth = 1000 Kb/s assert nio.bandwidth == 1000 nio.delete() diff --git a/old_tests/dynamips/test_router.py b/old_tests/dynamips/test_router.py index ebf9835c..4b0fd3db 100644 --- a/old_tests/dynamips/test_router.py +++ b/old_tests/dynamips/test_router.py @@ -99,14 +99,14 @@ def test_nvram(router): def test_mmap(router): - assert router.mmap == True # default value + assert router.mmap # default value router.mmap = False assert router.mmap == False def test_sparsemem(router): - assert router.sparsemem == True # default value + assert router.sparsemem # default value router.sparsemem = False assert router.sparsemem == False @@ -209,7 +209,7 @@ def test_get_slot_nio_bindings(router): def test_mac_addr(router): - assert router.mac_addr != None + assert router.mac_addr is not None router.mac_addr = "aa:aa:aa:aa:aa:aa" assert router.mac_addr == "aa:aa:aa:aa:aa:aa" diff --git a/old_tests/dynamips/test_vmhandler.py b/old_tests/dynamips/test_vmhandler.py index cdc4998c..e639d59f 100644 --- a/old_tests/dynamips/test_vmhandler.py +++ b/old_tests/dynamips/test_vmhandler.py @@ -8,56 +8,56 @@ import tempfile # class TestVMHandler(AsyncHTTPTestCase): -# +# # def setUp(self): -# +# # AsyncHTTPTestCase.setUp(self) # self.post_request = partial(self.http_client.fetch, # self.get_url("/api/vms/dynamips"), # self.stop, # method="POST") -# +# # def get_app(self): # return tornado.web.Application(Dynamips().handlers()) -# +# # def test_endpoint(self): # self.http_client.fetch(self.get_url("/api/vms/dynamips"), self.stop) # response = self.wait() # assert response.code == 200 -# +# # def test_upload(self): -# +# # try: # from poster.encode import multipart_encode # except ImportError: # # poster isn't available for Python 3, let's just ignore the test # return -# +# # file_to_upload = tempfile.NamedTemporaryFile() # data, headers = multipart_encode({"file1": file_to_upload}) # body = "" # for d in data: # body += d -# +# # response = self.fetch('/api/vms/dynamips/storage/upload', # headers=headers, # body=body, # method='POST') -# +# # assert response.code == 200 -# +# # def get_new_ioloop(self): # return tornado.ioloop.IOLoop.instance() -# +# # def test_create_vm(self): -# +# # post_data = {"name": "R1", # "platform": "c3725", # "console": 2000, # "aux": 3000, # "image": "c3725.bin", # "ram": 128} -# +# # self.post_request(body=json.dumps(post_data)) # response = self.wait() # assert(response.headers['Content-Type'].startswith('application/json')) diff --git a/old_tests/test_jsonrpc.py b/old_tests/test_jsonrpc.py index 155502c5..eb6920a6 100644 --- a/old_tests/test_jsonrpc.py +++ b/old_tests/test_jsonrpc.py @@ -72,6 +72,7 @@ class JSONRPC(AsyncTestCase): class AsyncWSRequest(TornadoWebSocketClient): + """ Very basic Websocket client for tests """ diff --git a/scripts/ws_client.py b/scripts/ws_client.py index 675bc7c3..9c0911f5 100644 --- a/scripts/ws_client.py +++ b/scripts/ws_client.py @@ -43,4 +43,4 @@ if __name__ == '__main__': ws.connect() ws.run_forever() except KeyboardInterrupt: - ws.close() \ No newline at end of file + ws.close() diff --git a/setup.py b/setup.py index 40a9e409..586d3f32 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ class PyTest(TestCommand): self.test_suite = True def run_tests(self): - #import here, cause outside the eggs aren't loaded + # import here, cause outside the eggs aren't loaded import pytest errcode = pytest.main(self.test_args) sys.exit(errcode) diff --git a/tests/api/base.py b/tests/api/base.py index 85d465e9..ee3d5024 100644 --- a/tests/api/base.py +++ b/tests/api/base.py @@ -36,6 +36,7 @@ from gns3server.modules.project_manager import ProjectManager class Query: + def __init__(self, loop, host='localhost', port=8001): self._loop = loop self._port = port diff --git a/tests/utils.py b/tests/utils.py index ee2aff19..40ef2803 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -20,6 +20,7 @@ from unittest.mock import patch class _asyncio_patch: + """ A wrapper around python patch supporting asyncio. Like the original patch you can use it as context @@ -29,6 +30,7 @@ class _asyncio_patch: inspiration: https://hg.python.org/cpython/file/3.4/Lib/unittest/mock.py """ + def __init__(self, function, *args, **kwargs): self.function = function self.args = args