The NetApp Manageability SDK (NMSDK) is an extremely powerful resource for programmatically interacting with your NetApp ONTAP systems. Included with the NMSDK is the ZExplore Development Interface which will auto-generate the relevant code that you will need to execute.
With ZExplore at your disposal, the only steps required to create a new script is:
- Look up the correct command
- Copy the provided code examples
- Update the variables to your specific use cases
However, every once and awhile you may run into an unexpected bug in the provided code examples. Let’s explore one such example, creating a new DNS entry, and walk through how to take advantage of the NetApp provided resources to troubleshoot and solve the issue.
To start with let’s take a greenfield cDOT 8.3.1 deployment that currently does not have any DNS configurations in place.
NTAP::> dns show This table is currently empty.
The ZExplore tool provides the following Python code to create a new DNS entry.
Note: I have removed several optional variables and the code required to connect to the NetApp Cluster for the sake of readability.
api = NaElement("net-dns-create") api.child_add_string("dns-state","
") api.child_add_string("domains"," ") xi = NaElement("name-servers") api.child_add(xi) xi.child_add_string("ip-address"," ") xo = s.invoke_elem(api)
After substituting site specific variables your code should similar to:
api = NaElement("net-dns-create") api.child_add_string("dns-state", "enabled") # Updated api.child_add_string("domains", "wwt.com") # Updated xi = NaElement("name-servers") api.child_add(xi) xi.child_add_string("ip-address", "172.20.226.145") # Updated xo = s.invoke_elem(api)
If you try executing the above code the NMSDK will provide you with the following failure message:
The confusing part of this error message is
expected element string. At face value it looks like the NMSDK is looking for a Python string object type. If you double check our code we are clearly passing
wwt.com as a string so that should not be the issue at hand.
Thankfully, NetApp has a Slack Channel (thePub) dedicated to all things DevOps including the NMSDK. Working with Andrew Kerr, who is on the NetApp OpenStack team, I was able to quickly troubleshoot the issue.
Andrew was able to generate the following XML code through an internal development tool which quickly cleared up the problem.
If you remember, the main portion of the error message stated
For array tag domains: expected element string. With the XML above we are able to determine that the NetApp system is expecting an element literally called string (
<string></string>) which was missing from the NMSDK provided code example. With the correct XML syntax at hand, we are able to manually create the correct code block which looks like:
api = NaElement("net-dns-create") dns_domains = NaElement("domains") api.child_add(dns_domains) dns_domains.child_add_string("string", "wwt.com") name_servers = NaElement("name-servers") api.child_add(name_servers) name_servers.child_add_string("ip-address", "172.20.227.24")
To make the code a little easier to digest and to fully understand what the Python code is accomplishing lets break apart the Python and XML code.
The first thing we need to do is tell the NMSDK what we are trying to configure, in this case create a new DNS entry.
api = NaElement("net-dns-create") # Create the
top level element
Next we define a child element under the top level
net-dns-create element and then add a child string to define what that actual element value is.
dns_domains = NaElement("domains") # Define the child element api.child_add(dns_domains) # Add the child element under
dns_domains.child_add_string("string", "wwt.com") # Add a child string to define the child element
Rinse and repeat for the name servers and you have a working code base.
If you ever see the
For array tag domains: expected element string error message just remember that the
array tag should be a child element and the
element should be a child string on that element. If there is any confusion, the Slack Channel is at your disposal and full of resources ready and eager to help.