mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-21 13:47:50 +00:00
Rename exception vpcsError to VPCSError.
This commit is contained in:
parent
db4280713c
commit
43fa46779f
@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
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
|
||||
|
||||
|
@ -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):
|
||||
"""
|
||||
@ -300,7 +300,6 @@ class VPCSDevice(object):
|
||||
self._process = None
|
||||
self._started = False
|
||||
|
||||
|
||||
def read_vpcs_stdout(self):
|
||||
"""
|
||||
Reads the standard output of the vpcs process.
|
||||
@ -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)
|
||||
@ -437,8 +435,8 @@ class VPCSDevice(object):
|
||||
# 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(["-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))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user