New to Isilon SDK

334 views
Skip to first unread message

Steve Bogdanski

unread,
Jan 23, 2017, 11:00:50 AM1/23/17
to Isilon Technical User Group
Hello,
I am running a couple of Isilon clusters (v7.2.1.4).  I just started playing with the Isilon SDK, looking at it for a couple of use cases (populating data about shares into our CMDB via python, controlling file share creation and modification via PowerShell automation).

I've been able to get some simple python scripts to execute and pull information from the cluster, but haven't had much luck manipulating that data.  Outside of printing the raw output ( using str() ), I can't seem to find an easy method to parse data.

As an example, if I pull recent data for ifs.percent.used I get

{'stats': [{'devid': 0,
            'error': None,
            'error_code': None,
            'key': 'ifs.percent.used',
            'values': [{'time': 1484382557, 'value': '79.93469004010353'},
                       {'time': 1484468970, 'value': '80.7195991986431'},
                       {'time': 1484555391, 'value': '81.38136878227196'},
                       {'time': 1484641808, 'value': '82.65750701554559'},
                       {'time': 1484728215, 'value': '80.79120664030835'},
                       {'time': 1484814628, 'value': '79.67643848241566'},
                       {'time': 1484901051, 'value': '81.09244951074712'}]}]}

But I haven't been able to pull out the "values", and store them separately (python dictionary).  I guess I am just having a hard time understanding how to manipulate the 

Does anyone have an useful resources that they can point me towards?  The results of my own search of been less then expected.

Peter Serocka

unread,
Jan 23, 2017, 11:20:22 AM1/23/17
to isilon-u...@googlegroups.com
The data is in JSON format — "Javascript object notation”.

Javascript has built-in functionality to convert
JSON texts into actual Javasscript objects.

For most other languages such conversions are
provides through bundled or separate libraries.

With Python, have a look at:

import json
python_data = json.loads (json_string)

JSON objects -> Python dict
JSON array -> Python list or tuple


hth

— Peter
> --
> You received this message because you are subscribed to the Google Groups "Isilon Technical User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to isilon-user-gr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


Steve Bogdanski

unread,
Jan 23, 2017, 3:39:48 PM1/23/17
to Isilon Technical User Group
What I had assumed, but I am not able convert the api response this way.

>>> import json
>>> import isi_sdk
>>> import urllib3
>>> urllib3.disable_warnings()
>>>
>>> # configure username and password
... isi_sdk.configuration.username = "*******"
>>> isi_sdk.configuration.password = "*******"
>>> isi_sdk.configuration.verify_ssl = False
>>>
>>> # configure host
... host = "https://**************:8080"
>>>
>>> api_client = isi_sdk.ApiClient(host)
>>> statistics_api = isi_sdk.StatisticsApi(api_client)
>>>
>>> key_ids = "ifs.percent.used"
>>> begin = "-604800"
>>>
>>> api_response = statistics_api.get_statistics_history(key=key_ids, begin=begin)
>>> print (api_response)
{'stats': [{'devid': 0,
            'error': None,
            'error_code': None,
            'key': 'ifs.percent.used',
            'values': [{'time': 1484641807, 'value': '82.65750701554559'},
                       {'time': 1484728214, 'value': '80.79120664030835'},
                       {'time': 1484814627, 'value': '79.67643848241566'},
                       {'time': 1484901050, 'value': '81.09244951074712'},
                       {'time': 1484987470, 'value': '82.29822225342822'},
                       {'time': 1485073882, 'value': '82.92465020796419'},
                       {'time': 1485160301, 'value': '83.33185846708719'}]}]}
>>>
>>> python_data = json.loads(api_response)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/json/__init__.py", line 348, in loads
    'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'StatisticsHistory'

Am I missing something?

Peter Serocka

unread,
Jan 23, 2017, 7:29:13 PM1/23/17
to isilon-u...@googlegroups.com
I have been using the Isilon Platform API before,
directly via HTTPS calls, not the Python SDK...

Seems the JSON response from the Isilon already
gets converted by statistics_api.get_statistics_history(…)
into a class object (not just a plain dict).

Try:


print (api_response.stats[0].devid)
print (api_response.stats[0].values[0].time)
etc...


— Peter

Steve Bogdanski

unread,
Jan 24, 2017, 9:51:18 AM1/24/17
to Isilon Technical User Group
Bingo, that did it!  I was coming to the same resolution, but you saved me some time :)

There are also function defined to convert to dictionary, .to_dict(), and string, .to_str().  Thanks for the help!
Reply all
Reply to author
Forward
0 new messages