def deleteUser(self, username=''): data = {"status": False, "content": "", "errLog": ""} try: if not username: raise ForwardError("Please specify a username") checkPermission = self._configMode() if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.cleanBuffer() self.shell.send("no username {username}\n".format( username=username)) #delete username while not re.search(self.prompt, data['content'].split('\n')[-1]): data['content'] += self.shell.recv(1024) if re.search('error|invalid', data['content'], flags=re.IGNORECASE): raise ForwardError(data['content']) else: # deleted username data = self._commit() data['status'] = True else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['status'] = False data['errLog'] = str(e)
def deleteUser(self,username=''): data = { "status":False, "content":"", "errLog":"" } try: if not username: raise ForwardError('Please specify a username') checkPermission = self._configMode() # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.write('delete system login user {username}\n'.format(username = username)) # adduser i = self.channel.expect([r"%s"%self.prompt],timeout = self.timeout) result = i[-1] if re.search('error|invalid',result,flags = re.IGNORECASE): raise ForwardError(result) # command failure else: data = self._commit() self._exitConfigMode() # exit config terminal mode. else: raise ForwardError('Has yet to enter configuration mode') except ForwardError,e: data['errLog'] = str(e) data['status'] = False
def addUser(self, username='', password='', addCommand='', admin=False): data = {"status": False, "content": "", "errLog": ""} try: if not addCommand: raise ForwardError("Please specify the add user's command") if not username or not password: raise ForwardError( 'Please specify the username = your-username and password = your-password' ) # Specify a user name and password parameters here. checkPermission = self._configMode( ) # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.cleanBuffer() self.shell.send( addCommand.format(username=username, password=password)) # adduser while not re.search(self.prompt, data['content'].split('\n')[-1]): data['content'] += self.shell.recv(1024) if re.search('error|invalid', data['content'], flags=re.IGNORECASE): data['content'] = '' raise ForwardError(data['content']) else: # set password is successed. data = self._commit() else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['status'] = False data['errLog'] = str(e)
def deleteBindIPAndBandwidth(self): njInfo = {"content": "", "errLog": "", "status": False} try: ipIsTrue = self.ipStatus() if ipIsTrue["status"]: data = self._configMode() if data["status"]: self.shell.execute( """delete firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip}""" .format(ip=self.ip)) self.shell.execute( """delete firewall filter Policer-For-Each-Address term {term} from address {ip}/32""" .format(ip=self.ip, term=self.termNumber)) data = self._commit() # commit if data["status"]: # commit succcessed data = self._exitConfigMode() if data["status"]: njInfo["status"] = True else: raise ForwardError(data["errLog"]) # failed. else: raise ForwardError(data["errLog"]) # failed. else: raise ForwardError( data["errLog"]) # switch to config mode failed. else: raise ForwardError("The specify ip is not valid.") except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def modifyIPAndBandwidth(self): njInfo = {"content": "", "errLog": "", "status": False} try: data = self.shell._configMode() if data["status"]: # switch to config mode successed self.shell.execute( """set firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} then prefix-action Action-Name-{bandwidth}M""" .format(bandwidth=self.bandwidth, ip=self.ip)) data = self._commit() # commit if data["status"]: data = self._exitConfigMode() if not data["status"]: # exit failed raise ForwardError(data["errLog"]) else: # Check whether the binding is successful data = self.ipAndBandwidthExist() if data["status"]: # modify successed njInfo["status"] = True else: raise ForwardError("Modify the binding failed") else: # commit failed raise ForwardError(data["errLog"]) else: raise ForwardError(data["errLog"]) except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def addUser(self, username='', password='', admin=False): if admin: command = """user administrator {username} local {password} authorized-table admin\n""".format( username=username, password=password) else: command = """user administrator {username} local {password} authorized-table admsee\n""".format( username=username, password=password) data = {"status": False, "content": "", "errLog": ""} try: if not username or not password: raise ForwardError( 'Please specify the username = your-username and password = your-password' ) # Spcify a user name and password parameters here. checkPermission = self._configMode( ) # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.write(command) # adduser data = self._recv(self.prompt) #recv result if not data['status']: raise ForwardError(data['errLog']) # break result = data['content'] if re.search('error|invalid|assword', result, flags=re.IGNORECASE): raise ForwardError(result) # command failure # set password is successed. data = self._commit() else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['errLog'] = str(e) data['status'] = False
def ipAndBandwidthExist(self): njInfo = {"content": "", "errLog": "", "status": False} try: data = self.shell.execute( self.checkIPAndBandwidthCommand) # check it if data["status"]: if re.search( """prefix\-action Action\-Name\-%sM""" % self.bandwidth, data["content"]): # exist bind # get term num # check again data = self.shell.execute( """show configuration firewall filter Policer-For-Each-Address term {term} | match {ip}/32""" .format(term=self.termNumber, ip=self.ip)) if data["status"]: if re.search("%s/32 except" % (self.ip), data["content"]): # success njInfo["status"] = True else: raise ForwardError("not exist bind") else: raise ForwardError(data["errLog"]) njInfo["status"] = True else: raise ForwardError("not exist bind") # not exist bind else: raise FowardError(data["errLog"]) except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def deleteUser(self,username=''): data = { "status":False, "content":"", "errLog":"" } # user leve default 1 try: if not username: raise ForwardError('Please specify a username') checkPermission = self._configMode() # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.cleanBuffer() self.shell.send('undo local-user {username}\n'.format(username = username)) while True: if ( re.search(self.prompt,data['content'].split('\n')[-1])) and ( re.search('undo local-user[\s\S]+%s'%self.prompt,data['content'])): break else: data['content'] += self.shell.recv(1024) if re.search('error|invalid',data['content'],flags = re.IGNORECASE): raise ForwardError(data['content']) data = self._commit() else: raise ForwardError('Has yet to enter configuration mode') except ForwardError,e: data['status'] = False data['errLog'] = str(e)
def changePassword(self, username='', password='', userLevel=1): data = {'status': False, 'content': '', 'errLog': ''} try: if not username or not password: raise ForwardError( 'Please specify the username = your-username and password = your-password' ) # Specify a user name and password parameters here. checkPermission = self._configMode( ) # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.send( """username {username} password 0 {password}\n""".format( username=username, password=password, userLevel=userLevel)) _result = self._recv(self.prompt) _tmp = re.search( """This command can be used by user "admin" only""", _result['content']) if _tmp: raise ForwardError(_tmp.group()) elif not _result['status']: raise ForwardError(_result['errLog']) if _result['status']: data = self._commit() else: data = _result else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['errLog'] = str(e) data['status'] = False
def deleteUser(self, username=''): data = {"status": False, "content": "", "errLog": ""} try: if not username: raise ForwardError('Please specify a username') checkPermission = self._configMode( ) # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.write( """no user administrator {username}\n""".format( username=username)) # deleteUser data = self._recv(self.prompt) #recv result if not data['status']: raise ForwardError(data['errLog']) # break result = data['content'] if re.search('error|invalid|assword', result, flags=re.IGNORECASE): raise ForwardError(result) # command failure # delete user is successed. data = self._commit() else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['errLog'] = str(e) data['status'] = False
def changePassword(self,username = '',password = '',userLevel = 1): data = { "status":False, "content":"", "errLog":"" } # user leve default 1 try: if not username or not password: raise ForwardError('Please specify the username = your-username and password = your-password') # Specify a user name and password parameters here. checkPermission = self._configMode() # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.shell.send('local-user {username} password cipher {password}\n'.format(username = username,password = password)) while True: if ( re.search(self.prompt,data['content'].split('\n')[-1])) and ( re.search('local-user .* password cipher[\s\S]+%s'%self.prompt,data['content'])): break else: data['content'] += self.shell.recv(1024) data = self._commit() else: raise ForwardError('Has yet to enter configuration mode') except ForwardError,e: data['status'] = False data['errLog'] = str(e)
def _deleteConfig(self, modeCommand="", deleteName=""): """ - param modeCommand: enter config firewall mode's command - deleteName: delete any-name """ njInfo = { "status": False, "content": "", "errLog": "", } try: mode = self._configFirewallMode( command=modeCommand) # enter config firewall mode if not mode["status"]: raise ForwardError(mode["errLog"]) data = self.execute( "delete {deleteNme}".format(deleteName=deleteName)) if not data["status"]: raise ForwardError(data["errLog"]) exitMode = self._exitConfigMode() if not exitMode[ "errLog"]: # exit config mode, go to the privileged mode raise Forward(exitMode['errLog']) njInfo["status"] = True # successed except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def createAddressName(self, addressName='', interface='', ip=''): """ - param addressName: addressName - param interface: interface - param ip: First of all, a range to determine whether the IP parameters, if it is a range of IP, execute the first way, otherwise the second execution """ njInfo = { "status": False, "content": "", "errLog": "", } try: if len(addressName) == 0 or len(interface) == 0 or len(ip) == 0: raise ForwardError('Must specify all effective parameters') mode = self._configFirewallMode(command="config firewall address") if not mode['status']: raise ForwardError(mode['errLog']) #self.shell.execute("edit {addressName}".format(addressName = addressName)) editMode = self._editMode(addressName) # enter edit mode if not editMode["status"]: raise ForwardError(editMode['errLog']) # check ip type if re.search('\-', interface): # first method # ip range # start ip startIP = ip.split('-')[0] endIP = ip.split('-')[1] self.execute("set associated-interface {interface}".format( interface=interface)) self.execute("set type iprange") self.execute("set start-ip {startIP}".format(startIP=startIP)) self.execute("set end-ip {endIP}".format(startIP=endIP)) elif re.search('/', interface): # second method # a ip self.execute("set associated-interface {interface}".format( interface=interfacde)) self.execute("set subnet {ip}") exitMode = self._exitConfigMode() if not exitMode[ "status"]: #exit config mode, go to the privileged mode raise Forward(editMode['errLog']) njInfo["status"] = True # successed except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def getUser(self, command="show running-config | in username"): data = {"status": False, "content": "", "errLog": ""} try: userList = [] # [{"username":"******","secret":5},{}....] # execute query command info = self.execute(command) if not info["status"]: raise ForwardError("Error:get user list failed: %s" % info["errLog"]) # process data result = info["content"] for line in result.split('\n'): # Each line index = 0 segments = line.split( ) # ['username' , 'test-user' , 'secret', '5','$.........'] for segment in segments: if index <= 1: index += 1 # Check after second fields username my-username secret/password ..... continue else: if segment == "secret" or segment == "password": userData = { "username": segments[1], "secret": segments[index + 1] } # get secret level userList.append(userData) break index += 1 data["content"] = userList data["status"] = True except ForwardError, e: data['status'] = False data['errLog'] = str(e)
def _commit(self): self.cleanBuffer() self.saveCommand = 'save' self.exitCommand = 'return' data = { "status":False, "content":"", "errLog":"" } try: if self.isConfigMode: self._exitConfigMode(cmd = self.exitCommand) self.shell.send('%s\n' % (self.saveCommand)) # save setup to system i = 1 while True: if re.search("continue\?",data['content'].split('\n')[-1]): #In interactive prompt self.shell.send('y\n') while not re.search(self.prompt,data['content'].split('\n')[-1]): data['content'] += self.shell.recv(1024) if re.search('successfully',data['content'],flags = re.IGNORECASE): data['status'] = True break else: data['content'] += self.shell.recv(1024) i += 1 else: raise ForwardError('Error: The current state is not configuration mode') except ForwardError,e: data['errLog'] = str(e) data['status'] = False
def _editMode(self, name=""): njInfo = { "status": False, "content": "", "errLog": "", } self.send("edit {name}\n".format(name=name)) #execute edit command buff = '' while not re.search( self.basePrompt, buff.split('\n')[-1] ): # When after switching mode, the prompt will change, it should be based on basePrompt to check and at last line try: try: buff += self.shell.recv(1024) except: raise ForwardError('Receive timeout [%s]' % (buff)) self.getPrompt() # renew get host prompt njInfo["status"] = True self.isConfigMode = True # successed except Exception, e: njInfo["errLog"] = str(e) njInfo["status"] = False break
def _configFirewallMode(self, command=""): """ enter config firewall mode """ njInfo = { "status": False, "content": "", "errLog": "", } self.shell.send('{command}\n'.format(command=command)) buff = '' self.isConfigMode = False while not re.search( self.basePrompt, buff.split('\n')[-1] ): # When after switching mode, the prompt will change, it should be based on basePrompt to check and at last line try: try: buff += self.shell.recv(1024) except: raise ForwardError('Receive timeout [%s]' % (buff)) self.getPrompt() # renew get host prompt njInfo["status"] = True self.isConfigMode = True # successed except Exception, e: njInfo["errLog"] = str(e) njInfo["status"] = False break
def bindIPAndBandwidth(self): njInfo = {"content": "", "errLog": "", "status": False} try: data = self._configMode() if data["status"]: # switch to config mode successed self.shell.execute( """set firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} from address {ip}/32""" .format(ip=self.ip)) self.shell.execute( """set firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} then forwarding-class queue_2""" .format(ip=slef.ip)) self.shell.execute( """set firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} then accept""" .format(ip=self.ip)) self.shell.execute( """set firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} then prefix-action Action-Name-{bandwidth}M""" .format(bandwidth=self.bandwidth, ip=self.ip)) self.shell.execute( """set firewall filter Policer-For-Each-Address term {term} from address {ip}/32 except""" .format(ip=self.ip, term=self.termNumber)) self.shell.execute( """insert firewall filter Policer-For-Each-Address term Filter-Term-Name-{ip} before term {term}""" .format(term=self.termNumber, ip=self.ip)) # commit data = self._commit() if data["status"]: # commit success data = self._exitConfigMode() if data["status"]: data = self.ipAndBandwidthExist() # check it if data["status"]: njInfo["status"] = True # bind successed else: raise ForwardError( "bind ip and bandwidth failed,Error:", data["errLog"]) else: raise ForwardError(data["errLog"]) else: raise ForwardError(data["errLog"]) else: raise ForwardError(data["errLog"]) except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def addUser(self,username = '',password = '',admin=False): if admin: command="set system login user {username} class read-only\n".format(username=username) else: command="set system login user {username} class ABC\n".format(username=username) data = { "status":False, "content":"", "errLog":"" } try: if not username or not password: raise ForwardError('Please specify the username = your-username and password = your-password') # Specify a user name and password parameters here. checkPermission = self._configMode() # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.write(command) # adduser data = self._recv(self.prompt) #recv result if not data['status']: raise ForwardError(data['errLog']) # break self.channel.write('set system login user {username} authentication plain-text-password\n'.format(username = username)) # execute useradd command i = self.channel.expect([r"New password:"******"%s"%self.prompt],timeout = self.timeout) result = i[-1] if re.search('error|invalid',result,flags = re.IGNORECASE): raise ForwardError(result) # command failure self.channel.write("{password}\n".format(password = password)) # Enter password i = self.channel.expect([r"Retype new password:"******"%s"%self.prompt],timeout = self.timeout) # check password if i[0] == 0: # repassword self.channel.write("{password}\n".format(password = password)) i = self.channel.expect([r"%s"%self.prompt],timeout = self.timeout) # check password if i[0] == 0: result = i[-1] if re.search('error|invalid',result,flags = re.IGNORECASE): raise ForwardError(result) else: # set password is successed. data = self._commit() self._exitConfigMode() # exit config terminal mode. elif i[0] == -1: raise ForwardError('Error: receive timeout') elif i[0] == 1: # password wrong raise ForwardError(i[-1]) elif i[0] == -1: # timeout raise ForwardError('Error: receive timeout') else: raise ForwardError('Has yet to enter configuration mode') except ForwardError,e: data['errLog'] = str(e) data['status'] = False
def privilegeMode(self, secondPassword='', deviceType='cisco'): if len(secondPassword) == 0: return self.njInfo self.njInfo['content'] = '' # Clear the previous content self.cleanBuffer() deviceType = deviceType.lower() if deviceType == 'huawei': self.privilegeModeCommand = 'super' else: self.privilegeModeCommand = 'enable' self.channel.send('%s\n' % (self.privilegeModeCommand)) try: i = self.channel.expect( [r"assword", r"%s" % self.basePrompt, pexpect.TIMEOUT], timeout=self.timeout) if i == 0: # need secondPassword self.channel.send('%s\n' % secondPassword) tmpI = self.channel.expect( [r"assword", r"%s" % self.basePrompt, pexpect.TIMEOUT], timeout=self.timeout) if tmpI == 0: raise ForwardError('secondPassword wrong.') elif tmpI == 1: # Switch mode succeed pass else: raise ForwardError("Switch mode failed, it was timed out.") elif i == 1: # switch mode's command incorrect result = self.channel.before if re.search('%|Invalid|\^', result): raise ForwardError('Privileged mode command incorrect') else: raise ForwardError( "Switch mode failed, received prompt it was timed out.") self.getPrompt() self.njInfo['status'] = True except ForwardError, e: self.logout() #Switch mode failed,then logout device self.njInfo['status'] = False self.njInfo['errLog'] = str(e)
def cleanBuffer(self): if self.shell.recv_ready(): self.shell.recv(4096) self.shell.send('\r\n') buff = '' while not re.search(self.basePrompt,buff.split('\n')[-1]): # When after switching mode, the prompt will change, it should be based on basePromptto check and at last line try: buff += self.shell.recv(1024) except: raise ForwardError('Receive timeout [%s]' %(buff))
def _commit(self): data = {'status': False, 'content': '', 'errLog': ''} saveCommand = "copy running-config startup-config" try: if self.isConfigMode: self._exitConfigMode() self.channel.send('%s\n' % (saveCommand)) # save setup to system data = self._recv(self.prompt) if re.search('user "admin" only', data['content']): raise ForwardError(data['content']) else: data['status'] = True else: raise ForwardError( 'Error: The current state is not configuration mode') except ForwardError, e: data['errLog'] = str(e) data['status'] = False
def _recv(self, _prompt): data = {"status": False, "content": "", "errLog": ""} i = self.channel.expect([r"%s" % _prompt], timeout=self.timeout) try: if i[0] == -1: raise ForwardError('Error: receive timeout') data['status'] = True data['content'] = i[-1] except ForwardError, e: data['errLog'] = str(e)
def createAddressName(self, addressName='', description='', netIP=[], rangeIP=[], hostIP=[]): """ - param addressName: Must provide - param description: Can be empty - param netIP: netIP and rangeIP and hostIP, must choose one of them, or choose all. """ njInfo = { "status": False, "content": "", "errLog": "", } try: mode = self._configMode() #enter config mode if not mode["status"]: raise ForwardError(mode["errLog"]) if type(netIP) != type([]) or type(rangeIP) != type( []) or type(hostIP) != type([]): raise ForwardError("Specified argument must be a list") if len(addressName) == 0: raise ForwardError("Must be specified addressName") # create address name data = self.execute( "address {addressName}".format(addressName=addressName)) if not data["status"]: raise ForwardError("create address-name failed:%s" % data["errLog"]) # create description if len(description) != 0: data = self.execute("description {description}".format( description=description)) if not data["status"]: raise ForwardError( "create address-description failed: %s" % data["errLog"]) njInfo["status"] = True except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def bindBandwidth(self): njInfo = {"content": "", "errLog": "", "status": False} try: ipIsTrue = self.ipStatus() if ipIsTrue["status"]: # ip is invalid if self.bandwidthConfigExist()["status"]: # bandwidth config is exist pass else: # bandwidth config is not exist,then create it data = self.createBandwidth() if data["status"]: # create bandwidth is successed # check ip and bandwidth is not bind data = self.ipAndBandwidthExist() if data["status"]: # Have binding, should modify it data = self.modifyIPAndBandwidth() if data["status"]: # successed njInfo["status"] = True else: raise ForwardError(data["errLog"]) else: # Have not binding, chould create it data = self.bindIPAndBandwidth() if data["status"]: # successed njInfo["status"] = True else: raise ForwardError(data["errLog"]) else: # failed raise ForwardError(data["errLog"]) else: # ip is not valid raise ForwardError(ipIsTrue["errLog"]) except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def deleteFirewallPolicy(self, id=''): njInfo = { "status": False, "content": "", "errLog": "", } try: if len(id) == 0: raise ForwardError("Must be specifyied ID") mode = self._configMode() #enter config mode if not mode["status"]: raise ForwardError(mode["errLog"]) # delete firewall policy data = self.execute("no policy {id}".format(id=id)) if not data["status"]: raise ForwardError("delete firewall policy failed: %s" % data["errLog"]) njInfo["status"] = True except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def deleteUser(self, username=''): data = {'status': False, 'content': '', 'errLog': ''} try: if not username: raise ForwardError('Please specify a username') checkPermission = self._configMode( ) # swith to config terminal mode. if not checkPermission['status']: raise ForwardError(checkPermission['errLog']) if self.isConfigMode: # check terminal status self.channel.send( """no username {username}\n""".format(username=username)) _result = self._recv(self.prompt) _tmp = re.search( """This command can be used by user "admin" only""", _result['content']) if _tmp: raise ForwardError(_tmp.group()) elif not _result['status']: raise ForwardError(_result['errLog']) if re.search('error|invalid', data['content'], flags=re.IGNORECASE): raise ForwardError(data['content']) if _result['status']: data = self._commit() else: data = _result else: raise ForwardError('Has yet to enter configuration mode') except ForwardError, e: data['errLog'] = str(e) data['status'] = False
def deleteAddressName(self, addressName=''): njInfo = { "status": False, "content": "", "errLog": "", } try: if len(addressName) == 0: raise ForwardError("Must be specified addressName") mode = self._configMode() #enter config mode if not mode["status"]: raise ForwardError(mode["errLog"]) # execute command data = self.execute( "no address {addressName}".format(addressName=addressName)) if not data["status"]: raise ForwardError("delete address-name failed: %s" % data["errLog"]) njInfo["status"] = True except Exception, e: njInfo["status"] = False njInfo["errLog"] = str(e)
def _exitConfigMode(self): data = {"status": False, "content": "", "errLog": ""} try: if self.isConfigMode: # Check current status self.channel.write("end\n") data = self._recv(self.basePrompt) if data['status']: self.isConfigMode = False else: raise ForwardError( 'Error: The current state is not configuration mode') except ForwardError, e: data['errLog'] = str(e)
def _exitConfigMode(self): exitCommand = "end" data = {'status': False, 'content': '', 'errLog': ''} try: if self.isConfigMode: # Check current status self.channel.send("%s\n" % (cmd)) data = self._recv(self.basePrompt) if data['status']: self.isConfigMode = False else: raise ForwardError( 'Error: The current state is not configuration mode') except ForwardError, e: data['errLog'] = str(e)