diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index 1b416889..37c7e583 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -275,6 +275,9 @@ class VPCS(IModule): name = None if "name" in request: name = request["name"] + base_script_file = None + if "base_script_file" in request: + base_script_file = request["base_script_file"] vpcs_path = request["path"] try: @@ -285,7 +288,7 @@ class VPCS(IModule): except OSError as 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, base_script_file, self._working_dir, host=self._host, name=name) # find a console port if self._current_console_port > self._console_end_port_range: self._current_console_port = self._console_start_port_range @@ -348,7 +351,6 @@ class VPCS(IModule): Optional request parameters: - any setting to update - - script_file_base64 (script-file base64 encoded) Response parameters: - updated settings @@ -366,26 +368,6 @@ class VPCS(IModule): return response = {} - try: - # a new script-file has been pushed - if "script_file_base64" in request: - config = base64.decodestring(request["script_file_base64"].encode("utf-8")).decode("utf-8") - config = "!\n" + config.replace("\r", "") - config = config.replace('%h', vpcs_instance.name) - config_path = os.path.join(vpcs_instance.working_dir, "script-file") - try: - with open(config_path, "w") as f: - 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)) - # update the request with the new local script-file path - request["script_file"] = os.path.basename(config_path) - - except VPCSError as e: - self.send_custom_error(str(e)) - return - # update the VPCS settings for name, value in request.items(): if hasattr(vpcs_instance, name) and getattr(vpcs_instance, name) != value: diff --git a/gns3server/modules/vpcs/schemas.py b/gns3server/modules/vpcs/schemas.py index d1061384..fbfd13f2 100644 --- a/gns3server/modules/vpcs/schemas.py +++ b/gns3server/modules/vpcs/schemas.py @@ -30,7 +30,12 @@ VPCS_CREATE_SCHEMA = { "description": "path to the VPCS executable", "type": "string", "minLength": 1, - } + }, + "base_script_file": { + "description": "path to the VPCS startup configuration file", + "type": "string", + "minLength": 1, + }, }, "required": ["path"] } @@ -67,15 +72,11 @@ VPCS_UPDATE_SCHEMA = { "type": "string", "minLength": 1, }, - "script_file": { + "base_script_file": { "description": "path to the VPCS startup configuration file", "type": "string", "minLength": 1, }, - "script_file_base64": { - "description": "startup configuration base64 encoded", - "type": "string" - }, }, "required": ["id"] } diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index af4ba19d..3e59fbba 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -45,7 +45,7 @@ class VPCSDevice(object): _instances = [] - def __init__(self, path, working_dir, host="127.0.0.1", name=None): + def __init__(self, path, base_script_file, working_dir, host="127.0.0.1", name=None): # find an instance identifier (1 <= id <= 255) # This 255 limit is due to a restriction on the number of possible @@ -74,7 +74,7 @@ class VPCSDevice(object): self._started = False # VPCS settings - self._script_file = "" + self._base_script_file = base_script_file self._ethernet_adapters = [EthernetAdapter()] # one adapter = 1 interfaces self._slots = self._ethernet_adapters @@ -93,7 +93,7 @@ class VPCSDevice(object): vpcs_defaults = {"name": self._name, "path": self._path, - "script_file": self._script_file, + "base_script_file": self._base_script_file, "console": self._console} return vpcs_defaults @@ -432,29 +432,29 @@ class VPCSDevice(object): 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]) + if self._base_script_file: + command.extend([self._base_script_file]) return command @property - def script_file(self): + def base_script_file(self): """ Returns the script-file for this VPCS instance. :returns: path to script-file file """ - return self._script_file + return self._base_script_file - @script_file.setter - def script_file(self, script_file): + @base_script_file.setter + def base_script_file(self, base_script_file): """ - Sets the script-file for this VPCS instance. + Sets the base-script-file for this VPCS instance. - :param script_file: path to script-file file + :param base_script_file: path to base-script-file file """ - self._script_file = script_file - log.info("VPCS {name} [id={id}]: script_file set to {config}".format(name=self._name, + self._base_script_file = base_script_file + log.info("VPCS {name} [id={id}]: base_script_file set to {config}".format(name=self._name, id=self._id, - config=self._script_file)) + config=self._base_script_file))