I have one of the below list of dict.
storage_details_combined: [
{
“wwns_dict”: {
“host4”: “0x100098f2b3a1f324”,
“host5”: “0x100098f2b3a12635”
},
“wwns_pmax_list”: [
“100098f2b3a12635”,
“100098f2b3a1f324”
],
“server_name”: “myserver3.domain.org”
},
{
“wwns_dict”: {
“host3”: “0x100098f2b3a14633”,
“host1”: “0x100098f2b3a1d541”
},
“wwns_pmax_list”: [
“100098f2b3a1d541”,
“100098f2b3a14633”
],
“server_name”: “myserver11.domain.org”
}
]
I am expecting a dict like below.
my_dict:
{
100098f2b3a1f324 : myserver3_host4
100098f2b3a12635 : myserver3_host5
100098f2b3a14633 : myserver11_host3
100098f2b3a1d541 : myserver11_host1
}
vbotka
(Vladimir Botka)
2
my_dict:
{
100098f2b3a1f324 : myserver3_host4
100098f2b3a12635 : myserver3_host5
100098f2b3a14633 : myserver11_host3
100098f2b3a1d541 : myserver11_host1
}
storage_details_combined:
- server_name: myserver3.domain.org
wwns_dict:
host4: '0x100098f2b3a1f324'
host5: '0x100098f2b3a12635'
wwns_pmax_list:
- 100098f2b3a12635
- 100098f2b3a1f324
- server_name: myserver11.domain.org
wwns_dict:
host1: '0x100098f2b3a1d541'
host3: '0x100098f2b3a14633'
wwns_pmax_list:
- 100098f2b3a1d541
- 100098f2b3a14633
Use Jinja
my_dict: |
{% filter from_yaml %}
{% for i in storage_details_combined %}
{% set srv=i.server_name|split('.')|first %}
{% for k,v in i.wwns_dict.items() %}
{{ v[2:] }}: {{ srv }}_{{ k }}
{% endfor %}
{% endfor %}
{% endfilter %}