Software Development Kit (SDK) and API Discussions
Software Development Kit (SDK) and API Discussions
Hi Guys,
I am currently trying to write a script to create volume via DFM as proxy.
I tried the API via direct filer, it works. Only via DFM proxy it doesn't work.
I keep getting the following errors if using dfm-proxy:
[root@vmwebtest Python]# python test aa zzz 10 11.7 Error: Missing required argument 'volume'
Code snipet:
import sys sys.path.append("/var/lib/NetApp/Python/") from NaServer import * def print_usage(): print ("Usage: nfs-bis.py <volname> <aggrname> <volsize> \n") print ("<volname> -- Volume name to be created\n") print ("<aggrname> -- Aggregate name\n") print ("<volsize> -- Request ordered size\n") sys.exit (1) args = len(sys.argv) - 1 if(args < 3): print_usage() volname = sys.argv[1] aggrname = sys.argv[2] volsize = int(sys.argv[3]) * 1.17 s = NaServer("192.168.59.12", 1 , 0) s.set_server_type("DFM") s.set_transport_type("HTTPS") s.set_port(8488) #s.set_style("LOGIN") s.set_admin_user("root", "start123") # Connects to DFM-Proxy proxyElem = NaElement("api-proxy") proxyElem.child_add_string("target", "192.168.59.20") proxyElem.child_add(requestElem) # ONTAPI API arg set here requestElem = NaElement("request") requestElem.child_add_string("name", "volume-create") requestElem.child_add_string("containing-aggr-name","aggr1") requestElem.child_add_string("language-code","en_US") requestElem.child_add_string("size","50m") requestElem.child_add_string("space-reserve","none") requestElem.child_add_string("volume","testPython1") out = s.invoke_elem(proxyElem) if (out.results_status() == 'failed'): print(out.results_reason()) print ("Error : " + out.results_reason() + "\n") sys.exit (1) dfmResponse = out.child_get('response') if (dfmResponse.child_get_string('status') == 'failed'): print ("Error: " + dfmResponse.child_get_string("reason") + "\n") sys.exit (1) ontapiResponse = dfmResponse.child_get('results') if (ontapiResponse.results_status() == 'failed'): print (ontapiResponse.results_reason() + "\n") sys.exit (1) print(ontapiResponse.sprintf())
Solved! See The Solution
Hi Daniel 🙂
In order to make your code doing what you wish, you need to create a new element called "args" where you add the arguments of volume-create zapi call.
In case you face a problem with SSL certificate verification, add 2 additional lines (3-4).
So, the working code should look like:
import sys # disable certificate verification in case of SSL certificate verification problem, comment out otherwise import ssl ssl._create_default_https_context = ssl._create_unverified_context sys.path.append("/var/lib/NetApp/Python/") from NaServer import * def print_usage(): print ("Usage: nfs-bis.py <volname> <aggrname> <volsize> \n") print ("<volname> -- Volume name to be created\n") print ("<aggrname> -- Aggregate name\n") print ("<volsize> -- Request ordered size\n") sys.exit (1) args = len(sys.argv) - 1 if(args < 3): print_usage() volname = sys.argv[1] aggrname = sys.argv[2] volsize = int(sys.argv[3]) * 1.17 s = NaServer("192.168.59.12", 1 , 0) s.set_server_type("DFM") s.set_transport_type("HTTPS") s.set_port(8488) #s.set_style("LOGIN") s.set_admin_user("root", "start123") # Connects to DFM-Proxy proxyElem = NaElement("api-proxy") proxyElem.child_add_string("target", "192.168.59.20") proxyElem.child_add(requestElem) # create element with volume-create arguments volcreateArgs = NaElement("args") volcreateArgs.child_add_string("volume","testPython1") volcreateArgs.child_add_string("containing-aggr-name","aggr1") volcreateArgs.child_add_string("language-code","en_US") volcreateArgs.child_add_string("size","50m") volcreateArgs.child_add_string("space-reserve","none") # ONTAPI API arg set here requestElem = NaElement("request") requestElem.child_add_string("name", "volume-create") # add arguments to volume-create zapi call requestElem.child_add(volcreateArgs) out = s.invoke_elem(proxyElem) if (out.results_status() == 'failed'): print(out.results_reason()) print ("Error : " + out.results_reason() + "\n") sys.exit (1) dfmResponse = out.child_get('response') if (dfmResponse.child_get_string('status') == 'failed'): print ("Error: " + dfmResponse.child_get_string("reason") + "\n") sys.exit (1) ontapiResponse = dfmResponse.child_get('results') if (ontapiResponse.results_status() == 'failed'): print (ontapiResponse.results_reason() + "\n") sys.exit (1) print(ontapiResponse.sprintf())
Here's the result...
## C4XXYYZZAA> vol status testPython1 ## Volume State Status Options ## testPython1 online raid_dp, flex create_ucode=on, convert_ucode=on, ## 64-bit guarantee=none, fractional_reserve=0 ## Volume UUID: 4eccc808-9b0c-4cea-8d40-d7b5865a9e81 ## Containing aggregate: 'aggr1'
Hope it helps ;).
Pavol
Hi Daniel 🙂
In order to make your code doing what you wish, you need to create a new element called "args" where you add the arguments of volume-create zapi call.
In case you face a problem with SSL certificate verification, add 2 additional lines (3-4).
So, the working code should look like:
import sys # disable certificate verification in case of SSL certificate verification problem, comment out otherwise import ssl ssl._create_default_https_context = ssl._create_unverified_context sys.path.append("/var/lib/NetApp/Python/") from NaServer import * def print_usage(): print ("Usage: nfs-bis.py <volname> <aggrname> <volsize> \n") print ("<volname> -- Volume name to be created\n") print ("<aggrname> -- Aggregate name\n") print ("<volsize> -- Request ordered size\n") sys.exit (1) args = len(sys.argv) - 1 if(args < 3): print_usage() volname = sys.argv[1] aggrname = sys.argv[2] volsize = int(sys.argv[3]) * 1.17 s = NaServer("192.168.59.12", 1 , 0) s.set_server_type("DFM") s.set_transport_type("HTTPS") s.set_port(8488) #s.set_style("LOGIN") s.set_admin_user("root", "start123") # Connects to DFM-Proxy proxyElem = NaElement("api-proxy") proxyElem.child_add_string("target", "192.168.59.20") proxyElem.child_add(requestElem) # create element with volume-create arguments volcreateArgs = NaElement("args") volcreateArgs.child_add_string("volume","testPython1") volcreateArgs.child_add_string("containing-aggr-name","aggr1") volcreateArgs.child_add_string("language-code","en_US") volcreateArgs.child_add_string("size","50m") volcreateArgs.child_add_string("space-reserve","none") # ONTAPI API arg set here requestElem = NaElement("request") requestElem.child_add_string("name", "volume-create") # add arguments to volume-create zapi call requestElem.child_add(volcreateArgs) out = s.invoke_elem(proxyElem) if (out.results_status() == 'failed'): print(out.results_reason()) print ("Error : " + out.results_reason() + "\n") sys.exit (1) dfmResponse = out.child_get('response') if (dfmResponse.child_get_string('status') == 'failed'): print ("Error: " + dfmResponse.child_get_string("reason") + "\n") sys.exit (1) ontapiResponse = dfmResponse.child_get('results') if (ontapiResponse.results_status() == 'failed'): print (ontapiResponse.results_reason() + "\n") sys.exit (1) print(ontapiResponse.sprintf())
Here's the result...
## C4XXYYZZAA> vol status testPython1 ## Volume State Status Options ## testPython1 online raid_dp, flex create_ucode=on, convert_ucode=on, ## 64-bit guarantee=none, fractional_reserve=0 ## Volume UUID: 4eccc808-9b0c-4cea-8d40-d7b5865a9e81 ## Containing aggregate: 'aggr1'
Hope it helps ;).
Pavol
awesome. thanks alot. I figure out it was something missing becoz the filer logs shown that no argument was pass on. 😄