本文整理汇总了Python中netmiko.ConnectHandler.receive_data_generator方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectHandler.receive_data_generator方法的具体用法?Python ConnectHandler.receive_data_generator怎么用?Python ConnectHandler.receive_data_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netmiko.ConnectHandler
的用法示例。
在下文中一共展示了ConnectHandler.receive_data_generator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IOSXR
# 需要导入模块: from netmiko import ConnectHandler [as 别名]
# 或者: from netmiko.ConnectHandler import receive_data_generator [as 别名]
#.........这里部分代码省略.........
# BUT we are not able to assign unique IDs and identify the request-reply map
# so will throw an error that does not help too much :(
raise XMLCLIError('XML agent cannot process parallel requests!', self)
if not output.strip().endswith('XML>'):
if '0x44318c06' in output or (self._cli_prompt and expect_string != self._cli_prompt and \
(output.startswith(self._cli_prompt) or output.endswith(self._cli_prompt))):
# sometimes the device throws a stupid error like:
# ERROR: 0x44318c06 'XML-TTY' detected the 'warning' condition
# 'A Light Weight Messaging library communication function returned an error': No such device or address
# and the XML agent connection is closed, but the SSH connection is fortunately maintained
# OR sometimes, the device simply exits from the XML mode without any clue
# In both cases, we need to re-enter in XML mode...
# so, whenever the CLI promt is detected, will re-enter in XML mode
# unless the expected string is the prompt
self._unlock_xml_agent()
self._enter_xml_mode()
# however, the command could not be executed properly, so we need to raise the XMLCLIError exception
raise XMLCLIError('Could not properly execute the command. Re-entering XML mode...', self)
if not output.strip(): # empty output, means that the device did not start delivering the output
# but for sure is still in XML mode as netmiko did not throw error
if not self._timeout_exceeded(start=start):
return self._send_command(command, receive=True, start=start) # let's try receiving more
raise XMLCLIError(output.strip(), self)
self._unlock_xml_agent()
return str(output.replace('XML>', '').strip())
def _netmiko_recv(self):
output = ''
for tmp_output in self.device.receive_data_generator():
output += tmp_output
return output
# previous module function __execute_rpc__
def _execute_rpc(self, command_xml, delay_factor=.1):
xml_rpc_command = '<?xml version="1.0" encoding="UTF-8"?><Request MajorVersion="1" MinorVersion="0">' \
+ command_xml + '</Request>'
response = self._send_command(xml_rpc_command, delay_factor=delay_factor)
try:
root = ET.fromstring(response)
except ET.XMLSyntaxError as xml_err:
if 'IteratorID="' in response:
raise IteratorIDError(self._ITERATOR_ID_ERROR_MSG, self)
raise InvalidXMLResponse('Unable to process the XML Response from the device!', self)
if 'IteratorID' in root.attrib:
raise IteratorIDError(self._ITERATOR_ID_ERROR_MSG, self)
childs = [x.tag for x in list(root)]
result_summary = root.find('ResultSummary')
if result_summary is not None and int(result_summary.get('ErrorCount', 0)) > 0:
if 'CLI' in childs:
error_msg = root.find('CLI').get('ErrorMsg') or ''
elif 'Commit' in childs:
error_msg = root.find('Commit').get('ErrorMsg') or ''