-
Notifications
You must be signed in to change notification settings - Fork 33
/
odl_test.py
executable file
·94 lines (67 loc) · 2.71 KB
/
odl_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python2.7
"""
* Copyright (c) 2016 by Cisco Systems, Inc.
* All rights reserved.
odl_test.py
- get a quick check on PCEP, BGP and Netconf from your ODL controller
Niklas Montin, 20161212, [email protected]
"""
import argparse
import sys
import json
import logging
from pathman_sr import LOGGING
from netconf import pcep_test, bgp_test, netconf_test, controller
version = '1.0'
def nprint(mydict):
print json.dumps(mydict, sort_keys=True,indent=4, separators=(',', ': '))
def print_pcep(name=None):
reply = pcep_test(name)
nprint(reply)
def print_bgp(name=None, address=None):
reply = bgp_test(name, address)
nprint(reply)
def print_netconf(name=None):
reply = netconf_test(name)
nprint(reply)
if __name__ == '__main__':
LOGGING['root']['handlers'] = ['console','logtofile']
logging.config.dictConfig(LOGGING)
logging.info("This is initializing the automation log")
logging.captureWarnings(True)
p = argparse.ArgumentParser(
prog=sys.argv[0],
description='Test BGP, PCEP and Netconf output ODL Controller',
version=version,
epilog='Copyright (c) 2017 by Cisco Systems, Inc. All Rights Reserved'
)
subp = p.add_subparsers(help='commands', dest='command')
pcep_p = subp.add_parser("pcep", help='print pcep output')
pcep_p.add_argument('--address', type=str, help='address of node to list')
bgp_p = subp.add_parser("bgp", help='print bgp output')
bgp_p.add_argument('--name', type=str, help='name of node to list')
bgp_p.add_argument('--address', type=str, help='address of node to list')
netconf_p = subp.add_parser("netconf", help='list netconf nodes')
netconf_p.add_argument('--name', type=str, help='name of node to list')
p.add_argument('--controller_ip', default=controller['odl_ip'], type=str, help='ODL Controller ip address')
p.add_argument('--controller_port', default=controller['odl_port'], type=str, help='ODL port')
p.add_argument('--user', default=controller['any_user'], type=str, help='ODL user')
p.add_argument('--password', default=controller['any_pass'], type=str, help='ODL password')
ns = p.parse_args()
logging.info("Parser: %s" % ns)
if ns.controller_ip:
controller['odl_ip'] = ns.controller_ip
if ns.controller_port:
controller['odl_port'] = ns.controller_port
if ns.user:
controller['any_user'] = ns.user
# odl_user = ns.user
if ns.password:
controller['any_pass'] = ns.password
if ns.command == 'pcep':
print_pcep(ns.address)
elif ns.command == 'bgp':
print_bgp(ns.name, ns.address)
elif ns.command == 'netconf':
print_netconf(ns.name)
# Bye bye