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

added juniper netconf schema

parent 160e67fe
Branches
Tags
No related merge requests found
# import os
from jnpr.junos import Device
# from inventory_provider import config
from lxml import etree
def load_config(hostname, ssh_params):
def _rpc(hostname, ssh):
dev = Device(
host=hostname,
user=ssh_params['username'],
ssh_private_key_file=ssh_params['private-key'])
user=ssh['username'],
ssh_private_key_file=ssh['private-key'])
dev.open()
return dev.rpc
def load_config(hostname, ssh_params):
# data = dev.rpc.get_config(options={'format': 'json'})
return dev.rpc.get_config()
return _rpc(hostname, ssh_params).get_config()
def load_interfaces(hostname, ssh_params):
......@@ -47,11 +49,3 @@ def load_interfaces(hostname, ssh_params):
# for i in data.xpath("//configuration/routing-instances/instance/interface"):
# print(i.xpath('./name/text()'))
# if __name__ == "__main__":
# with open("config.json") as f:
# params = config.load(f)
# for r in params['routers']:
# netconf = _load_netconf(r['hostname'], params['ssh'])
# with open(os.path.join(TEST_DATA_DIR, "%s-netconf.xml" % r['hostname']), 'w') as f:
# f.write(etree.tostring(netconf, encoding='unicode'))
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
import os
from lxml import etree
from inventory_provider import netconf
def load_config_schema(hostname, ssh_params):
return netconf._rpc(hostname, ssh_params).get_xnm_information(
type='xml-schema',
namespace='junos-configuration')
if __name__ == "__main__":
from inventory_provider import config
with open("config.json") as f:
params = config.load(f)
# for r in params['routers']:
# netconf = _load_netconf(r['hostname'], params['ssh'])
# with open(os.path.join(TEST_DATA_DIR, "%s-netconf.xml" % r['hostname']), 'w') as f:
# f.write(etree.tostring(netconf, encoding='unicode'))
# x = dev.rpc.get_software_information()
hostname = 'mx1.ams.nl.geant.net'
# hostname = params['routers'][0]['hostname']
OUTPUT_DIRNAME = os.path.dirname(__file__)
schema_doc = load_config_schema(hostname, params['ssh'])
with open(os.path.join(OUTPUT_DIRNAME, 'netconf-config-schema.xml'), 'w') as f:
f.write(etree.tostring(schema_doc, pretty_print=True).decode('utf-8'))
\ No newline at end of file
import os
from inventory_provider import netconf
from lxml import etree
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
class MockedJunosRpc(object):
def __init__(self, hostname):
filename = os.path.join(TEST_DATA_DIR, "%s-netconf.xml" % hostname)
self.config = etree.parse(filename)
def get_config(self):
return self.config
class MockedJunosDevice(object):
def __init__(self, **kwargs):
self.rpc = MockedJunosRpc(kwargs['host'])
def open(self):
pass
def test_nr1(mocker, data_config):
mocker.patch(
'inventory_provider.pyez_test.Device',
# 'inventory_provider.pyez_test.jnpr.junos.Device',
MockedJunosDevice)
import json
for r in data_config['routers']:
print(r['hostname'])
x = netconf.load_interfaces(r['hostname'], data_config['ssh'])
print(json.dumps(list(x), indent=4))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment