1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

IOU: rename startup-config to initial-config because it makes more sense.

This commit is contained in:
grossmj 2014-06-18 06:08:00 -06:00
parent cb763e0926
commit 587ddf7646
3 changed files with 37 additions and 37 deletions

View File

@ -356,7 +356,7 @@ class IOU(IModule):
Optional request parameters:
- any setting to update
- startup_config_base64 (startup-config base64 encoded)
- initial_config_base64 (initial-config base64 encoded)
Response parameters:
- updated settings
@ -373,36 +373,36 @@ class IOU(IModule):
if not iou_instance:
return
config_path = os.path.join(iou_instance.working_dir, "startup-config")
config_path = os.path.join(iou_instance.working_dir, "initial-config")
try:
if "startup_config_base64" in request:
# a new startup-config has been pushed
config = base64.decodebytes(request["startup_config_base64"].encode("utf-8")).decode("utf-8")
if "initial_config_base64" in request:
# a new initial-config has been pushed
config = base64.decodebytes(request["initial_config_base64"].encode("utf-8")).decode("utf-8")
config = "!\n" + config.replace("\r", "")
config = config.replace('%h', iou_instance.name)
try:
with open(config_path, "w") as f:
log.info("saving startup-config to {}".format(config_path))
log.info("saving initial-config to {}".format(config_path))
f.write(config)
except OSError as e:
raise IOUError("Could not save the configuration {}: {}".format(config_path, e))
# update the request with the new local startup-config path
request["startup_config"] = os.path.basename(config_path)
elif "startup_config" in request:
if os.path.isfile(request["startup_config"]) and request["startup_config"] != config_path:
# update the request with the new local initial-config path
request["initial_config"] = os.path.basename(config_path)
elif "initial_config" in request:
if os.path.isfile(request["initial_config"]) and request["initial_config"] != config_path:
# this is a local file set in the GUI
try:
with open(request["startup_config"], "r", errors="replace") as f:
with open(request["initial_config"], "r", errors="replace") as f:
config = f.read()
with open(config_path, "w") as f:
config = "!\n" + config.replace("\r", "")
config = config.replace('%h', iou_instance.name)
f.write(config)
request["startup_config"] = os.path.basename(config_path)
request["initial_config"] = os.path.basename(config_path)
except OSError as e:
raise IOUError("Could not save the configuration from {} to {}: {}".format(request["startup_config"], config_path, e))
raise IOUError("Could not save the configuration from {} to {}: {}".format(request["initial_config"], config_path, e))
elif not os.path.isfile(config_path):
raise IOUError("Startup-config {} could not be found on this server".format(request["startup_config"]))
raise IOUError("Startup-config {} could not be found on this server".format(request["initial_config"]))
except IOUError as e:
self.send_custom_error(str(e))
return

View File

@ -110,7 +110,7 @@ class IOUDevice(object):
self._slots = self._ethernet_adapters + self._serial_adapters
self._use_default_iou_values = True # for RAM & NVRAM values
self._nvram = 128 # Kilobytes
self._startup_config = ""
self._initial_config = ""
self._ram = 256 # Megabytes
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
@ -148,7 +148,7 @@ class IOUDevice(object):
iou_defaults = {"name": self._name,
"path": self._path,
"startup_config": self._startup_config,
"intial_config": self._initial_config,
"use_default_iou_values": self._use_default_iou_values,
"ram": self._ram,
"nvram": self._nvram,
@ -208,9 +208,9 @@ class IOUDevice(object):
new_working_dir,
e))
if self._startup_config:
# update the startup-config
config_path = os.path.join(self._working_dir, "startup-config")
if self._intial_config:
# update the initial-config
config_path = os.path.join(self._working_dir, "initial-config")
if os.path.isfile(config_path):
try:
with open(config_path, "r+", errors="replace") as f:
@ -379,7 +379,7 @@ class IOUDevice(object):
def clean_delete(self):
"""
Deletes this IOU device & all files (nvram, startup-config etc.)
Deletes this IOU device & all files (nvram, initial-config etc.)
"""
self.stop()
@ -799,8 +799,8 @@ class IOUDevice(object):
command.extend(["-n", str(self._nvram)])
command.extend(["-m", str(self._ram)])
command.extend(["-L"]) # disable local console, use remote console
if self._startup_config:
command.extend(["-c", self._startup_config])
if self._initial_config:
command.extend(["-c", self._initial_config])
if self._l1_keepalives:
self._enable_l1_keepalives(command)
command.extend([str(self._id)])
@ -910,27 +910,27 @@ class IOUDevice(object):
self._nvram = nvram
@property
def startup_config(self):
def initial_config(self):
"""
Returns the startup-config for this IOU instance.
Returns the initial-config for this IOU instance.
:returns: path to startup-config file
:returns: path to initial-config file
"""
return self._startup_config
return self._initial_config
@startup_config.setter
def startup_config(self, startup_config):
@initial_config.setter
def initial_config(self, initial_config):
"""
Sets the startup-config for this IOU instance.
Sets the initial-config for this IOU instance.
:param startup_config: path to startup-config file
:param initial_config: path to initial-config file
"""
self._startup_config = startup_config
log.info("IOU {name} [id={id}]: startup_config set to {config}".format(name=self._name,
self._initial_config = initial_config
log.info("IOU {name} [id={id}]: initial_config set to {config}".format(name=self._name,
id=self._id,
config=self._startup_config))
config=self._initial_config))
@property
def ethernet_adapters(self):

View File

@ -79,8 +79,8 @@ IOU_UPDATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"startup_config": {
"description": "path to the IOU startup configuration file",
"initial_config": {
"description": "path to the IOU initial configuration file",
"type": "string",
"minLength": 1,
},
@ -118,8 +118,8 @@ IOU_UPDATE_SCHEMA = {
"description": "enable or disable layer 1 keepalive messages",
"type": "boolean"
},
"startup_config_base64": {
"description": "startup configuration base64 encoded",
"initial_config_base64": {
"description": "initial configuration base64 encoded",
"type": "string"
},
},