diff --git a/inventory_provider/juniper.py b/inventory_provider/juniper.py index 723ab2bc40936cc97da6bbe9b1649bcaf55302c7..5bf4edff6a67d0407dfaddd27c36d90d729d890d 100644 --- a/inventory_provider/juniper.py +++ b/inventory_provider/juniper.py @@ -43,6 +43,8 @@ CONFIG_SCHEMA = """<?xml version="1.1" encoding="UTF-8" ?> <xs:complexType> <xs:sequence> <xs:choice minOccurs="1" maxOccurs="unbounded"> + <xs:element name="transfer-on-commit" minOccurs="0" type="xs:string" /> + <xs:element name="archive-sites" minOccurs="0" type="generic-sequence" /> <xs:element name="version" minOccurs="0" type="xs:string" /> <xs:element name="groups" minOccurs="0" type="generic-sequence" /> <xs:element name="apply-groups" minOccurs="0" type="xs:string" /> @@ -155,20 +157,22 @@ def validate_netconf_config(config_doc): _validate(unit_schema, u) -def load_config(hostname, ssh_params): +def load_config(hostname, ssh_params, validate=True): """ - loads netconf data from the router, validates and + loads netconf data from the router, validates (by default) and returns as an lxml etree doc :param hostname: router hostname :param ssh_params: 'ssh' config element(cf. config.py:CONFIG_SCHEMA) + :param validate: whether or not to validate netconf data (default True) :return: :raises: NetconfHandlingError from validate_netconf_config """ logger = logging.getLogger(__name__) logger.info("capturing netconf data for '%s'" % hostname) config = _rpc(hostname, ssh_params).get_config() - validate_netconf_config(config) + if validate: + validate_netconf_config(config) return config diff --git a/inventory_provider/routes/testing.py b/inventory_provider/routes/testing.py index 81a43cf0db6f0b0ec48f1c0266f6479f6f8ea0fc..c9bdc7a1d2f3ca9e4bad3bea88e47a8489e47ce4 100644 --- a/inventory_provider/routes/testing.py +++ b/inventory_provider/routes/testing.py @@ -189,6 +189,18 @@ def snmp_ids(hostname): return jsonify(ifc_data) +@routes.route("netconf/<hostname>", methods=['GET', 'POST']) +def get_netconf(hostname): + config = current_app.config["INVENTORY_PROVIDER_CONFIG"] + try: + netconf_doc = juniper.load_config( + hostname, config["ssh"], validate=False) + msg = etree.tostring(netconf_doc, encoding='unicode') + except (ConnectionError, juniper.NetconfHandlingError) as e: + msg = f'error loading netconf data from {hostname}\n{e}' + return msg + + @routes.route("latchdb", methods=['GET', 'POST']) def latch_db(): config = current_app.config["INVENTORY_PROVIDER_CONFIG"]