mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Merge pull request #12 from joebowen/master
Fixes for the VPCS path setting and base_script_file setting
This commit is contained in:
commit
0f8d1bc6da
@ -275,6 +275,9 @@ class VPCS(IModule):
|
|||||||
name = None
|
name = None
|
||||||
if "name" in request:
|
if "name" in request:
|
||||||
name = request["name"]
|
name = request["name"]
|
||||||
|
base_script_file = None
|
||||||
|
if "base_script_file" in request:
|
||||||
|
base_script_file = request["base_script_file"]
|
||||||
vpcs_path = request["path"]
|
vpcs_path = request["path"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -285,7 +288,23 @@ class VPCS(IModule):
|
|||||||
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)
|
# a new base-script-file has been pushed
|
||||||
|
if "base_script_file_base64" in request:
|
||||||
|
config = base64.decodestring(request["base_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(self._working_dir, "base-script-file")
|
||||||
|
try:
|
||||||
|
with open(config_path, "w") as f:
|
||||||
|
log.info("saving base-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 base-script-file path
|
||||||
|
request["base_script_file"] = os.path.basename(config_path)
|
||||||
|
|
||||||
|
vpcs_instance = VPCSDevice(vpcs_path, config_path, self._working_dir, host=self._host, name=name)
|
||||||
|
|
||||||
# find a console port
|
# find a console port
|
||||||
if self._current_console_port > self._console_end_port_range:
|
if self._current_console_port > self._console_end_port_range:
|
||||||
self._current_console_port = self._console_start_port_range
|
self._current_console_port = self._console_start_port_range
|
||||||
@ -348,7 +367,7 @@ class VPCS(IModule):
|
|||||||
|
|
||||||
Optional request parameters:
|
Optional request parameters:
|
||||||
- any setting to update
|
- any setting to update
|
||||||
- script_file_base64 (script-file base64 encoded)
|
- base_script_file_base64 (script-file base64 encoded)
|
||||||
|
|
||||||
Response parameters:
|
Response parameters:
|
||||||
- updated settings
|
- updated settings
|
||||||
@ -367,25 +386,25 @@ class VPCS(IModule):
|
|||||||
|
|
||||||
response = {}
|
response = {}
|
||||||
try:
|
try:
|
||||||
# a new script-file has been pushed
|
# a new base-script-file has been pushed
|
||||||
if "script_file_base64" in request:
|
if "base_script_file_base64" in request:
|
||||||
config = base64.decodestring(request["script_file_base64"].encode("utf-8")).decode("utf-8")
|
config = base64.decodestring(request["base_script_file_base64"].encode("utf-8")).decode("utf-8")
|
||||||
config = "!\n" + config.replace("\r", "")
|
config = "!\n" + config.replace("\r", "")
|
||||||
config = config.replace('%h', vpcs_instance.name)
|
config = config.replace('%h', vpcs_instance.name)
|
||||||
config_path = os.path.join(vpcs_instance.working_dir, "script-file")
|
config_path = os.path.join(vpcs_instance.working_dir, "base-script-file")
|
||||||
try:
|
try:
|
||||||
with open(config_path, "w") as f:
|
with open(config_path, "w") as f:
|
||||||
log.info("saving script-file to {}".format(config_path))
|
log.info("saving base-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 base-script-file path
|
||||||
request["script_file"] = os.path.basename(config_path)
|
request["base_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
|
||||||
|
|
||||||
# update the VPCS settings
|
# update the VPCS settings
|
||||||
for name, value in request.items():
|
for name, value in request.items():
|
||||||
if hasattr(vpcs_instance, name) and getattr(vpcs_instance, name) != value:
|
if hasattr(vpcs_instance, name) and getattr(vpcs_instance, name) != value:
|
||||||
|
@ -30,7 +30,16 @@ VPCS_CREATE_SCHEMA = {
|
|||||||
"description": "path to the VPCS executable",
|
"description": "path to the VPCS executable",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
}
|
},
|
||||||
|
"base_script_file": {
|
||||||
|
"description": "path to the VPCS startup configuration file",
|
||||||
|
"type": "string",
|
||||||
|
"minLength": 1,
|
||||||
|
},
|
||||||
|
"base_script_file_base64": {
|
||||||
|
"description": "startup script file base64 encoded",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"required": ["path"]
|
"required": ["path"]
|
||||||
}
|
}
|
||||||
@ -67,13 +76,13 @@ VPCS_UPDATE_SCHEMA = {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
"script_file": {
|
"base_script_file": {
|
||||||
"description": "path to the VPCS startup configuration file",
|
"description": "path to the VPCS startup script file file",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
"script_file_base64": {
|
"base_script_file_base64": {
|
||||||
"description": "startup configuration base64 encoded",
|
"description": "startup script file base64 encoded",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -45,13 +45,13 @@ class VPCSDevice(object):
|
|||||||
|
|
||||||
_instances = []
|
_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)
|
# find an instance identifier (1 <= id <= 512)
|
||||||
# This 255 limit is due to a restriction on the number of possible
|
# This 512 limit is due to a restriction on the number of possible
|
||||||
# mac addresses given in VPCS using the -m option
|
# mac addresses given in VPCS using the -m option
|
||||||
self._id = 0
|
self._id = 0
|
||||||
for identifier in range(1, 256):
|
for identifier in range(1, 513):
|
||||||
if identifier not in self._instances:
|
if identifier not in self._instances:
|
||||||
self._id = identifier
|
self._id = identifier
|
||||||
self._instances.append(self._id)
|
self._instances.append(self._id)
|
||||||
@ -74,7 +74,7 @@ class VPCSDevice(object):
|
|||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
# VPCS settings
|
# VPCS settings
|
||||||
self._script_file = ""
|
self._base_script_file = base_script_file
|
||||||
self._ethernet_adapters = [EthernetAdapter()] # one adapter = 1 interfaces
|
self._ethernet_adapters = [EthernetAdapter()] # one adapter = 1 interfaces
|
||||||
self._slots = self._ethernet_adapters
|
self._slots = self._ethernet_adapters
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ class VPCSDevice(object):
|
|||||||
|
|
||||||
vpcs_defaults = {"name": self._name,
|
vpcs_defaults = {"name": self._name,
|
||||||
"path": self._path,
|
"path": self._path,
|
||||||
"script_file": self._script_file,
|
"base_script_file": self._base_script_file,
|
||||||
"console": self._console}
|
"console": self._console}
|
||||||
|
|
||||||
return vpcs_defaults
|
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(["-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._base_script_file:
|
||||||
command.extend([self._script_file])
|
command.extend([self._base_script_file])
|
||||||
return command
|
return command
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def script_file(self):
|
def base_script_file(self):
|
||||||
"""
|
"""
|
||||||
Returns the script-file for this VPCS instance.
|
Returns the script-file for this VPCS instance.
|
||||||
|
|
||||||
:returns: path to script-file file
|
:returns: path to script-file file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return self._script_file
|
return self._base_script_file
|
||||||
|
|
||||||
@script_file.setter
|
@base_script_file.setter
|
||||||
def script_file(self, script_file):
|
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
|
self._base_script_file = base_script_file
|
||||||
log.info("VPCS {name} [id={id}]: script_file set to {config}".format(name=self._name,
|
log.info("VPCS {name} [id={id}]: base_script_file set to {config}".format(name=self._name,
|
||||||
id=self._id,
|
id=self._id,
|
||||||
config=self._script_file))
|
config=self._base_script_file))
|
||||||
|
Loading…
Reference in New Issue
Block a user