Skip to content
Snippets Groups Projects
Commit 11accbec authored by Erik Reid's avatar Erik Reid
Browse files

working stripped-down skeleton schema

parent bc64d7c7
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,12 @@ from lxml import etree ...@@ -6,6 +6,12 @@ from lxml import etree
from inventory_provider import config from inventory_provider import config
SCHEMA_FILENAME = os.path.realpath(os.path.join(
os.path.dirname(__file__),
"data",
"juniper-netconf.xsd"
))
def _load_netconf(hostname, ssh_params): def _load_netconf(hostname, ssh_params):
dev = Device( dev = Device(
...@@ -28,17 +34,80 @@ def _load_netconf(hostname, ssh_params): ...@@ -28,17 +34,80 @@ def _load_netconf(hostname, ssh_params):
# print(i.xpath('./name/text()')) # print(i.xpath('./name/text()'))
# #
SCHEMA = """<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="generic-sequence">
<xs:sequence>
<xs:any processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:anyAttribute processContents="skip" />
</xs:complexType>
<xs:element name="configuration">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<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" />
<xs:element name="system" minOccurs="0" type="generic-sequence" />
<xs:element name="logical-systems" minOccurs="0" type="generic-sequence" />
<xs:element name="chassis" minOccurs="0" type="generic-sequence" />
<xs:element name="services" minOccurs="0" type="generic-sequence" />
<xs:element name="interfaces" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded">
<xs:element name="apply-groups" minOccurs="0" type="xs:string" />
<xs:element name="interface" minOccurs="1" type="generic-sequence" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="snmp" minOccurs="0" type="generic-sequence" />
<xs:element name="forwarding-options" minOccurs="0" type="generic-sequence" />
<xs:element name="routing-options" minOccurs="0" type="generic-sequence" />
<xs:element name="protocols" minOccurs="0" type="generic-sequence" />
<xs:element name="policy-options" minOccurs="0" type="generic-sequence" />
<xs:element name="class-of-service" minOccurs="0" type="generic-sequence" />
<xs:element name="firewall" minOccurs="0" type="generic-sequence" />
<xs:element name="routing-instances" minOccurs="0" type="generic-sequence" />
<xs:element name="bridge-domains" minOccurs="0" type="generic-sequence" />
</xs:choice>
</xs:sequence>
<xs:attribute name="changed-seconds" type="xs:string" />
<xs:attribute name="changed-localtime" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
"""
if __name__ == "__main__": if __name__ == "__main__":
TEST_DATA_DIR = os.path.dirname(__file__) TEST_DATA_DIR = os.path.dirname(__file__)
CONFIG_FILENAME = "config.json" CONFIG_FILENAME = "config.json"
SCHEMA_FILENAME = os.path.join(TEST_DATA_DIR, "juniper-netconf.xsd")
with open("config.json") as f: with open("config.json") as f:
params = config.load(f) params = config.load(f)
for r in params['routers']: for r in params['routers']:
netconf = _load_netconf(r['hostname'], params['ssh']) # netconf = _load_netconf(r['hostname'], params['ssh'])
# filename = os.path.join(
# TEST_DATA_DIR,
# "%s-netconf.xml" % r['hostname'])
# with open(filename, 'w') as f:
# f.write(etree.tostring(netconf, encoding='unicode'))
filename = os.path.join( filename = os.path.join(
TEST_DATA_DIR, TEST_DATA_DIR,
"%s-netconf.xml" % r['hostname']) "%s-netconf.xml" % r['hostname'])
with open(filename, 'w') as f:
f.write(etree.tostring(netconf, encoding='unicode')) # schema_doc = etree.parse(SCHEMA_FILENAME)
schema_doc = etree.XML(SCHEMA.encode('utf-8'))
schema = etree.XMLSchema(schema_doc)
parser = etree.XMLParser(schema=schema)
print(filename)
etree.parse(filename, parser)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment