Python Discussions

Newbie to Python and NASDK

jet

I am new to using Python and the NASDK and was trying to determine how to return some data from the security-config-get api.  Here is some sample code I used to gather the data and the output that I can get from it. As you can see I can get the some of the data out, but I only get one of the supported ciphers.  I have tried several ways to use a 'for in' loop.  It does show me that there are 3 ciphers but the i have not been able to figure out how to get the 3 actual names into a variable to use for verification.  I am sure whatever the answer to this is would/could be used in similar situations with other API calls.  Thanks  

 

api = NaElement("security-config-get")

 

xi = NaElement("desired-attributes")

api.child_add(xi)

 

 

xi1 = NaElement("security-config-info")

xi.child_add(xi1)

 

xi1.child_add_string("cluster-security-config-ready","<cluster-security-config-ready>")

xi1.child_add_string("interface","<interface>")

xi1.child_add_string("is-fips-enabled","<is-fips-enabled>")

xi1.child_add_string("supported-ciphers","<supported-ciphers>")

 

xi2 = NaElement("supported-protocols")

xi1.child_add(xi2)

 

xi2.child_add_string("security-supported-protocols","<security-supported-protocols>")

api.child_add_string("interface","ssl")

 

xo = s.invoke_elem(api)

if (xo.results_status() == "failed") :

print ("Error:\n")

print (xo.sprintf())

sys.exit (1)

 

print ("Received:\n")

print (xo.sprintf())

 

attribs = xo.child_get("attributes")

result=attribs.children_get()

for res in result:

i = res.child_get_string("interface")

f = res.child_get_string("is-fips-enabled")

c = res.child_get_string("supported-ciphers")

p1 = res.child_get("supported-protocols").child_get_string("security-supported-protocols")

print (i)

print (f)

print (c)

print (p1)

 

OUTPUT___________________

Received:

<results status="passed">
 <attributes>
  <security-config-info>
   <cluster-security-config-ready>true</cluster-security-config-ready>
   <interface>ssl</interface>
   <is-fips-enabled>false</is-fips-enabled>
   <supported-ciphers>ALL:!RC4:!LOW:!aNULL:!EXP:!eNULL</supported-ciphers>
   <supported-protocols>
    <security-supported-protocols>tlsv1.2</security-supported-protocols>
    <security-supported-protocols>tlsv1.1</security-supported-protocols>
    <security-supported-protocols>tlsv1</security-supported-protocols>
   </supported-protocols>
  </security-config-info>
 </attributes>
</results>

ssl
false
ALL:!RC4:!LOW:!aNULL:!EXP:!eNULL
tlsv1.2

1 REPLY 1

jet

Here is the way i tried this that basically gave me the 3 ciphers but not the name of them, just says none.

 

attribs = xo.child_get("attributes")

result=attribs.children_get()

for res in result:

i = res.child_get_string("interface")

f = res.child_get_string("is-fips-enabled")

c = res.child_get_string("supported-ciphers")

# p1 = res.child_get("supported-protocols").child_get_string("security-supported-protocols")

print (i)

print (f)

print (c)

# print (p1)

pt = res.child_get("supported-protocols")

ptres = pt.children_get()

for p in iter(ptres):

p1 = p.child_get_string("security-supported-protocols")

print (p1)

 

OUTPUT_____________________

Received:

<results status="passed">
 <attributes>
  <security-config-info>
   <cluster-security-config-ready>true</cluster-security-config-ready>
   <interface>ssl</interface>
   <is-fips-enabled>false</is-fips-enabled>
   <supported-ciphers>ALL:!RC4:!LOW:!aNULL:!EXP:!eNULL</supported-ciphers>
   <supported-protocols>
    <security-supported-protocols>tlsv1.2</security-supported-protocols>
    <security-supported-protocols>tlsv1.1</security-supported-protocols>
    <security-supported-protocols>tlsv1</security-supported-protocols>
   </supported-protocols>
  </security-config-info>
 </attributes>
</results>

ssl
false
ALL:!RC4:!LOW:!aNULL:!EXP:!eNULL
None
None
None

Announcements
Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public