def _parse_response(xmlns, netconf_namespace, response): """parse response from server with check to rpc-error""" xml_node = etree.XML(response) xml_dict = {} utils.generate_dict_node(xml_dict, xml_node, xmlns) reply = None if 'rpc-reply' in xml_dict: reply = xml_dict['rpc-reply'] elif (netconf_namespace + '@rpc-reply') in xml_dict: # default namespace can't be not netconf 1.0 reply = xml_dict[netconf_namespace + '@rpc-reply'] if not reply: raise cfy_exc.NonRecoverableError("unexpected reply struct") # error check error = None # we can have empty error, so we need additional flag for that have_error = False if 'rpc-error' in reply: error = reply['rpc-error'] have_error = True elif (netconf_namespace + '@rpc-error') in reply: # default namespace can't be not netconf 1.0 error = reply[netconf_namespace + '@rpc-error'] have_error = True if have_error: raise cfy_exc.NonRecoverableError("We have error in reply" + str(error)) return reply
def _parse_response(xmlns, netconf_namespace, response): """parse response from server with check to rpc-error""" xml_node = etree.XML(response) xml_dict = {} utils.generate_dict_node( xml_dict, xml_node, xmlns ) reply = None if 'rpc-reply' in xml_dict: reply = xml_dict['rpc-reply'] elif (netconf_namespace + '@rpc-reply') in xml_dict: # default namespace can't be not netconf 1.0 reply = xml_dict[netconf_namespace + '@rpc-reply'] if not reply: raise cfy_exc.NonRecoverableError( "unexpected reply struct" ) # error check error = None # we can have empty error, so we need additional flag for that have_error = False if 'rpc-error' in reply: error = reply['rpc-error'] have_error = True elif (netconf_namespace + '@rpc-error') in reply: # default namespace can't be not netconf 1.0 error = reply[netconf_namespace + '@rpc-error'] have_error = True if have_error: raise cfy_exc.NonRecoverableError( "We have error in reply" + str(error) ) return reply
def _server_support_1_1(xmlns, netconf_namespace, response): xml_node = etree.XML(response) xpath = ("/%s:hello/%s:capabilities/%s:capability" % (netconf_namespace, netconf_namespace, netconf_namespace)) capabilities = xml_node.xpath(xpath, namespaces=xmlns) for node in capabilities: xml_dict = {} utils.generate_dict_node(xml_dict, node, xmlns) value = xml_dict.get(netconf_namespace + '@capability') if value == netconf_connection.NETCONF_1_1_CAPABILITY: return True return False
def _server_support_1_1(xmlns, netconf_namespace, response): xml_node = etree.XML(response) xpath = ( "/%s:hello/%s:capabilities/%s:capability" % ( netconf_namespace, netconf_namespace, netconf_namespace ) ) capabilities = xml_node.xpath(xpath, namespaces=xmlns) for node in capabilities: xml_dict = {} utils.generate_dict_node( xml_dict, node, xmlns ) value = xml_dict.get(netconf_namespace + '@capability') if value == netconf_connection.NETCONF_1_1_CAPABILITY: return True return False