<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Basic question around accessing single result in Python Discussions</title>
    <link>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148018#M30</link>
    <description>&lt;P&gt;Hello, I've seen several examples around accessing results from get-iter but I'm struggling to access a single result and the examples in the 9.4 API seem to rely on deprecated api calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;results status="passed"&amp;gt;
	&amp;lt;attributes&amp;gt;
		&amp;lt;snapmirror-info&amp;gt;
			&amp;lt;destination-location&amp;gt;vsm01:vsm01_my_volume&amp;lt;/destination-location&amp;gt;
			&amp;lt;destination-volume&amp;gt;vsm01_my_volume&amp;lt;/destination-volume&amp;gt;
			&amp;lt;destination-vserver&amp;gt;vsm01&amp;lt;/destination-vserver&amp;gt;
			&amp;lt;lag-time&amp;gt;1143&amp;lt;/lag-time&amp;gt;
			&amp;lt;source-location&amp;gt;vsm01:my_volume&amp;lt;/source-location&amp;gt;
			&amp;lt;source-volume&amp;gt;my_volume&amp;lt;/source-volume&amp;gt;
			&amp;lt;source-vserver&amp;gt;vsm01&amp;lt;/source-vserver&amp;gt;
		&amp;lt;/snapmirror-info&amp;gt;
	&amp;lt;/attributes&amp;gt;
&amp;lt;/results&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;My code snippet is as follows, my functions returns the ZExplore generated 'xo' object as 'XMLObject', how can I access the lat-time key/value please, thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def getLagTime(strCluster, strUser, strPassword, strDestVserver, strDestVolume):
    s = NaServer(strCluster, 1 , ONTAPI_VERSION)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(strUser, strPassword)

    api = NaElement("snapmirror-get")

    xi = NaElement("desired-attributes")
    api.child_add(xi)

    xi1 = NaElement("snapmirror-info")
    xi.child_add(xi1)

    xi1.child_add_string("lag-time","&amp;lt;lag-time&amp;gt;")
    api.child_add_string("destination-volume",strDestVolume)
    api.child_add_string("destination-vserver",strDestVserver)

    xo = s.invoke_elem(api)
    if (xo.results_status() != "passed") :
        print ("Error:\n")
        print (xo.sprintf())
        # If the check fails, we exit with 'UNKNOWN' according to the nagios spec.
        sys.exit (UNKNOWN)

    #print ("Received:\n")
    #print (xo.sprintf())
    
    return xo

# Call the function
XMLObject = getLagTime(strCluster, strUser, strPassword, strDestVserver, strDestVolume)

print ("Received SnapMirror Lag Time Data:")
print (XMLObject.sprintf())
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jun 2025 12:37:38 GMT</pubDate>
    <dc:creator>__mattb__</dc:creator>
    <dc:date>2025-06-04T12:37:38Z</dc:date>
    <item>
      <title>Basic question around accessing single result</title>
      <link>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148018#M30</link>
      <description>&lt;P&gt;Hello, I've seen several examples around accessing results from get-iter but I'm struggling to access a single result and the examples in the 9.4 API seem to rely on deprecated api calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;results status="passed"&amp;gt;
	&amp;lt;attributes&amp;gt;
		&amp;lt;snapmirror-info&amp;gt;
			&amp;lt;destination-location&amp;gt;vsm01:vsm01_my_volume&amp;lt;/destination-location&amp;gt;
			&amp;lt;destination-volume&amp;gt;vsm01_my_volume&amp;lt;/destination-volume&amp;gt;
			&amp;lt;destination-vserver&amp;gt;vsm01&amp;lt;/destination-vserver&amp;gt;
			&amp;lt;lag-time&amp;gt;1143&amp;lt;/lag-time&amp;gt;
			&amp;lt;source-location&amp;gt;vsm01:my_volume&amp;lt;/source-location&amp;gt;
			&amp;lt;source-volume&amp;gt;my_volume&amp;lt;/source-volume&amp;gt;
			&amp;lt;source-vserver&amp;gt;vsm01&amp;lt;/source-vserver&amp;gt;
		&amp;lt;/snapmirror-info&amp;gt;
	&amp;lt;/attributes&amp;gt;
&amp;lt;/results&amp;gt;
&lt;/PRE&gt;
&lt;P&gt;My code snippet is as follows, my functions returns the ZExplore generated 'xo' object as 'XMLObject', how can I access the lat-time key/value please, thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def getLagTime(strCluster, strUser, strPassword, strDestVserver, strDestVolume):
    s = NaServer(strCluster, 1 , ONTAPI_VERSION)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(strUser, strPassword)

    api = NaElement("snapmirror-get")

    xi = NaElement("desired-attributes")
    api.child_add(xi)

    xi1 = NaElement("snapmirror-info")
    xi.child_add(xi1)

    xi1.child_add_string("lag-time","&amp;lt;lag-time&amp;gt;")
    api.child_add_string("destination-volume",strDestVolume)
    api.child_add_string("destination-vserver",strDestVserver)

    xo = s.invoke_elem(api)
    if (xo.results_status() != "passed") :
        print ("Error:\n")
        print (xo.sprintf())
        # If the check fails, we exit with 'UNKNOWN' according to the nagios spec.
        sys.exit (UNKNOWN)

    #print ("Received:\n")
    #print (xo.sprintf())
    
    return xo

# Call the function
XMLObject = getLagTime(strCluster, strUser, strPassword, strDestVserver, strDestVolume)

print ("Received SnapMirror Lag Time Data:")
print (XMLObject.sprintf())
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 12:37:38 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148018#M30</guid>
      <dc:creator>__mattb__</dc:creator>
      <dc:date>2025-06-04T12:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Basic question around accessing single result</title>
      <link>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148019#M31</link>
      <description>&lt;P&gt;Ah, I finally managed to answer my own question - posting here in case anyone else has the same query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;# Call the function
XMLObject = getLagTime(strCluster, strUser, strPassword, strDestVserver, strDestVolume)

# Debug info:
print ("Received SnapMirror Lag Time Data:")
print (XMLObject.sprintf())
print ("\n")

# Walk the tree and pull out the lag-time value.
mynewlagtime = XMLObject.child_get("attributes").child_get("snapmirror-info").child_get_int("lag-time")

print (mynewlagtime)&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Apr 2019 10:24:31 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148019#M31</guid>
      <dc:creator>__mattb__</dc:creator>
      <dc:date>2019-04-17T10:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Basic question around accessing single result</title>
      <link>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148030#M32</link>
      <description>&lt;P&gt;You can also use xmltodict also to make it simple for these kind of tasks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is volume API example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import xmltodict
.
.
.
xo = s.invoke_elem(api)
obj = xmltodict.parse(xo.sprintf())
jd = json.dumps(obj)
jl = json.loads(jd)

if xo.results_status() == "failed":
	reason = xo.results_reason()
	print ("Failure: %s" %reason)
else:
	for h in jl["results"]["attributes-list"]["volume-attributes"]:
		print (h["volume-id-attributes"]["owning-vserver-name"], h["volume-id-attributes"]["name"], h["volume-space-attributes"]["percentage-size-used"])					
		&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 17:24:29 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Python-Discussions/Basic-question-around-accessing-single-result/m-p/148030#M32</guid>
      <dc:creator>gaurav_verma</dc:creator>
      <dc:date>2019-04-17T17:24:29Z</dc:date>
    </item>
  </channel>
</rss>

