def load_config(self, config, commit=False, replace=False, comment=None): commands = ['configure terminal'] commands.extend(config) if commands[-1] == 'end': commands.pop() try: self.execute(commands) diff = self.execute(['show commit changes diff']) if commit: if replace: prompt = re.compile(r'\[no\]:\s$') commit = 'commit replace' if comment: commit += ' comment %s' % comment cmd = Command(commit, prompt=prompt, response='yes') self.execute([cmd, 'end']) else: commit = 'commit' if comment: commit += ' comment %s' % comment self.execute([commit, 'end']) else: self.execute(['abort']) except NetworkError: self.execute(['abort']) diff = None raise return diff[0]
def do_rollback(module, result): rollback = 'rollback %s' % module.params['rollback'] prompt = re.compile('\[confirm\]') cmd = Command(rollback, prompt=prompt, response='y', is_reboot=True, delay=1) try: module.cli(['configure', cmd]) except NetworkError: exc = get_exception() cmds = [str(c) for c in exc.kwargs.get('commands', list())] module.fail_json(msg=str(exc), commands=cmds)
def configure(self, commands, **kwargs): cmds = ['configure terminal'] cmdlist = list() for c in to_list(commands): cmd = Command(c, prompt=self.WARNING_PROMPTS_RE, response='yes') cmdlist.append(cmd) cmds.extend(cmdlist) cmds.append('end') responses = self.execute(cmds) responses.pop(0) return responses
def authorize(self, params, **kwargs): passwd = params['auth_pass'] self.run_commands( Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)) self.run_commands('terminal length 0')
def save_config(self): cmdlist = list() cmd = 'copy running-config startup-config' cmdlist.append( Command(cmd, prompt=self.WARNING_PROMPTS_RE, response='yes')) self.execute(cmdlist)
def authorize(self, params, **kwargs): passwd = params['auth_pass'] self.execute(Command('enable', prompt=NET_PASSWD_RE, response=passwd))