1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

PEP 8 clean thanks to auto pep8

This commit is contained in:
Julien Duponchelle 2015-01-20 13:24:00 +01:00
parent 7f185663d1
commit f5ed9fbcf1
124 changed files with 340 additions and 210 deletions

View File

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

View File

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

View File

@ -98,6 +98,8 @@ Options:
""" % (SCRIPT_NAME)
# Parse cmd line options
def parse_cmd_line(argv):
"""
Parse command line arguments
@ -148,7 +150,6 @@ def parse_cmd_line(argv):
else:
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
@ -294,6 +296,7 @@ def _get_file_age(filename):
os.path.getmtime(filename)
)
def monitor_loop(options):
"""
Checks the options["file"] modification time against an interval. If the
@ -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'])
)
@ -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)

View File

@ -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."""
@ -114,7 +120,7 @@ class daemon:
# Try killing the daemon process
try:
while 1:
while True:
os.kill(pid, signal.SIGTERM)
time.sleep(0.1)
except OSError as err:

View File

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

View File

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

View File

@ -27,7 +27,9 @@ 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"
@ -39,7 +41,9 @@ class GNS3BaseHandler(tornado.web.RequestHandler):
if self.settings['required_user'] == user.decode("utf-8"):
return user
class GNS3WebSocketBaseHandler(tornado.websocket.WebSocketHandler):
def get_current_user(self):
if 'required_user' not in self.settings:
return "FakeUser"
@ -53,6 +57,7 @@ class GNS3WebSocketBaseHandler(tornado.websocket.WebSocketHandler):
class LoginHandler(tornado.web.RequestHandler):
def get(self):
self.write('<html><body><form action="/login" method="post">'
'Name: <input type="text" name="name">'

View File

@ -34,6 +34,7 @@ log = logging.getLogger(__name__)
class FileUploadHandler(GNS3BaseHandler):
"""
File upload handler.

View File

@ -22,6 +22,7 @@ from aiohttp.web import HTTPConflict
class ProjectHandler:
@classmethod
@Route.post(
r"/project",

View File

@ -22,6 +22,7 @@ from ..modules.virtualbox import VirtualBox
class VirtualBoxHandler:
"""
API entry points for VirtualBox.
"""

View File

@ -23,6 +23,7 @@ from ..modules.vpcs import VPCS
class VPCSHandler:
"""
API entry points for VPCS.
"""

View File

@ -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
@ -75,7 +76,6 @@ def main():
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:

View File

@ -17,6 +17,7 @@
class Adapter(object):
"""
Base class for adapters.

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class EthernetAdapter(Adapter):
"""
VPCS Ethernet adapter.
"""

View File

@ -24,6 +24,7 @@ from .project_manager import ProjectManager
class BaseManager:
"""
Base class for all Manager.
Responsible of management of a VM pool

View File

@ -95,6 +95,7 @@ log = logging.getLogger(__name__)
class Dynamips(IModule):
"""
Dynamips module.

View File

@ -17,6 +17,7 @@
class Adapter(object):
"""
Base class for adapters.

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C1700_MB_1FE(Adapter):
"""
Integrated 1 port FastEthernet adapter for c1700 platform.
"""

View File

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

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C2600_MB_1E(Adapter):
"""
Integrated 1 port Ethernet adapter for the c2600 platform.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C2600_MB_1FE(Adapter):
"""
Integrated 1 port FastEthernet adapter for the c2600 platform.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C2600_MB_2E(Adapter):
"""
Integrated 2 port Ethernet adapter for the c2600 platform.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C2600_MB_2FE(Adapter):
"""
Integrated 2 port FastEthernet adapter for the c2600 platform.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C7200_IO_2FE(Adapter):
"""
C7200-IO-2FE FastEthernet Input/Ouput controller.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C7200_IO_FE(Adapter):
"""
C7200-IO-FE FastEthernet Input/Ouput controller.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class C7200_IO_GE_E(Adapter):
"""
C7200-IO-GE-E GigabitEthernet Input/Ouput controller.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class Leopard_2FE(Adapter):
"""
Integrated 2 port FastEthernet adapter for c3660 router.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class NM_16ESW(Adapter):
"""
NM-16ESW FastEthernet network module.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class NM_1E(Adapter):
"""
NM-1E Ethernet network module.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class NM_1FE_TX(Adapter):
"""
NM-1FE-TX FastEthernet network module.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class NM_4E(Adapter):
"""
NM-4E Ethernet network module.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class NM_4T(Adapter):
"""
NM-4T Serial network module.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_2FE_TX(Adapter):
"""
PA-2FE-TX FastEthernet port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_4E(Adapter):
"""
PA-4E Ethernet port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_4T(Adapter):
"""
PA-4T+ Serial port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_8E(Adapter):
"""
PA-8E Ethernet port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_8T(Adapter):
"""
PA-8T Serial port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_A1(Adapter):
"""
PA-A1 ATM port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_FE_TX(Adapter):
"""
PA-FE-TX FastEthernet port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_GE(Adapter):
"""
PA-GE GigabitEthernet port adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class PA_POS_OC3(Adapter):
"""
PA-POS-OC3 port adapter.
"""

View File

@ -17,6 +17,7 @@
class WIC_1ENET(object):
"""
WIC-1ENET Ethernet
"""

View File

@ -17,6 +17,7 @@
class WIC_1T(object):
"""
WIC-1T Serial
"""

View File

@ -17,6 +17,7 @@
class WIC_2T(object):
"""
WIC-2T Serial
"""

View File

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

View File

@ -30,6 +30,7 @@ log = logging.getLogger(__name__)
class DynamipsHypervisor(object):
"""
Creates a new connection to a Dynamips server (also called hypervisor)

View File

@ -32,6 +32,7 @@ log = logging.getLogger(__name__)
class Hypervisor(DynamipsHypervisor):
"""
Hypervisor.

View File

@ -34,6 +34,7 @@ log = logging.getLogger(__name__)
class HypervisorManager(object):
"""
Manages Dynamips hypervisors.

View File

@ -27,6 +27,7 @@ log = logging.getLogger(__name__)
class NIO(object):
"""
Base NIO class

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_FIFO(NIO):
"""
Dynamips FIFO NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_GenericEthernet(NIO):
"""
Dynamips generic Ethernet NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_LinuxEthernet(NIO):
"""
Dynamips Linux Ethernet NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_Mcast(NIO):
"""
Dynamips Linux Ethernet NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_Null(NIO):
"""
Dynamips NULL NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_TAP(NIO):
"""
Dynamips TAP NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_UDP(NIO):
"""
Dynamips UDP NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_UDP_auto(NIO):
"""
Dynamips auto UDP NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_UNIX(NIO):
"""
Dynamips UNIX NIO.

View File

@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
class NIO_VDE(NIO):
"""
Dynamips VDE NIO.

View File

@ -24,6 +24,7 @@ from ..dynamips_error import DynamipsError
class ATMBridge(object):
"""
Dynamips bridge switch.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class ATMSwitch(object):
"""
Dynamips ATM switch.

View File

@ -22,6 +22,7 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L538
class Bridge(object):
"""
Dynamips bridge.

View File

@ -29,6 +29,7 @@ log = logging.getLogger(__name__)
class C1700(Router):
"""
Dynamips c1700 router.

View File

@ -31,6 +31,7 @@ log = logging.getLogger(__name__)
class C2600(Router):
"""
Dynamips c2600 router.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class C2691(Router):
"""
Dynamips c2691 router.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class C3600(Router):
"""
Dynamips c3600 router.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class C3725(Router):
"""
Dynamips c3725 router.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class C3745(Router):
"""
Dynamips c3745 router.

View File

@ -30,6 +30,7 @@ log = logging.getLogger(__name__)
class C7200(Router):
"""
Dynamips c7200 router (model is 7206).

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class EthernetSwitch(object):
"""
Dynamips Ethernet switch.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class FrameRelaySwitch(object):
"""
Dynamips Frame Relay switch.

View File

@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
class Hub(Bridge):
"""
Dynamips hub (based on Bridge)

View File

@ -33,6 +33,7 @@ log = logging.getLogger(__name__)
class Router(object):
"""
Dynamips router implementation.

View File

@ -56,6 +56,7 @@ log = logging.getLogger(__name__)
class IOU(IModule):
"""
IOU module.

View File

@ -17,6 +17,7 @@
class Adapter(object):
"""
Base class for adapters.

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class EthernetAdapter(Adapter):
"""
IOU Ethernet adapter.
"""

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class SerialAdapter(Adapter):
"""
IOU Serial adapter.
"""

View File

@ -43,6 +43,7 @@ log = logging.getLogger(__name__)
class IOUDevice(object):
"""
IOU device implementation.

View File

@ -154,6 +154,7 @@ class FileLock:
class Console:
def fileno(self):
raise NotImplementedError("Only routers have fileno()")

View File

@ -21,6 +21,7 @@ Base interface for NIOs.
class NIO(object):
"""
Network Input/Output.
"""

View File

@ -23,6 +23,7 @@ from .nio import NIO
class NIO_GenericEthernet(NIO):
"""
Generic Ethernet NIO.

View File

@ -23,6 +23,7 @@ from .nio import NIO
class NIO_TAP(NIO):
"""
TAP NIO.

View File

@ -23,6 +23,7 @@ from .nio import NIO
class NIO_UDP(NIO):
"""
UDP NIO.

View File

@ -21,6 +21,7 @@ Interface for TAP NIOs (UNIX based OSes only).
class NIO_TAP(object):
"""
TAP NIO.

View File

@ -21,6 +21,7 @@ Interface for UDP NIOs.
class NIO_UDP(object):
"""
UDP NIO.

View File

@ -21,6 +21,7 @@ import asyncio
class PortManager:
"""
:param host: IP address to bind for console connections
"""

View File

@ -21,6 +21,7 @@ from uuid import uuid4
class Project:
"""
A project contains a list of VM.
In theory VM are isolated project/project.

View File

@ -20,6 +20,7 @@ from .project import Project
class ProjectManager:
"""
This singleton keeps track of available projects.
"""

View File

@ -49,6 +49,7 @@ log = logging.getLogger(__name__)
class Qemu(IModule):
"""
QEMU module.

View File

@ -17,6 +17,7 @@
class Adapter(object):
"""
Base class for adapters.

View File

@ -19,6 +19,7 @@ from .adapter import Adapter
class EthernetAdapter(Adapter):
"""
QEMU Ethernet adapter.
"""

View File

@ -21,6 +21,7 @@ Base interface for NIOs.
class NIO(object):
"""
Network Input/Output.
"""

View File

@ -23,6 +23,7 @@ from .nio import NIO
class NIO_UDP(NIO):
"""
UDP NIO.

View File

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

View File

@ -31,6 +31,7 @@ if sys.platform.startswith("win"):
class TelnetServer(threading.Thread):
"""
Mini Telnet Server.
@ -257,6 +258,7 @@ LINEMO = 34 # Line Mode
class TelnetClient(object):
"""
Represents a Telnet client connection.

View File

@ -45,6 +45,7 @@ log = logging.getLogger(__name__)
class VirtualBoxVM(BaseVM):
"""
VirtualBox VM implementation.
"""
@ -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))

View File

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

View File

@ -25,4 +25,3 @@
__version__ = "1.3.dev1"
__version_info__ = (1, 3, 0, 0)

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More