我已将数据存储到字典中。现在,我不知道如何将其用于jinja模板中以获取预期的输出。我试图获取,但是没有用。
这是我的字典:
{
"Nokia_SRAN_S1-MME_X2_IN": [
{
"b": 102,
"c": "",
"d": "Nokia_SRAN_mobility_platinum",
"e": "h1",
"f": 7,
"g": "dscp-fc-map",
"h": [
"ef",
"nc1"
]
}
],
"Nodeb_IN_New": [
{
"b": 107,
"c": "class-default",
"d": "mobility-platinum",
"e": "h1",
"f": 7,
"g": "dscp-fc-map",
"h": [
"ef"
]
},
{
"b": 107,
"c": "",
"d": "mobility-gold-new",
"e": "h2",
"f": 5,
"g": "dscp-fc-map",
"h": [
"af41"
]
},
{
"b": 107,
"c": "",
"d": "mobility-silver-new",
"e": "l1",
"f": 4,
"g": "dscp-fc-map",
"h": [
"af11",
"af21",
"af31"
]
}
]
}
这是我尝试过的JINJA模板。
/configure qos
{%-for k,v in data.items()%}
{%-if (v['nokia'])|length>0%}
{{v['nokia']}} {{v['policy_id']}} create
description "{{k}}"
{%-for i in range(0,(v['dscp'])|length)%}
dscp {{v['dscp'][i]}} fc "{{v['mpls']}}"
{%endfor%}
{%-if v['default'] != ''%}
{v['default']}
{%endif%}
exit
{%endif%}
ingress-cos-policy {{v['policy_id']}} create
description "{{k}}"
enable-dscp-exp-remarking
{{v['nokia']}} {{v['policy_id']}}
exit
sap-ingress {{v['policy_id']}} create
description "{{k}}"
ingress-cos-policy {{v['policy_id']}}
{%-for j in queue%}
policer {{queue}} create
exit
{%-endfor%}
{%-for j,l in zip(queue,v['dscp'])%}
fc "{{v['dscp']}}" create
policer {{queue}}
exit
{%-endfor%}
exit
{%-endfor%}
我的预期输出应该是这样的:
/configure qos
dscp-fc-map 100 create
description "Nokia_SRAN_S1-MME_X2_IN"
dscp ef fc "h1"
dscp nc1 fc "h1"
exit
ingress-cos-policy 100 create
description "Nokia_SRAN_S1-MME_X2_IN"
enable-dscp-exp-remarking
dscp-fc-map 100
exit
sap-ingress 100 create
description "Nokia_SRAN_S1-MME_X2_IN"
ingress-cos-policy 100
policer 7 create
exit
fc "h1" create
policer 7
exit
exit
-----------------
/configure qos
dscp-fc-map 101 create
description "Nodeb_IN_New"
dscp ef fc "h1"
dscp af11 fc "l1"
dscp af21 fc "l1"
dscp af31 fc "l1"
dscp af41 fc "h2"
default-fc be
exit
ingress-cos-policy 101 create
description "Nodeb_IN_New"
enable-dscp-exp-remarking
dscp-fc-map 101
exit
sap-ingress 101 create
description "Nodeb_IN_New"
ingress-cos-policy 101
policer 7 create
exit
policer 5 create
exit
policer 4 create
exit
fc "h1" create
policer 7
exit
fc "h2" create
policer 5
exit
fc "l1" create
policer 4
exit
exit
需要帮助才能获得预期的输出。