Loading validateInventory.py +22 −3 Original line number Diff line number Diff line Loading @@ -99,9 +99,28 @@ def check_port_inventory(xml_reply): return "SUCCESS" def check_carrier_inventory(xml_reply): tree = ET.fromstring(xml_reply) carrier = tree.findall(".//ns1:interface", namespaces={"ns0" :"urn:ietf:params:xml:ns:netconf:base:1.0","ns1": "urn:ietf:params:xml:ns:yang:ietf-interfaces"}) for iface in carrier: from lxml import etree ns = { 'if': 'urn:ietf:params:xml:ns:yang:ietf-interfaces', 'ianaift': 'urn:ietf:params:xml:ns:yang:iana-if-type', 'mw': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link' } tree = etree.fromstring(xml_reply.encode()) # Find all interface elements regardless of namespace interfaces = tree.xpath('.//*[local-name()="interface"]') carrier_ifaces = [] for iface in interfaces: types = iface.xpath('if:type', namespaces=ns) if types: t = types[0] if t.text and 'microwaveCarrierTermination' in t.text: carrier_ifaces.append(iface) if not carrier_ifaces: return "No carrier found" for iface in carrier_ifaces: carrier_id = iface.findall(".//ns1:carrier-id", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) tx_enabled = iface.findall(".//ns1:carrier-id", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) oper_status = iface.findall(".//ns1:tx-enabled", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) Loading Loading
validateInventory.py +22 −3 Original line number Diff line number Diff line Loading @@ -99,9 +99,28 @@ def check_port_inventory(xml_reply): return "SUCCESS" def check_carrier_inventory(xml_reply): tree = ET.fromstring(xml_reply) carrier = tree.findall(".//ns1:interface", namespaces={"ns0" :"urn:ietf:params:xml:ns:netconf:base:1.0","ns1": "urn:ietf:params:xml:ns:yang:ietf-interfaces"}) for iface in carrier: from lxml import etree ns = { 'if': 'urn:ietf:params:xml:ns:yang:ietf-interfaces', 'ianaift': 'urn:ietf:params:xml:ns:yang:iana-if-type', 'mw': 'urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link' } tree = etree.fromstring(xml_reply.encode()) # Find all interface elements regardless of namespace interfaces = tree.xpath('.//*[local-name()="interface"]') carrier_ifaces = [] for iface in interfaces: types = iface.xpath('if:type', namespaces=ns) if types: t = types[0] if t.text and 'microwaveCarrierTermination' in t.text: carrier_ifaces.append(iface) if not carrier_ifaces: return "No carrier found" for iface in carrier_ifaces: carrier_id = iface.findall(".//ns1:carrier-id", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) tx_enabled = iface.findall(".//ns1:carrier-id", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) oper_status = iface.findall(".//ns1:tx-enabled", namespaces={"ns1": "urn:ietf:params:xml:ns:yang:ietf-microwave-radio-link"}) Loading