4
4
from __future__ import print_function
5
5
import yang as ly
6
6
import syslog
7
+
7
8
from json import dump , dumps , loads
8
9
from xmltodict import parse
9
10
from glob import glob
10
11
11
- qos_maps_model = ['DSCP_TO_TC_MAP_LIST' ,
12
- 'DOT1P_TO_TC_MAP_LIST' ,
13
- 'TC_TO_PRIORITY_GROUP_MAP_LIST' ,
14
- 'TC_TO_QUEUE_MAP_LIST' ,
15
- 'MAP_PFC_PRIORITY_TO_QUEUE_LIST' ,
16
- 'PFC_PRIORITY_TO_PRIORITY_GROUP_MAP_LIST' ]
17
-
18
12
"""
19
13
This is the Exception thrown out of all public function of this class.
20
14
"""
@@ -412,108 +406,6 @@ def _yangConvert(val):
412
406
413
407
return vValue
414
408
415
- """
416
- Xlate a Qos Maps list
417
- This function will xlate from a dict in config DB to a Yang JSON list
418
- using yang model. Output will be go in self.xlateJson
419
-
420
- Note: Exceptions from this function are collected in exceptionList and
421
- are displayed only when an entry is not xlated properly from ConfigDB
422
- to sonic_yang.json.
423
-
424
- QOS MAPS Yang has inner list, which is diffrent from config DB.
425
- Each field value in config db should be converted to inner list with
426
- key and value.
427
- Example:
428
-
429
- Config DB:
430
- "DSCP_TO_TC_MAP": {
431
- "Dscp_to_tc_map1": {
432
- "1": "1",
433
- "2": "2"
434
- }
435
- }
436
-
437
- YANG Model:
438
- module: sonic-dscp-tc-map
439
- +--rw sonic-dscp-tc-map
440
- +--rw DSCP_TO_TC_MAP
441
- +--rw DSCP_TO_TC_MAP_LIST* [name]
442
- +--rw name string
443
- +--rw DSCP_TO_TC_MAP* [dscp]
444
- +--rw dscp string
445
- +--rw tc? string
446
-
447
- YANG JSON:
448
- "sonic-dscp-tc-map:sonic-dscp-tc-map": {
449
- "sonic-dscp-tc-map:DSCP_TO_TC_MAP": {
450
- "DSCP_TO_TC_MAP_LIST": [
451
- {
452
- "name": "map3",
453
- "DSCP_TO_TC_MAP": [
454
- {
455
- "dscp": "64",
456
- "tc": "1"
457
- },
458
- {
459
- "dscp":"2",
460
- "tc":"2"
461
- }
462
- ]
463
- }
464
- ]
465
- }
466
- }
467
- """
468
- def _xlateQosMapList (self , model , yang , config , table , exceptionList ):
469
-
470
- #create a dict to map each key under primary key with a dict yang model.
471
- #This is done to improve performance of mapping from values of TABLEs in
472
- #config DB to leaf in YANG LIST.
473
- inner_clist = model .get ('list' )
474
- if inner_clist :
475
- inner_listKey = inner_clist ['key' ]['@value' ]
476
- inner_leafDict = self ._createLeafDict (inner_clist , table )
477
- for lkey in inner_leafDict :
478
- if inner_listKey != lkey :
479
- inner_listVal = lkey
480
-
481
- # get keys from YANG model list itself
482
- listKeys = model ['key' ]['@value' ]
483
- self .sysLog (msg = "xlateList keyList:{}" .format (listKeys ))
484
- primaryKeys = list (config .keys ())
485
- for pkey in primaryKeys :
486
- try :
487
- vKey = None
488
- self .sysLog (syslog .LOG_DEBUG , "xlateList Extract pkey:{}" .\
489
- format (pkey ))
490
- # Find and extracts key from each dict in config
491
- keyDict = self ._extractKey (pkey , listKeys )
492
-
493
- if inner_clist :
494
- inner_yang_list = list ()
495
- for vKey in config [pkey ]:
496
- inner_keyDict = dict ()
497
- self .sysLog (syslog .LOG_DEBUG , "xlateList Key {} vkey {} Val {} vval {}" .\
498
- format (inner_listKey , str (vKey ), inner_listVal , str (config [pkey ][vKey ])))
499
- inner_keyDict [inner_listKey ] = str (vKey )
500
- inner_keyDict [inner_listVal ] = str (config [pkey ][vKey ])
501
- inner_yang_list .append (inner_keyDict )
502
-
503
- keyDict [inner_clist ['@name' ]] = inner_yang_list
504
- yang .append (keyDict )
505
- # delete pkey from config, done to match one key with one list
506
- del config [pkey ]
507
-
508
- except Exception as e :
509
- # log debug, because this exception may occur with multilists
510
- self .sysLog (msg = "xlateList Exception:{}" .format (str (e )), \
511
- debug = syslog .LOG_DEBUG , doPrint = True )
512
- exceptionList .append (str (e ))
513
- # with multilist, we continue matching other keys.
514
- continue
515
- return
516
-
517
409
"""
518
410
Xlate a list
519
411
This function will xlate from a dict in config DB to a Yang JSON list
@@ -524,22 +416,16 @@ def _xlateQosMapList(self, model, yang, config, table, exceptionList):
524
416
to sonic_yang.json.
525
417
"""
526
418
def _xlateList (self , model , yang , config , table , exceptionList ):
527
-
528
- #Qos Map lists needs special handling because of inner yang list and
529
- #config db format.
530
- if model ['@name' ] in qos_maps_model :
531
- self .sysLog (msg = "_xlateQosMapList: {}" .format (model ['@name' ]))
532
- self ._xlateQosMapList (model , yang ,config , table , exceptionList )
533
- return
534
419
535
420
#create a dict to map each key under primary key with a dict yang model.
536
421
#This is done to improve performance of mapping from values of TABLEs in
537
422
#config DB to leaf in YANG LIST.
538
-
539
423
leafDict = self ._createLeafDict (model , table )
424
+
540
425
# get keys from YANG model list itself
541
426
listKeys = model ['key' ]['@value' ]
542
427
self .sysLog (msg = "xlateList keyList:{}" .format (listKeys ))
428
+
543
429
primaryKeys = list (config .keys ())
544
430
for pkey in primaryKeys :
545
431
try :
@@ -573,6 +459,7 @@ def _xlateList(self, model, yang, config, table, exceptionList):
573
459
"""
574
460
def _xlateListInContainer (self , model , yang , configC , table , exceptionList ):
575
461
clist = model
462
+ #print(clist['@name'])
576
463
yang [clist ['@name' ]] = list ()
577
464
self .sysLog (msg = "xlateProcessListOfContainer: {}" .format (clist ['@name' ]))
578
465
self ._xlateList (clist , yang [clist ['@name' ]], configC , table , exceptionList )
@@ -742,93 +629,10 @@ def _revYangConvert(val):
742
629
743
630
return vValue
744
631
745
- """
746
- Rev xlate from <TABLE>_LIST to table in config DB
747
- QOS MAP Yang has inner list, each inner list key:val should
748
- be mapped to field:value in Config DB.
749
- Example:
750
-
751
- YANG:
752
- module: sonic-dscp-tc-map
753
- +--rw sonic-dscp-tc-map
754
- +--rw DSCP_TO_TC_MAP
755
- +--rw DSCP_TO_TC_MAP_LIST* [name]
756
- +--rw name string
757
- +--rw DSCP_TO_TC_MAP* [dscp]
758
- +--rw dscp string
759
- +--rw tc? string
760
-
761
- YANG JSON:
762
- "sonic-dscp-tc-map:sonic-dscp-tc-map": {
763
- "sonic-dscp-tc-map:DSCP_TO_TC_MAP": {
764
- "DSCP_TO_TC_MAP_LIST": [
765
- {
766
- "name": "map3",
767
- "DSCP_TO_TC_MAP": [
768
- {
769
- "dscp": "64",
770
- "tc": "1"
771
- },
772
- {
773
- "dscp":"2",
774
- "tc":"2"
775
- }
776
- ]
777
- }
778
- ]
779
- }
780
- }
781
-
782
- Config DB:
783
- "DSCP_TO_TC_MAP": {
784
- "Dscp_to_tc_map1": {
785
- "1": "1",
786
- "2": "2"
787
- }
788
- }
789
- """
790
-
791
- def _revQosMapXlateList (self , model , yang , config , table ):
792
- # get keys from YANG model list itself
793
- listKeys = model ['key' ]['@value' ]
794
- # create a dict to map each key under primary key with a dict yang model.
795
- # This is done to improve performance of mapping from values of TABLEs in
796
- # config DB to leaf in YANG LIST.
797
-
798
- # Gather inner list key and value from model
799
- inner_clist = model .get ('list' )
800
- if inner_clist :
801
- inner_listKey = inner_clist ['key' ]['@value' ]
802
- inner_leafDict = self ._createLeafDict (inner_clist , table )
803
- for lkey in inner_leafDict :
804
- if inner_listKey != lkey :
805
- inner_listVal = lkey
806
-
807
- # list with name <NAME>_LIST should be removed,
808
- if "_LIST" in model ['@name' ]:
809
- for entry in yang :
810
- # create key of config DB table
811
- pkey , pkeydict = self ._createKey (entry , listKeys )
812
- self .sysLog (syslog .LOG_DEBUG , "revXlateList pkey:{}" .format (pkey ))
813
- config [pkey ]= dict ()
814
- # fill rest of the entries
815
- inner_list = entry [inner_clist ['@name' ]]
816
- for index in range (len (inner_list )):
817
- self .sysLog (syslog .LOG_DEBUG , "revXlateList fkey:{} fval {}" .\
818
- format (str (inner_list [index ][inner_listKey ]),\
819
- str (inner_list [index ][inner_listVal ])))
820
- config [pkey ][str (inner_list [index ][inner_listKey ])] = str (inner_list [index ][inner_listVal ])
821
- return
822
-
823
632
"""
824
633
Rev xlate from <TABLE>_LIST to table in config DB
825
634
"""
826
635
def _revXlateList (self , model , yang , config , table ):
827
-
828
- # special processing for QOS Map table.
829
- if model ['@name' ] in qos_maps_model :
830
- self ._revQosMapXlateList (model , yang , config , table )
831
- return
832
636
833
637
# get keys from YANG model list itself
834
638
listKeys = model ['key' ]['@value' ]
0 commit comments