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 authorize(self, params, **kwargs): passwd = params['auth_pass'] if passwd: self.execute( Command('enable', prompt=self.NET_PASSWD_RE, response=passwd)) else: self.execute('enable')
def authorize(self, params, **kwargs): passwd = params['auth_pass'] errors = self.shell.errors # Disable errors (if already in enable mode) self.shell.errors = [] cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd) self.execute([cmd, 'no terminal pager']) # Reapply error handling self.shell.errors = errors
def backup_config(module): cmd = 'copy running-config flash:/ansible-rollback' cmd = Command(cmd, prompt=re.compile('\? $'), response='\n') module.cli(cmd)
def authorize(self, params, **kwargs): passwd = params['auth_pass'] cmd = Command('enable', prompt=self.NET_PASSWD_RE, response=passwd) self.execute([cmd, 'no terminal pager'])
def authorize(self, params, **kwargs): passwd = params['auth_pass'] self.run_commands( Command('enable', prompt=self.NET_PASSWD_RE, response=passwd))