Skip to content
Snippets Groups Projects
Commit c3a71b48 authored by Robert Latta's avatar Robert Latta
Browse files

Merge branch 'feature/DBOARD3-386' into develop

parents 98d1d157 48d501c2
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment