Support l1_keepalives in IOU

This commit is contained in:
Julien Duponchelle committed 2015-02-13 16:57:35 +01:00
1 parent 1550ca01e6
commit ee019caa37
5 files changed
+69 -6

No files matched your search

+3 -1
View File
@@ -55,7 +55,8 @@ class IOUHandler:
serial_adapters=request.json.get("serial_adapters"),
ethernet_adapters=request.json.get("ethernet_adapters"),
ram=request.json.get("ram"),
nvram=request.json.get("nvram")
nvram=request.json.get("nvram"),
l1_keepalives=request.json.get("l1_keepalives")
)
vm.path = request.json.get("path", vm.path)
vm.iourc_path = request.json.get("iourc_path", vm.iourc_path)
@@ -110,6 +111,7 @@ class IOUHandler:
vm.serial_adapters = request.json.get("serial_adapters", vm.serial_adapters)
vm.ram = request.json.get("ram", vm.ram)
vm.nvram = request.json.get("nvram", vm.nvram)
vm.l1_keepalives = request.json.get("l1_keepalives", vm.l1_keepalives)
response.json(vm)
+45 -3
View File
@@ -61,6 +61,7 @@ class IOUVM(BaseVM):
:params serial_adapters: Number of serial adapters
:params ram: Ram MB
:params nvram: Nvram KB
:params l1_keepalives: Always up ethernet interface
"""
def __init__(self, name, vm_id, project, manager,
@@ -69,7 +70,8 @@ class IOUVM(BaseVM):
ram=None,
nvram=None,
ethernet_adapters=None,
serial_adapters=None):
serial_adapters=None,
l1_keepalives=None):
super().__init__(name, vm_id, project, manager)
@@ -93,7 +95,7 @@ class IOUVM(BaseVM):
self._nvram = 128 if nvram is None else nvram # Kilobytes
self._initial_config = ""
self._ram = 256 if ram is None else ram # Megabytes
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
self._l1_keepalives = False if l1_keepalives is None else l1_keepalives # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
if self._console is not None:
self._console = self._manager.port_manager.reserve_console_port(self._console)
@@ -208,7 +210,8 @@ class IOUVM(BaseVM):
"ethernet_adapters": len(self._ethernet_adapters),
"serial_adapters": len(self._serial_adapters),
"ram": self._ram,
"nvram": self._nvram
"nvram": self._nvram,
"l1_keepalives": self._l1_keepalives
}
@property
@@ -759,3 +762,42 @@ class IOUVM(BaseVM):
os.kill(self._iouyap_process.pid, signal.SIGHUP)
return nio
@property
def l1_keepalives(self):
"""
Returns either layer 1 keepalive messages option is enabled or disabled.
:returns: boolean
"""
return self._l1_keepalives
@l1_keepalives.setter
def l1_keepalives(self, state):
"""
Enables or disables layer 1 keepalive messages.
:param state: boolean
"""
self._l1_keepalives = state
if state:
log.info("IOU {name} [id={id}]: has activated layer 1 keepalive messages".format(name=self._name, id=self._id))
else:
log.info("IOU {name} [id={id}]: has deactivated layer 1 keepalive messages".format(name=self._name, id=self._id))
def _enable_l1_keepalives(self, command):
"""
Enables L1 keepalive messages if supported.
:param command: command line
"""
env = os.environ.copy()
env["IOURC"] = self._iourc
try:
output = subprocess.check_output([self._path, "-h"], stderr=subprocess.STDOUT, cwd=self._working_dir, env=env)
if re.search("-l\s+Enable Layer 1 keepalive messages", output.decode("utf-8")):
command.extend(["-l"])
else:
raise IOUError("layer 1 keepalive messages are not supported by {}".format(os.path.basename(self._path)))
except (OSError, subprocess.SubprocessError) as e:
log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e))
@@ -23,6 +23,7 @@ from .nio import NIO
class NIO_GenericEthernet(NIO):
"""
Generic Ethernet NIO.
+13 -1
View File
@@ -65,6 +65,10 @@ IOU_CREATE_SCHEMA = {
"nvram": {
"description": "Allocated NVRAM KB",
"type": ["integer", "null"]
},
"l1_keepalives": {
"description": "Always up ethernet interface",
"type": ["boolean", "null"]
}
},
"additionalProperties": False,
@@ -114,6 +118,10 @@ IOU_UPDATE_SCHEMA = {
"nvram": {
"description": "Allocated NVRAM KB",
"type": ["integer", "null"]
},
"l1_keepalives": {
"description": "Always up ethernet interface",
"type": ["boolean", "null"]
}
},
"additionalProperties": False,
@@ -168,10 +176,14 @@ IOU_OBJECT_SCHEMA = {
"nvram": {
"description": "Allocated NVRAM KB",
"type": "integer"
},
"l1_keepalives": {
"description": "Always up ethernet interface",
"type": "boolean"
}
},
"additionalProperties": False,
"required": ["name", "vm_id", "console", "project_id", "path", "serial_adapters", "ethernet_adapters", "ram", "nvram"]
"required": ["name", "vm_id", "console", "project_id", "path", "serial_adapters", "ethernet_adapters", "ram", "nvram", "l1_keepalives"]
}
IOU_NIO_SCHEMA = {