Hey Randy and Richard,
A quick note: I am in no way a programmer, I just pretend to be one
when I need to get stuff done. My code is likely ugly.
Covering most of the issues called out in this thread.
The doc file error means zedi can't run the small handful of zapis
that only exist in 8.3 or later as it does not yet know about them.
It's not going to prevent zapis that exist in both zedi and 8.3 from
working. Nor will it affect your abilities to run zapis with python
or any language by hand.
Before I share an example that works, a quick note on the page you
linked:
http://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Anyone-successfully-using-the-cifs-share-get-iter-API/td-p/73664
It talks about how when iterating through xml, from a data
collection perspective you can either get a list of all children, or
get a child object given the name, but there is no clear
documentation on how to get the content of an xml element. This is
of course a requirement to get stuff done. I struggled with this
initially as well, and that page explained it enough to me to get
stuff working. It's not really a bug, more a lack of clear
documentation on the calls you can do on elements.
For example, if you have this:
<share>
<name>awesomeshare</name>
<path>/project/location</path>
</share>
You can iterate through the share children and get objects for the
name and path (the children_get() call), or you can pull the name
object specifically with child_get('name'), but you want that
'awesomeshare', or that '/project/location' property value, not just
an object for the property/value combination. The documentation
(still?) lacks a clear indication on how to get the value inside of
an xml element. Zulanch answers it: you do a
object.element['content'] to get that inside information. The python
sdk code itself has not really changed in years it looks like, as
it's a convenient wrapper around builtin xml libraries and is
expected to work in the same form for all zapis for the past years
(decade?).
Here's a basic working python script example that pulls data over
zapi to get you going, using that .element call extensively; it at
least works against 8.3.1. http://pastebin.com/Kpm6nJmq
The example script is very basic and creates a python list of
returned elements with a python dictionary of properties for each
one, much easier to handle in python than the raw xml returned by
the sdk.
It's a scraper, it does not push changes.
The script is not optimal, especially if elements get really deep,
but should work for most queries and can easily be extended. I bet
libraries like xmltodict can do this in a more scalable way, I'm
doing all the work by hand in this example. At least the raw code
should give you a very good idea on how to make zapi calls work in
python. I also cover the max records part and do subsequent calls
that start where the previous zapi response left off to get that
comprehensive table of data.
Notes on script:
It takes a cluster mgmt ip or hostname, and a zapi call as input
strings. It uses NaServer and NaElement to get the xml.
It has the default max records of 20 set to keep pressure on the
cluster low in maintaining records in memory before returning to
clients (management processes do not like to do too much work,
imagine them having to keep thousands of objects in memory, each
with hundreds of properties before they can return them, while a
dozen other management tools are hitting the same cluster against
the same node that hosts the cluster mgmt lif. I don't want to be
complicit in an api DOS of my own system when pulling inventory if I
don't need to be), but will continue pulling 20 items sequentially
until all items for a given zapi are pulled (in below example the
items are shares, but it can also get volumes, aggregates, ports,
disks, lifs etc. with the associated zapi)
Below lines pull in the script, invoke the function and print the
output. The script depends on a creds file with a username and
password. The script expects the relevant user to have ontapi (at
least read only) access. (or do things your own way and modify it to
use certs instead).
Maarten
--------------------------
#!/usr/bin/env python
from NcPullDictExample import api_dict
output_array=api_dict('YOUR CLUSTER IP/HOSTNAME
HERE','cifs-share-get-iter')
#This iterates over the returned list, and shows each elements'
properties, see example output below.
for i in output_array:
print(i)
#Or get the whole list in one go:
#printapi_dict('YOUR CLUSTER IP/HOSTNAME
HERE','cifs-share-get-iter')
--------------------------
creds file needed by the NcPullDictExample would simply contain
something like below:
--------------------------
user = 'apiuser'
pw = 'hunter2'
--------------------------
example output for the CIFS query.
{'cifs-server': 'TESTVSERVER', 'share-properties':
{'cifs-share-properties': 'browsable'}, 'vserver': 'testVserver',
'volume': 'testroot', 'path': '/', 'share-name': 'admin$',
'vscan-fileop-profile': 'standard', 'max-connections-per-share':
'4294967295'}
{'cifs-server': 'TESTVSERVER', 'share-properties':
{'cifs-share-properties': 'changenotify'}, 'acl': {'string':
'BUILTIN\\Administrators / Full Control'}, 'vserver': 'testVserver',
'volume': 'testroot', 'path': '/', 'share-name': 'c$',
'symlink-properties': {'cifs-share-symlink-properties': 'enable'},
'vscan-fileop-profile': 'standard', 'max-connections-per-share':
'4294967295'}
{'cifs-server': 'TESTVSERVER', 'share-properties':
{'cifs-share-properties': 'browsable'}, 'vserver': 'testVserver',
'volume': 'testroot', 'path': '/', 'share-name': 'ipc$',
'vscan-fileop-profile': 'standard', 'max-connections-per-share':
'4294967295'}
On 10/29/2015 3:08 PM, Rue, Randy wrote:
> No need for any apology, I'm grateful for any guidance at all, especially when you're doing actual work to try to figure this out for me.
>
> If I do need to specify the vserver that might explain why I get an empty return when I get a return at all. Will noodle with that. Also going to ask our NA representation about the API doc file for 1.30.
>
> Will keep you posted on any progress...
>
> Randy
>
> -----Original Message-----
> From: Payne, Richard [mailto:richard.payne@amd.com]
> Sent: Monday, October 26, 2015 1:56 PM
> To: Rue, Randy; 'toasters@teaparty.net'
> Subject: RE: python API guidance for cluster mode CIFS share reporting/management
>
> So I just tried some of this myself and the bad news is we don't have CIFS licenses. I tried running 'cifs-share-get-iter' (from perl) and it ran with success but of course returned nothing.
>
> " Also, the guidance I'm finding seems to revolve around viewing things on the cluster. At some point I'm also going to need to know how to change them"
>
> There's a cifs-share-modify, just keep in mind that works at the vserver context so you'll have to run a set_vserver on the NaServer object to change the context to the vserver.
>
> You may also want to try that for the cifs-share-get-iter call, the DOCs say it works under the cluster vserver context but not sure what it would return in cluster context (I assume all CIFS shares but I could be wrong there).
>
> Sorry I can't be of more help....
>
> --rdp
>
> -----Original Message-----
> From: Rue, Randy [mailto:rrue@fredhutch.org]
> Sent: Thursday, October 22, 2015 11:40 AM
> To: Payne, Richard; 'toasters@teaparty.net'
> Subject: RE: python API guidance for cluster mode CIFS share reporting/management
>
> I'm running the 5.4 SDK, maybe (likely) this is a user (me) problem resulting from contact with a new API, XML. Etc.
>
> Can I break down a few weird things I'm seeing and hopefully you can point out what newbie thing I'm missing?
>
> When I first connect to the 8.3 cluster using ZEDI I get a warning "API Version: Ontapi 1.30 Cluster-Mode not listed. Please select the API Document manually." Is the cluster running a newer version than ZEDI? I can see where to select API documents in the ZEDI interface, and that 1.21 is the latest version offered for cluster-mode, and where to import a file for new documents. I can't find any sign online of where to get a file like what they appear to be looking for, or anything resembling it in the zip file I downloaded for the SDK.
>
> If I drill down to cifs-->cifs-share-get-iter, right-click and Generate, and then Execute, first I get an error in the XML output "<results reason='Invalid integer value for max-records: (null)' errno='13115' status='failed'/>"
>
> I can take the python from the Develop tab and run it in an IDE (after pasting in the password in text, yee-haw, I'll switch to cert authentication if this ever goes live), I get the same error in my output.
>
> If I plug in a value for max-records i.e. 10000 to the XML, in the XML tab I get what looks like a healthy return but with 0 records returned. But if I run the python code in my IDE I get "<results status="failed" errno="1" reason="Extra content at the end of the document "></results>"
>
> Also, the guidance I'm finding seems to revolve around viewing things on the cluster. At some point I'm also going to need to know how to change them.
>
> So how many glaring green oversights are listed above?
>
> Hope to hear from you,
>
> Randy
>
>
>
> -----Original Message-----
> From: Payne, Richard [mailto:richard.payne@amd.com]
> Sent: Thursday, October 22, 2015 5:40 AM
> To: Rue, Randy; 'toasters@teaparty.net'
> Subject: RE: python API guidance for cluster mode CIFS share reporting/management
>
> Hello,
>
> I've done a fair amount of work with the SDK though mostly using Perl, just started playing with Python. I guess the first thing is has this been fixed in the latest SDK release (5.4)? That post looks a couple of years old and there haves been a couple of SDK releases since then. I think technically 5.4 is to support 8.3.1 but it might be worth testing it.
>
> --rdp
>
> -----Original Message-----
> From: toasters-bounces@teaparty.net [mailto:toasters-bounces@teaparty.net] On Behalf Of Rue, Randy
> Sent: Wednesday, October 21, 2015 6:12 PM
> To: 'toasters@teaparty.net'
> Subject: python API guidance for cluster mode CIFS share reporting/management
>
> Hello All,
>
> I'm working on automating the synchronizing of CIFS shares on the vservers of one 8.3 cluster to their DR mirrors on another cluster. It occurs to me that this might be useful to other shops so I'm trying to up my game from my usual fairly sloppy code i.e. http://xkcd.com/1513/ with lots of SSH calls to the CLI and parsing text output sequentially, to something portable and standard enough to share.
>
> Taking a look at the SDK/API with ZEDI as a guide to the objects involved and having a tough time getting started (never used much XML either). To make things muddier, the API I'm looking at "cifs-share-get-iter" apparently has a bug (http://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/Anyone-successfully-using-the-cifs-share-get-iter-API/td-p/73664) that I don't totally get. Maybe if I could understand the object as it's supposed to work first.
>
> Any experience with the API? Looks like it's a few years old, is it used with 8.3?
>
> Hope to hear from you,
>
> Randy in Seattle
>
>
>
>
> _______________________________________________
> Toasters mailing list
> Toasters@teaparty.net
> http://www.teaparty.net/mailman/listinfo/toasters
>
> _______________________________________________
> Toasters mailing list
> Toasters@teaparty.net
> http://www.teaparty.net/mailman/listinfo/toasters