mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 16:04:49 +00:00
topogen: allow daemon spec in vtysh_cmd
Allow commands to be run per-daemon basis. While here make daemon logging file configuration per-daemon.
This commit is contained in:
parent
d1c3108673
commit
f9b48d8b42
@ -620,7 +620,7 @@ class TopoRouter(TopoGear):
|
|||||||
if enabled == 0:
|
if enabled == 0:
|
||||||
continue
|
continue
|
||||||
self.vtysh_cmd('configure terminal\nlog file {}/{}-{}.log'.format(
|
self.vtysh_cmd('configure terminal\nlog file {}/{}-{}.log'.format(
|
||||||
self.logdir, self.name, daemon))
|
self.logdir, self.name, daemon), daemon=daemon)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ class TopoRouter(TopoGear):
|
|||||||
self.logger.debug('stopping')
|
self.logger.debug('stopping')
|
||||||
return self.tgen.net[self.name].stopRouter()
|
return self.tgen.net[self.name].stopRouter()
|
||||||
|
|
||||||
def vtysh_cmd(self, command, isjson=False):
|
def vtysh_cmd(self, command, isjson=False, daemon=None):
|
||||||
"""
|
"""
|
||||||
Runs the provided command string in the vty shell and returns a string
|
Runs the provided command string in the vty shell and returns a string
|
||||||
with the response.
|
with the response.
|
||||||
@ -642,9 +642,14 @@ class TopoRouter(TopoGear):
|
|||||||
"""
|
"""
|
||||||
# Detect multi line commands
|
# Detect multi line commands
|
||||||
if command.find('\n') != -1:
|
if command.find('\n') != -1:
|
||||||
return self.vtysh_multicmd(command)
|
return self.vtysh_multicmd(command, daemon=daemon)
|
||||||
|
|
||||||
|
dparam = ''
|
||||||
|
if daemon is not None:
|
||||||
|
dparam += '-d {}'.format(daemon)
|
||||||
|
|
||||||
|
vtysh_command = 'vtysh {} -c "{}" 2>/dev/null'.format(dparam, command)
|
||||||
|
|
||||||
vtysh_command = 'vtysh -c "{}" 2>/dev/null'.format(command)
|
|
||||||
output = self.run(vtysh_command)
|
output = self.run(vtysh_command)
|
||||||
self.logger.info('\nvtysh command => {}\nvtysh output <= {}'.format(
|
self.logger.info('\nvtysh command => {}\nvtysh output <= {}'.format(
|
||||||
command, output))
|
command, output))
|
||||||
@ -657,7 +662,7 @@ class TopoRouter(TopoGear):
|
|||||||
logger.warning('vtysh_cmd: failed to convert json output')
|
logger.warning('vtysh_cmd: failed to convert json output')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def vtysh_multicmd(self, commands, pretty_output=True):
|
def vtysh_multicmd(self, commands, pretty_output=True, daemon=None):
|
||||||
"""
|
"""
|
||||||
Runs the provided commands in the vty shell and return the result of
|
Runs the provided commands in the vty shell and return the result of
|
||||||
execution.
|
execution.
|
||||||
@ -669,11 +674,15 @@ class TopoRouter(TopoGear):
|
|||||||
# Prepare the temporary file that will hold the commands
|
# Prepare the temporary file that will hold the commands
|
||||||
fname = topotest.get_file(commands)
|
fname = topotest.get_file(commands)
|
||||||
|
|
||||||
|
dparam = ''
|
||||||
|
if daemon is not None:
|
||||||
|
dparam += '-d {}'.format(daemon)
|
||||||
|
|
||||||
# Run the commands and delete the temporary file
|
# Run the commands and delete the temporary file
|
||||||
if pretty_output:
|
if pretty_output:
|
||||||
vtysh_command = 'vtysh < {}'.format(fname)
|
vtysh_command = 'vtysh {} < {}'.format(dparam, fname)
|
||||||
else:
|
else:
|
||||||
vtysh_command = 'vtysh -f {}'.format(fname)
|
vtysh_command = 'vtysh {} -f {}'.format(dparam, fname)
|
||||||
|
|
||||||
res = self.run(vtysh_command)
|
res = self.run(vtysh_command)
|
||||||
os.unlink(fname)
|
os.unlink(fname)
|
||||||
|
Loading…
Reference in New Issue
Block a user