mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix 'macro name' timeout (#44001)
* Fix 'macro name' timeout Added function to send macro to device using 'sendonly'. * Filter 'macro' from normal commands * Removed white space * Undefined variable 'cmd'
This commit is contained in:
parent
d89a1be011
commit
a767929456
2 changed files with 34 additions and 1 deletions
|
@ -321,6 +321,13 @@ def check_args(module, warnings):
|
|||
'single character')
|
||||
|
||||
|
||||
def edit_config_or_macro(connection, commands):
|
||||
if "macro name" in commands[0]:
|
||||
connection.edit_macro(candidate=commands)
|
||||
else:
|
||||
connection.edit_config(candidate=commands)
|
||||
|
||||
|
||||
def get_candidate_config(module):
|
||||
candidate = ''
|
||||
if module.params['src']:
|
||||
|
@ -457,7 +464,7 @@ def main():
|
|||
# them with the current running config
|
||||
if not module.check_mode:
|
||||
if commands:
|
||||
connection.edit_config(candidate=commands)
|
||||
edit_config_or_macro(connection, commands)
|
||||
if banner_diff:
|
||||
connection.edit_banner(candidate=json.dumps(banner_diff), multiline_delimiter=module.params['multiline_delimiter'])
|
||||
|
||||
|
|
|
@ -151,6 +151,32 @@ class Cliconf(CliconfBase):
|
|||
resp['response'] = results
|
||||
return resp
|
||||
|
||||
def edit_macro(self, candidate=None, commit=True, replace=None, comment=None):
|
||||
resp = {}
|
||||
operations = self.get_device_operations()
|
||||
self.check_edit_config_capabiltiy(operations, candidate, commit, replace, comment)
|
||||
|
||||
results = []
|
||||
requests = []
|
||||
if commit:
|
||||
commands = ''
|
||||
for line in candidate:
|
||||
if line != 'None':
|
||||
commands += (' ' + line + '\n')
|
||||
self.send_command('config terminal', sendonly=True)
|
||||
obj = {'command': commands, 'sendonly': True}
|
||||
results.append(self.send_command(**obj))
|
||||
requests.append(commands)
|
||||
|
||||
self.send_command('end', sendonly=True)
|
||||
time.sleep(0.1)
|
||||
results.append(self.send_command('\n'))
|
||||
requests.append('\n')
|
||||
|
||||
resp['request'] = requests
|
||||
resp['response'] = results
|
||||
return resp
|
||||
|
||||
def get(self, command=None, prompt=None, answer=None, sendonly=False, output=None):
|
||||
if not command:
|
||||
raise ValueError('must provide value of command to execute')
|
||||
|
|
Loading…
Reference in a new issue