Software Development Kit (SDK) and API Discussions

api data extract initiator-name

i've followed a previous article : https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/How-to-get-result-from-NMSDK-in-json-format-or-set-content-type-to-ap...

 

with a great example posted by gaurav_verma

 

In my case i'd like to extract igroup XML metadata , which is returned from the ontap cluster after running 

api = NaElement("igroup-get-iter") ( see below)

 

<initiator-group-info>
<initiator-group-alua-enabled>true</initiator-group-alua-enabled>
<initiator-group-name>v0101</initiator-group-name>
<initiator-group-os-type>hyper_v</initiator-group-os-type>
<initiator-group-throttle-borrow>false</initiator-group-throttle-borrow>
<initiator-group-throttle-reserve>0</initiator-group-throttle-reserve>
<initiator-group-type>iscsi</initiator-group-type>
<initiator-group-use-partner>true</initiator-group-use-partner>
<initiator-group-uuid>8f3a4fb8-2c64-11e9-aa39-00a098321792</initiator-group-uuid>
<initiator-group-vsa-enabled>false</initiator-group-vsa-enabled>
<initiators>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:wshv0101n01</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n02</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n03</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n04</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n05</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n06</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n07</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n08</initiator-name>
</initiator-info>
<initiator-info>
<initiator-name>iqn.1991-05.com.microsoft:v0101n09</initiator-name>
</initiator-info>
</initiators>
<vserver>testv99</vserver>

 

i cant seem to extract each initiator name entry  ie ...

 

<initiator-name>iqn.1991-05.com.microsoft:v0101n09</initiator-name>

 

as you can see there are multiple entries...

 

here is what i have so far...

 

api = NaElement("igroup-get-iter")
xi = NaElement("desired-attributes")
api.child_add(xi)
xi1 = NaElement("initiator-group-info")
xi.child_add(xi1)
xi1.child_add_string("initiator-group-alua-enabled","<initiator-group-alua-enabled>")
xi1.child_add_string("initiator-group-name","<initiator-group-name>")
xi1.child_add_string("initiator-group-os-type","<initiator-group-os-type>")
xi1.child_add_string("initiator-group-portset-name","<initiator-group-portset-name>")
xi1.child_add_string("initiator-group-throttle-borrow","<initiator-group-throttle-borrow>")
xi1.child_add_string("initiator-group-throttle-reserve","<initiator-group-throttle-reserve>")
xi1.child_add_string("initiator-group-type","<initiator-group-type>")
xi1.child_add_string("initiator-group-use-partner","<initiator-group-use-partner>")
xi1.child_add_string("initiator-group-uuid","<initiator-group-uuid>")
xi1.child_add_string("initiator-group-vsa-enabled","<initiator-group-vsa-enabled>")
xi2 = NaElement("initiators")
xi1.child_add(xi2)
xi3 = NaElement("initiator-info")
xi2.child_add(xi3)
xi3.child_add_string("initiator-name","<initiator-name>")
xi1.child_add_string("lun-id","<lun-id>")
xi1.child_add_string("vserver","<vserver>")
api.child_add_string("max-records","99999")
xo = epicclustername.invoke_elem(api)

 

my_xml_initiator_group=xo.sprintf()
my_initiator_group_dictionary = xmltodict.parse(my_xml_initiator_group)
print ("Convert to json.dumps.....")
jasondump_ig=json.dumps(my_initiator_group_dictionary)
jasonload_ig=json.loads(jasondump_ig)

global igdata

 

igdata = []
for ig in jasonload_ig["results"]["attributes-list"]["initiator-group-info"]:
# print ("-----------------------------------------------------------------")
# lets extract ALL metadata - lots will not be used - but easier to use in the future - if needed.
initiatorgroupaluaenabled=(ig["initiator-group-alua-enabled"])
initiatorgroupname=(ig["initiator-group-name"])
initiatorgroupostype=(ig["initiator-group-os-type"])
initiatorgroupthrottleborrow=(ig["initiator-group-throttle-borrow"])
initiatorgroupthrottlereserve=(ig["initiator-group-throttle-reserve"])
initiatorgrouptype=(ig["initiator-group-type"])
initiatorgroupusepartner=(ig["initiator-group-use-partner"])
initiatorgroupuuid=(ig["initiator-group-uuid"])
initiatorgroupvsaenabled=(ig["initiator-group-vsa-enabled"])

# initiatorname=(ig["initiators"]["initiator-info"]["initiator-name"])

 

 

igdata.append((initiatorgroupaluaenabled,initiatorgroupname,initiatorgroupostype,initiatorgroupthrottleborrow,initiatorgroupthrottlereserve,initiatorgrouptype,initiatorgroupusepartner,initiatorgroupuuid,initiatorgroupvsaenabled))

 

for i in igdata:
print ("I have : {}".format(i))

 

tail of the python file on execution shows...

I have : (u'true', u'igroup_md0004', u'linux', u'false', u'0', u'iscsi', u'true', u'fa9acae7-125d-11e6-978a-123478563412', u'false',)
I have : (u'true', u'igroup_md6369', u'windows', u'false', u'0', u'iscsi', u'true', u'2cdee44a-2e10-11e6-8345-00a098321792', u'false')

 

however if i unhash the line in the loop ....

 

initiatorname=(ig["initiators"]["initiator-info"]["initiator-name"])

 

and add this var in the append , if fails.... with

 

KeyError: 'initiators'

 

so,,, how do i extract sub elements from the original xml format ?

ie 

         ["initiators"]["initiator-info"]["initiator-name"]

 

Maybe there is a alternative solution that i'm unaware of....

any help, much appreciated ...

 

 

 

 

 

NetApp Insights To Action
All Community Forums