Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'macro name' timeout #44001

Merged
merged 4 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ansible/modules/network/ios/ios_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,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']:
Expand Down Expand Up @@ -447,7 +454,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'])

Expand Down
26 changes: 26 additions & 0 deletions lib/ansible/plugins/cliconf/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ def edit_config(self, candidate=None, commit=True, replace=None, comment=None):
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')
Expand Down