From 43fa46779fda5dc4cdef2a31b8887fd93eef06a6 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 13 May 2014 15:11:37 -0600 Subject: [PATCH] Rename exception vpcsError to VPCSError. --- gns3server/modules/vpcs/__init__.py | 36 +++++++++++------------ gns3server/modules/vpcs/vpcs_device.py | 40 ++++++++++++-------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index a1060b71..baef9bdc 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -16,7 +16,7 @@ # along with this program. If not, see . """ -vpcs server module. +VPCS server module. """ import os @@ -52,7 +52,7 @@ log = logging.getLogger(__name__) class VPCS(IModule): """ - vpcs module. + VPCS module. :param name: module name :param args: arguments for the module @@ -283,7 +283,7 @@ class VPCS(IModule): except FileExistsError: pass except OSError as e: - raise vpcsError("Could not create working directory {}".format(e)) + raise VPCSError("Could not create working directory {}".format(e)) vpcs_instance = VPCSDevice(vpcs_path, self._working_dir, host=self._host, name=name) # find a console port @@ -292,7 +292,7 @@ class VPCS(IModule): try: vpcs_instance.console = find_unused_port(self._current_console_port, self._console_end_port_range, self._host) except Exception as e: - raise vpcsError(e) + raise VPCSError(e) self._current_console_port += 1 except VPCSError as e: self.send_custom_error(str(e)) @@ -332,7 +332,7 @@ class VPCS(IModule): try: vpcs_instance.delete() del self._vpcs_instances[request["id"]] - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return @@ -378,11 +378,11 @@ class VPCS(IModule): log.info("saving script-file to {}".format(config_path)) f.write(config) except OSError as e: - raise vpcsError("Could not save the configuration {}: {}".format(config_path, e)) + raise VPCSError("Could not save the configuration {}: {}".format(config_path, e)) # update the request with the new local script-file path request["script_file"] = os.path.basename(config_path) - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return @@ -392,7 +392,7 @@ class VPCS(IModule): try: setattr(vpcs_instance, name, value) response[name] = value - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return @@ -425,7 +425,7 @@ class VPCS(IModule): log.debug("starting vpcs with command: {}".format(vpcs_instance.command())) vpcs_instance.vpcs = self._vpcs vpcs_instance.start() - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return self.send_response(True) @@ -455,7 +455,7 @@ class VPCS(IModule): try: vpcs_instance.stop() - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return self.send_response(True) @@ -487,7 +487,7 @@ class VPCS(IModule): if vpcs_instance.is_running(): vpcs_instance.stop() vpcs_instance.start() - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return self.send_response(True) @@ -525,7 +525,7 @@ class VPCS(IModule): try: port = find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP") except Exception as e: - raise vpcsError(e) + raise VPCSError(e) self._current_udp_port += 1 log.info("{} [id={}] has allocated UDP port {} with host {}".format(vpcs_instance.name, @@ -534,7 +534,7 @@ class VPCS(IModule): self._host)) response = {"lport": port} - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return @@ -563,7 +563,7 @@ class VPCS(IModule): log.error("could not determine if CAP_NET_RAW capability is set for {}: {}".format(self._vpcs, e)) return - raise vpcsError("{} has no privileged access to {}.".format(self._vpcs, device)) + raise VPCSError("{} has no privileged access to {}.".format(self._vpcs, device)) @IModule.route("vpcs.add_nio") def add_nio(self, request): @@ -612,14 +612,14 @@ class VPCS(IModule): self._check_for_privileged_access(tap_device) nio = NIO_TAP(tap_device) if not nio: - raise vpcsError("Requested NIO does not exist or is not supported: {}".format(request["nio"]["type"])) - except vpcsError as e: + raise VPCSError("Requested NIO does not exist or is not supported: {}".format(request["nio"]["type"])) + except VPCSError as e: self.send_custom_error(str(e)) return try: vpcs_instance.slot_add_nio_binding(slot, port, nio) - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return @@ -654,7 +654,7 @@ class VPCS(IModule): port = request["port"] try: vpcs_instance.slot_remove_nio_binding(slot, port) - except vpcsError as e: + except VPCSError as e: self.send_custom_error(str(e)) return diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index 05de81d1..a30012c1 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -63,7 +63,7 @@ class VPCSDevice(object): break if self._id == 0: - raise vpcsError("Maximum number of vpcs instances reached") + raise VPCSError("Maximum number of vpcs instances reached") if name: self._name = name @@ -192,7 +192,7 @@ class VPCSDevice(object): except FileExistsError: pass except OSError as e: - raise vpcsError("Could not create working directory {}: {}".format(working_dir, e)) + raise VPCSError("Could not create working directory {}: {}".format(working_dir, e)) self._working_dir = working_dir log.info("vpcs {name} [id={id}]: working directory changed to {wd}".format(name=self._name, @@ -259,10 +259,10 @@ class VPCSDevice(object): if not self.is_running(): if not os.path.isfile(self._path): - raise vpcsError("vpcs image '{}' is not accessible".format(self._path)) + raise VPCSError("vpcs image '{}' is not accessible".format(self._path)) if not os.access(self._path, os.X_OK): - raise vpcsError("vpcs image '{}' is not executable".format(self._path)) + raise VPCSError("vpcs image '{}' is not executable".format(self._path)) self._command = self._build_command() try: @@ -279,7 +279,7 @@ class VPCSDevice(object): except OSError as e: vpcs_stdout = self.read_vpcs_stdout() log.error("could not start vpcs {}: {}\n{}".format(self._path, e, vpcs_stdout)) - raise vpcsError("could not start vpcs {}: {}\n{}".format(self._path, e, vpcs_stdout)) + raise VPCSError("could not start vpcs {}: {}\n{}".format(self._path, e, vpcs_stdout)) def stop(self): """ @@ -292,15 +292,14 @@ class VPCSDevice(object): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self._host, self._console)) - sock.send(bytes("quit\n", 'UTF-8')) - sock.close() + sock.send(bytes("quit\n", 'UTF-8')) + sock.close() except TypeError as e: log.warn("vpcs instance {} PID={} is still running. Error: {}".format(self._id, self._process.pid, e)) self._process = None self._started = False - def read_vpcs_stdout(self): """ Reads the standard output of the vpcs process. @@ -327,7 +326,7 @@ class VPCSDevice(object): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self._host, self._console)) - sock.close() + sock.close() return True except: e = sys.exc_info()[0] @@ -335,7 +334,6 @@ class VPCSDevice(object): return False return False - def slot_add_nio_binding(self, slot_id, port_id, nio): """ Adds a slot NIO binding. @@ -348,11 +346,11 @@ class VPCSDevice(object): try: adapter = self._slots[slot_id] except IndexError: - raise vpcsError("Slot {slot_id} doesn't exist on vpcs {name}".format(name=self._name, + raise VPCSError("Slot {slot_id} doesn't exist on vpcs {name}".format(name=self._name, slot_id=slot_id)) if not adapter.port_exists(port_id): - raise vpcsError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=adapter, + raise VPCSError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=adapter, port_id=port_id)) adapter.add_nio(port_id, nio) @@ -373,11 +371,11 @@ class VPCSDevice(object): try: adapter = self._slots[slot_id] except IndexError: - raise vpcsError("Slot {slot_id} doesn't exist on vpcs {name}".format(name=self._name, + raise VPCSError("Slot {slot_id} doesn't exist on vpcs {name}".format(name=self._name, slot_id=slot_id)) if not adapter.port_exists(port_id): - raise vpcsError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=adapter, + raise VPCSError("Port {port_id} doesn't exist in adapter {adapter}".format(adapter=adapter, port_id=port_id)) nio = adapter.get_nio(port_id) @@ -422,7 +420,7 @@ class VPCSDevice(object): command = [self._path] command.extend(["-p", str(self._console)]) - + for adapter in self._slots: for unit in adapter.ports.keys(): nio = adapter.get_nio(unit) @@ -432,13 +430,13 @@ class VPCSDevice(object): command.extend(["-s", str(nio.lport)]) command.extend(["-c", str(nio.rport)]) command.extend(["-t", str(nio.rhost)]) - + elif isinstance(nio, NIO_TAP): # TAP interface - command.extend(["-e"]) #, str(nio.tap_device)]) #TODO: Fix, currently vpcs doesn't allow specific tap_device - - command.extend(["-m", str(self._id)]) #The unique ID is used to set the mac address offset - command.extend(["-i", str(1)]) #Option to start only one pc instance + command.extend(["-e"]) #, str(nio.tap_device)]) #TODO: Fix, currently vpcs doesn't allow specific tap_device + + command.extend(["-m", str(self._id)]) # The unique ID is used to set the mac address offset + command.extend(["-i", str(1)]) # Option to start only one pc instance if self._script_file: command.extend([self._script_file]) return command @@ -465,5 +463,3 @@ class VPCSDevice(object): log.info("vpcs {name} [id={id}]: script_file set to {config}".format(name=self._name, id=self._id, config=self._script_file)) - -