|
47 | 47 | 20160912, Niklas - ver 5.9c - Fixed Boron version check from false positives |
48 | 48 | 20160919, Niklas - ver 5.9d - getTopo reply format changed |
49 | 49 | 20160924, Niklas - ver 5.9e - Updated metrics selection |
50 | | - 20161226, Niklas - ver 5.9f - Updates from branches; multi-area/level and sid fix |
| 50 | + 20161204, Niklas - Ver 5.9f - Added BGP-RIB support to retrieve SIDs. Requires XRv 6.1.x, or higher. |
| 51 | + 20161210, Niklas - ver 5.9g - Added Netconf-modules for users to add their nodes to netconf |
| 52 | + - Added static netconf mappings for users ho give up on netconf |
| 53 | + 20161226, Niklas - ver 5.9h - Multi area/level fix for bgp-ls and sid bug. |
| 54 | + 20170202, Niklas - ver 5.9i - Refactored sid_list to sid_saves to avoid duplicate use |
51 | 55 | """ |
52 | 56 | __author__ = 'niklas' |
53 | 57 |
|
|
64 | 68 |
|
65 | 69 |
|
66 | 70 | #============================================================== |
67 | | -version = '5.9f' |
| 71 | + |
| 72 | +version = '5.9i' |
| 73 | + |
68 | 74 | # Defaults overridden by pathman_ini.py |
69 | 75 | odl_ip = '127.0.0.1' |
70 | 76 | odl_port = '8181' |
@@ -301,6 +307,24 @@ def formatTime(self, record, datefmt=None): |
301 | 307 | } |
302 | 308 |
|
303 | 309 |
|
| 310 | +def dict_to_file(mdict, file): |
| 311 | + with open(file,'w') as f: |
| 312 | + f.write(json.dumps(mdict)) |
| 313 | + logging.info("writing %s" % mdict) |
| 314 | + |
| 315 | + |
| 316 | +def file_to_dict(file): |
| 317 | + mdict = {} |
| 318 | + if os.path.exists(file): |
| 319 | + with open(file,'r') as f: |
| 320 | + string = f.read() |
| 321 | + user_files = json.loads(string) |
| 322 | + logging.info("reading %s" % user_files) |
| 323 | + for item in user_files: |
| 324 | + mdict.update({item:user_files[item]}) |
| 325 | + return mdict |
| 326 | + |
| 327 | + |
304 | 328 | def version_check(): |
305 | 329 | """modified from odl_gateway""" |
306 | 330 | url = get_version |
@@ -368,18 +392,19 @@ def get_config(url_list, match): |
368 | 392 | try: |
369 | 393 | sid = get_config([get_node_isis_config, get_node_ospf_config], 'prefix-sid') |
370 | 394 | rid = get_config([get_node_bgp_config], 'router-id') |
371 | | - logging.info('rid: %s, sid: %s' %(rid, sid)) |
| 395 | + logging.info('rid: %s, sid: %s' % (rid, sid)) |
372 | 396 |
|
373 | 397 | if sid != -1: |
374 | | - node_configs.update({node:sid}) |
| 398 | + node_configs.update({node: sid}) |
375 | 399 | logging.info("got netconf data for: %s" % node) |
376 | 400 | if rid != -1: |
377 | | - rid_dict.update({rid:sid}) |
| 401 | + rid_dict.update({rid: sid}) |
378 | 402 | logging.info("router-id: %s" % rid) |
379 | 403 | else: |
380 | | - logging.error("No rid for: %s" % node) |
| 404 | + logging.info("No sid for: %s" % node) |
381 | 405 | else: |
382 | | - logging.info("No sid for: %s" % node) |
| 406 | + logging.error("No rid for: %s" % node) |
| 407 | + |
383 | 408 | except: |
384 | 409 | logging.error("failure to get netconf data for: %s" % node) |
385 | 410 | return node_configs, rid_dict |
@@ -408,25 +433,41 @@ def keyd_dict_walker(mdict, key): |
408 | 433 | def node_sr_update(node_list): |
409 | 434 | def update(node, temp_sid): |
410 | 435 | if 'value' in temp_sid.keys(): |
411 | | - node_list[node_list.index(node)] = node._replace(sid = temp_sid['value']) |
412 | | - logging.info("SR sid updated for: %s" % node.name) |
| 436 | + node_list[node_list.index(node)] = node._replace(sid=temp_sid['value']) |
| 437 | + logging.info("SR sid updated for: %s from netconf" % node.name) |
413 | 438 | elif 'sid-value' in temp_sid.keys(): |
414 | | - node_list[node_list.index(node)] = node._replace(sid = temp_sid['sid-value']) |
415 | | - logging.info("SR sid updated for: %s" % node.name) |
416 | | - else: |
417 | | - logging.error("No sid value for: %s - %s" % (node.name,temp_sid)) |
418 | | - |
419 | | - node_configs, rid_dict = get_netconf() |
420 | | - for node in node_list: |
421 | | - temp_sid = node_configs.get(node.name,{}) |
422 | | - rid_sid = rid_dict.get(node.loopback,{}) |
423 | | - |
424 | | - if len(temp_sid) >0: |
425 | | - update(node, temp_sid) |
426 | | - elif len(rid_sid) >0: |
427 | | - update(node, rid_sid) |
| 439 | + node_list[node_list.index(node)] = node._replace(sid=temp_sid['sid-value']) |
| 440 | + logging.info("SR sid updated for: %s from netconf" % node.name) |
428 | 441 | else: |
429 | | - logging.error("No sid for: %s" % node.name) |
| 442 | + logging.error("No sid value for: %s - %s" % (node.name, temp_sid)) |
| 443 | + |
| 444 | + # BGP Check |
| 445 | + bgp_rib = MyBGP() |
| 446 | + sid_dict = bgp_rib.get_sr_info() |
| 447 | + my_local_sids = file_to_dict(sid_saves) |
| 448 | + # sid_dict = {} |
| 449 | + if len(sid_dict) > 0: |
| 450 | + for node in node_list: |
| 451 | + if node.loopback in sid_dict.keys(): |
| 452 | + node_list[node_list.index(node)] = node._replace(sid=sid_dict[node.loopback]) |
| 453 | + logging.info('SR sid updated for: {} from bgp'.format(node.name)) |
| 454 | + else: |
| 455 | + logging.error('No BGP SID for: {}'.format(node.name)) |
| 456 | + else: |
| 457 | + node_configs, rid_dict = get_netconf() |
| 458 | + for node in node_list: |
| 459 | + temp_sid = node_configs.get(node.name,{}) |
| 460 | + rid_sid = rid_dict.get(node.loopback,{}) |
| 461 | + |
| 462 | + if len(temp_sid) >0: |
| 463 | + update(node, temp_sid) |
| 464 | + elif len(rid_sid) >0: |
| 465 | + update(node, rid_sid) |
| 466 | + elif my_local_sids.get(node.loopback): |
| 467 | + node_list[node_list.index(node)] = node._replace(sid=my_local_sids[node.loopback]['sid']) |
| 468 | + logging.info('SR sid updated for: {} from static'.format(node.name)) |
| 469 | + else: |
| 470 | + logging.error("No sid for: %s" % node.name) |
430 | 471 |
|
431 | 472 | return node_list |
432 | 473 |
|
@@ -1107,14 +1148,14 @@ def sort_paths(pathlist, metriclist, type): |
1107 | 1148 |
|
1108 | 1149 | def postUrl(url, data): |
1109 | 1150 | import requests |
1110 | | - response = requests.post(url, data=data, auth = (odl_user, odl_password),headers= {'Content-Type': 'application/json'}) |
| 1151 | + response = requests.post(url, data=data, auth=(odl_user, odl_password), headers={'Content-Type': 'application/json'}) |
1111 | 1152 | # print response.text |
1112 | 1153 | return response.json() |
1113 | 1154 |
|
1114 | 1155 | def postXml(url, data): |
1115 | 1156 | """ post our lsp creation commands """ |
1116 | 1157 | import requests |
1117 | | - response = requests.post(url, data=data, auth = (odl_user, odl_password),headers= {'Content-Type': 'application/xml'}) |
| 1158 | + response = requests.post(url, data=data, auth=(odl_user, odl_password), headers={'Content-Type': 'application/xml'}) |
1118 | 1159 | # print response.text |
1119 | 1160 |
|
1120 | 1161 | return response.json() |
|
0 commit comments