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

nokia processing placeholders

parent 915a2428
No related branches found
No related tags found
No related merge requests found
...@@ -3,13 +3,14 @@ from datetime import datetime ...@@ -3,13 +3,14 @@ from datetime import datetime
from functools import partial from functools import partial
import json import json
import socket import socket
from typing import List
import click import click
import jsonschema import jsonschema
from lxml import etree from lxml import etree
from brian_polling_manager.interface_stats import config, brian, errors from brian_polling_manager.interface_stats import config, brian, errors
from brian_polling_manager.interface_stats.vendors import juniper from brian_polling_manager.interface_stats.vendors import juniper, nokia
from brian_polling_manager import influx, inventory from brian_polling_manager import influx, inventory
...@@ -101,12 +102,14 @@ def _validate_config(_unused_ctx, _unused_param, file): ...@@ -101,12 +102,14 @@ def _validate_config(_unused_ctx, _unused_param, file):
raise click.BadParameter(e) raise click.BadParameter(e)
def _validate_hostname(_unused_ctx, _unused_param, hostname): def _validate_hostname(_unused_ctx, _unused_param, hostname_or_names):
try: hostnames = hostname_or_names if isinstance(hostname_or_names, (list, tuple)) else [hostname_or_names]
socket.gethostbyname(hostname) for _h in hostnames:
except socket.error: try:
raise click.BadParameter(f'{hostname} is not resolveable') socket.gethostbyname(_h)
return hostname except socket.error:
raise click.BadParameter(f'{_h} is not resolveable')
return hostname_or_names
def _brian_points(router_fqdn, netconf_doc, timestamp, measurement_name): def _brian_points(router_fqdn, netconf_doc, timestamp, measurement_name):
...@@ -151,7 +154,7 @@ def _error_points(router_fqdn, netconf_doc, timestamp, measurement_name): ...@@ -151,7 +154,7 @@ def _error_points(router_fqdn, netconf_doc, timestamp, measurement_name):
yield from map(_ctr2point, counters) yield from map(_ctr2point, counters)
def _main(router_fqdn: str, app_config_params: dict): def _juniper_main(router_fqdn: str, app_config_params: dict):
""" """
callable entry point, without click - for testing callable entry point, without click - for testing
...@@ -198,6 +201,10 @@ def _main(router_fqdn: str, app_config_params: dict): ...@@ -198,6 +201,10 @@ def _main(router_fqdn: str, app_config_params: dict):
client.write_points(points) client.write_points(points)
def _nokia_main(router_fqdn: str, app_config_params: dict):
assert False, 'TO DO'
@click.command() @click.command()
@click.option( @click.option(
'--config', 'app_config_params', '--config', 'app_config_params',
...@@ -206,28 +213,47 @@ def _main(router_fqdn: str, app_config_params: dict): ...@@ -206,28 +213,47 @@ def _main(router_fqdn: str, app_config_params: dict):
help='config filename', help='config filename',
callback=_validate_config) callback=_validate_config)
@click.option( @click.option(
'--router', 'router_fqdn', '--juniper', 'juniper_fqdns',
required=True, multiple=True,
type=click.STRING,
help='juniper router fqdn(s)',
callback=_validate_hostname)
@click.option(
'--nokia', 'nokia_fqdns',
multiple=True,
type=click.STRING, type=click.STRING,
help='router fqdn', help='nuniper router fqdn(s)',
callback=_validate_hostname) callback=_validate_hostname)
@click.option( @click.option(
'--netconf-only/--no-netconf-only', 'netconf_only', '--netconf-only/--no-netconf-only', 'netconf_only',
default=False, default=False,
type=click.BOOL, type=click.BOOL,
help='just run the netconf query and output the simplified xml, then exit') help='just run the netconf query and output the simplified xml, then exit')
def main(router_fqdn: str, app_config_params: dict, netconf_only: bool): def main(
juniper_fqdns: List[str],
nokia_fqdns: List[str],
app_config_params: dict,
netconf_only: bool):
# this is expected to be called only when debugging config/setup # this is expected to be called only when debugging config/setup
if netconf_only: if netconf_only:
_doc = juniper.get_interface_info_ncrpc( for _h in juniper_fqdns:
router_fqdn, _doc = juniper.get_interface_info_ncrpc(
ssh_config=app_config_params['ssh-config']) router_name=_h,
print(etree.tostring(_doc, pretty_print=True).decode('utf-8')) ssh_config=app_config_params['ssh-config'])
print(etree.tostring(_doc, pretty_print=True).decode('utf-8'))
for _h in nokia_fqdns:
_doc = nokia.get_interface_info_ncrpc(
router_name=_h,
ssh_config=app_config_params['ssh-config'])
print(etree.tostring(_doc, pretty_print=True).decode('utf-8'))
return return
# normal flow ... # normal flow ...
_main(router_fqdn, app_config_params) for _h in juniper_fqdns:
_juniper_main(_h, app_config_params)
for _h in nokia_fqdns:
_nokia_main(_h, app_config_params)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) ...@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
def get_interface_info_ncrpc(router_name, ssh_config, host_verify=False): def get_interface_info_ncrpc(router_name, ssh_config, host_verify=False):
request = etree.Element('get-interface-information') request = etree.Element('get-interface-information')
request.append(etree.Element('extensive')) request.append(etree.Element('extensive'))
return netconf.netconf_rpc( return netconf.rpc(
router_name=router_name, router_name=router_name,
ssh_config=ssh_config, ssh_config=ssh_config,
command=request, command=request,
......
# from lxml import etree
#
# from brian_polling_manager.interface_stats.vendors import netconf
def get_interface_info_ncrpc(router_name, ssh_config, host_verify=False):
# request = etree.Element('get-interface-information')
# request.append(etree.Element('extensive'))
# return netconf.netconf_rpc(
# router_name=router_name,
# ssh_config=ssh_config,
# command=request,
# host_verify=host_verify)
assert False, 'to do'
\ No newline at end of file
...@@ -56,7 +56,7 @@ def ifc_netconf_rpc(): ...@@ -56,7 +56,7 @@ def ifc_netconf_rpc():
with open(data_filename) as f: with open(data_filename) as f:
return etree.parse(f) return etree.parse(f)
with patch('brian_polling_manager.interface_stats.vendors.juniper.netconf_rpc') as rpc: with patch('brian_polling_manager.interface_stats.vendors.netconf.rpc') as rpc:
rpc.side_effect = _mocked_netconf_rpc rpc.side_effect = _mocked_netconf_rpc
yield yield
...@@ -445,7 +445,7 @@ def test_e2e(app_config_params, app_config_filename, ifc_netconf_rpc, testenv_co ...@@ -445,7 +445,7 @@ def test_e2e(app_config_params, app_config_filename, ifc_netconf_rpc, testenv_co
cli.main, cli.main,
[ [
'--config', app_config_filename, '--config', app_config_filename,
'--router', router_fqdn '--juniper', router_fqdn
]) ])
assert result.exit_code == 0, str(result) assert result.exit_code == 0, str(result)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment