mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-26 08:48:11 +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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
vpcs server module.
|
VPCS server module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -52,7 +52,7 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class VPCS(IModule):
|
class VPCS(IModule):
|
||||||
"""
|
"""
|
||||||
vpcs module.
|
VPCS module.
|
||||||
|
|
||||||
:param name: module name
|
:param name: module name
|
||||||
:param args: arguments for the module
|
:param args: arguments for the module
|
||||||
@ -283,7 +283,7 @@ class VPCS(IModule):
|
|||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
except OSError as e:
|
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)
|
vpcs_instance = VPCSDevice(vpcs_path, self._working_dir, host=self._host, name=name)
|
||||||
# find a console port
|
# find a console port
|
||||||
@ -292,7 +292,7 @@ class VPCS(IModule):
|
|||||||
try:
|
try:
|
||||||
vpcs_instance.console = find_unused_port(self._current_console_port, self._console_end_port_range, self._host)
|
vpcs_instance.console = find_unused_port(self._current_console_port, self._console_end_port_range, self._host)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise vpcsError(e)
|
raise VPCSError(e)
|
||||||
self._current_console_port += 1
|
self._current_console_port += 1
|
||||||
except VPCSError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
@ -332,7 +332,7 @@ class VPCS(IModule):
|
|||||||
try:
|
try:
|
||||||
vpcs_instance.delete()
|
vpcs_instance.delete()
|
||||||
del self._vpcs_instances[request["id"]]
|
del self._vpcs_instances[request["id"]]
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -378,11 +378,11 @@ class VPCS(IModule):
|
|||||||
log.info("saving script-file to {}".format(config_path))
|
log.info("saving script-file to {}".format(config_path))
|
||||||
f.write(config)
|
f.write(config)
|
||||||
except OSError as e:
|
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
|
# update the request with the new local script-file path
|
||||||
request["script_file"] = os.path.basename(config_path)
|
request["script_file"] = os.path.basename(config_path)
|
||||||
|
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ class VPCS(IModule):
|
|||||||
try:
|
try:
|
||||||
setattr(vpcs_instance, name, value)
|
setattr(vpcs_instance, name, value)
|
||||||
response[name] = value
|
response[name] = value
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ class VPCS(IModule):
|
|||||||
log.debug("starting vpcs with command: {}".format(vpcs_instance.command()))
|
log.debug("starting vpcs with command: {}".format(vpcs_instance.command()))
|
||||||
vpcs_instance.vpcs = self._vpcs
|
vpcs_instance.vpcs = self._vpcs
|
||||||
vpcs_instance.start()
|
vpcs_instance.start()
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
self.send_response(True)
|
self.send_response(True)
|
||||||
@ -455,7 +455,7 @@ class VPCS(IModule):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
vpcs_instance.stop()
|
vpcs_instance.stop()
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
self.send_response(True)
|
self.send_response(True)
|
||||||
@ -487,7 +487,7 @@ class VPCS(IModule):
|
|||||||
if vpcs_instance.is_running():
|
if vpcs_instance.is_running():
|
||||||
vpcs_instance.stop()
|
vpcs_instance.stop()
|
||||||
vpcs_instance.start()
|
vpcs_instance.start()
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
self.send_response(True)
|
self.send_response(True)
|
||||||
@ -525,7 +525,7 @@ class VPCS(IModule):
|
|||||||
try:
|
try:
|
||||||
port = find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP")
|
port = find_unused_port(self._current_udp_port, self._udp_end_port_range, host=self._host, socket_type="UDP")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise vpcsError(e)
|
raise VPCSError(e)
|
||||||
self._current_udp_port += 1
|
self._current_udp_port += 1
|
||||||
|
|
||||||
log.info("{} [id={}] has allocated UDP port {} with host {}".format(vpcs_instance.name,
|
log.info("{} [id={}] has allocated UDP port {} with host {}".format(vpcs_instance.name,
|
||||||
@ -534,7 +534,7 @@ class VPCS(IModule):
|
|||||||
self._host))
|
self._host))
|
||||||
response = {"lport": port}
|
response = {"lport": port}
|
||||||
|
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
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))
|
log.error("could not determine if CAP_NET_RAW capability is set for {}: {}".format(self._vpcs, e))
|
||||||
return
|
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")
|
@IModule.route("vpcs.add_nio")
|
||||||
def add_nio(self, request):
|
def add_nio(self, request):
|
||||||
@ -612,14 +612,14 @@ class VPCS(IModule):
|
|||||||
self._check_for_privileged_access(tap_device)
|
self._check_for_privileged_access(tap_device)
|
||||||
nio = NIO_TAP(tap_device)
|
nio = NIO_TAP(tap_device)
|
||||||
if not nio:
|
if not nio:
|
||||||
raise vpcsError("Requested NIO does not exist or is not supported: {}".format(request["nio"]["type"]))
|
raise VPCSError("Requested NIO does not exist or is not supported: {}".format(request["nio"]["type"]))
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vpcs_instance.slot_add_nio_binding(slot, port, nio)
|
vpcs_instance.slot_add_nio_binding(slot, port, nio)
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -654,7 +654,7 @@ class VPCS(IModule):
|
|||||||
port = request["port"]
|
port = request["port"]
|
||||||
try:
|
try:
|
||||||
vpcs_instance.slot_remove_nio_binding(slot, port)
|
vpcs_instance.slot_remove_nio_binding(slot, port)
|
||||||
except vpcsError as e:
|
except VPCSError as e:
|
||||||
self.send_custom_error(str(e))
|
self.send_custom_error(str(e))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class VPCSDevice(object):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if self._id == 0:
|
if self._id == 0:
|
||||||
raise vpcsError("Maximum number of vpcs instances reached")
|
raise VPCSError("Maximum number of vpcs instances reached")
|
||||||
|
|
||||||
if name:
|
if name:
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -192,7 +192,7 @@ class VPCSDevice(object):
|
|||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
except OSError as e:
|
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
|
self._working_dir = working_dir
|
||||||
log.info("vpcs {name} [id={id}]: working directory changed to {wd}".format(name=self._name,
|
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 self.is_running():
|
||||||
|
|
||||||
if not os.path.isfile(self._path):
|
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):
|
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()
|
self._command = self._build_command()
|
||||||
try:
|
try:
|
||||||
@ -279,7 +279,7 @@ class VPCSDevice(object):
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
vpcs_stdout = self.read_vpcs_stdout()
|
vpcs_stdout = self.read_vpcs_stdout()
|
||||||
log.error("could not start vpcs {}: {}\n{}".format(self._path, e, 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):
|
def stop(self):
|
||||||
"""
|
"""
|
||||||
@ -300,7 +300,6 @@ class VPCSDevice(object):
|
|||||||
self._process = None
|
self._process = None
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
|
|
||||||
def read_vpcs_stdout(self):
|
def read_vpcs_stdout(self):
|
||||||
"""
|
"""
|
||||||
Reads the standard output of the vpcs process.
|
Reads the standard output of the vpcs process.
|
||||||
@ -335,7 +334,6 @@ class VPCSDevice(object):
|
|||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def slot_add_nio_binding(self, slot_id, port_id, nio):
|
def slot_add_nio_binding(self, slot_id, port_id, nio):
|
||||||
"""
|
"""
|
||||||
Adds a slot NIO binding.
|
Adds a slot NIO binding.
|
||||||
@ -348,11 +346,11 @@ class VPCSDevice(object):
|
|||||||
try:
|
try:
|
||||||
adapter = self._slots[slot_id]
|
adapter = self._slots[slot_id]
|
||||||
except IndexError:
|
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))
|
slot_id=slot_id))
|
||||||
|
|
||||||
if not adapter.port_exists(port_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))
|
port_id=port_id))
|
||||||
|
|
||||||
adapter.add_nio(port_id, nio)
|
adapter.add_nio(port_id, nio)
|
||||||
@ -373,11 +371,11 @@ class VPCSDevice(object):
|
|||||||
try:
|
try:
|
||||||
adapter = self._slots[slot_id]
|
adapter = self._slots[slot_id]
|
||||||
except IndexError:
|
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))
|
slot_id=slot_id))
|
||||||
|
|
||||||
if not adapter.port_exists(port_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))
|
port_id=port_id))
|
||||||
|
|
||||||
nio = adapter.get_nio(port_id)
|
nio = adapter.get_nio(port_id)
|
||||||
@ -435,10 +433,10 @@ class VPCSDevice(object):
|
|||||||
|
|
||||||
elif isinstance(nio, NIO_TAP):
|
elif isinstance(nio, NIO_TAP):
|
||||||
# TAP interface
|
# TAP interface
|
||||||
command.extend(["-e"]) #, str(nio.tap_device)]) #TODO: Fix, currently vpcs doesn't allow specific tap_device
|
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(["-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(["-i", str(1)]) # Option to start only one pc instance
|
||||||
if self._script_file:
|
if self._script_file:
|
||||||
command.extend([self._script_file])
|
command.extend([self._script_file])
|
||||||
return command
|
return command
|
||||||
@ -465,5 +463,3 @@ class VPCSDevice(object):
|
|||||||
log.info("vpcs {name} [id={id}]: script_file set to {config}".format(name=self._name,
|
log.info("vpcs {name} [id={id}]: script_file set to {config}".format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
config=self._script_file))
|
config=self._script_file))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user