This blog originally published in 2016.
A question I have seen more than once is:
“I understand connecting and getting basic information, but what if I want to pull statistics or more advanced information from the array besides what the default commands? The API glossary for the toolkit doesn’t say explicitly how I can get the information I want”
In short, just because the Python glossary doesn’t explicitly say how to do something or even if you can, it does not mean you can’t. It really depends on what the REST API can do.
Let me explain.
If you go to our API glossary you can see the list of commands supported in our Python toolkit. As you might notice, it is a bit different than our PowerShell SDK for instance. While they both use our REST API to communicate with the array, the Python toolkit has less abstraction of the specific REST calls, meaning the syntax looks and follows exactly how our REST needs it. For the most part, there is one Python command for each specific GET, PUT, POST etc REST high-level command. PowerShell has switches etc to change it’s command structure. If we run the get_volume command with just the volume name will get you the basic information:
1 2 |
<span style=“text-decoration: underline;”>Python Command: </span>array.get_volume(“myvolume”) |
1 2 3 |
<span style=“text-decoration: underline;”>JSON Response: </span>{‘source’: None, ‘serial’: ‘5BF1C41FE35945C400011094’, ‘size’: 10995116277760L, ‘name’:‘myvolume’, ‘created’: ‘2016-06-28T01:09:15Z’ } |
But that is not the only option for that command. If you look at the REST API guide you can see what else the GET volume REST call supports. The guide is built into your FlashArray GUI (click on the help button in the upper-right).
So if you go to the volume call you can see what it supports. Additional options like snapshots, space information, performance, etc.
So how do they get passed? The default call does not include any parameters. How can I add them? Well if you look at the Python guide, you will see a second parameter entry for putting in additional parameters:
1 |
get_volume</code><span class=“sig-paren”>(</span><em>volume</em>, <em>**kwargs</em><span class=“sig-paren”>)</span><a class=“reference internal” href=“https://pythonhosted.org/purestorage/_modules/purestorage.html#FlashArray.get_volume”><span class=“viewcode-link”>[source]</span></a> |
Return a dictionary describing a volume or snapshot.
Parameters: |
|
---|---|
Returns: |
A list describing snapshots of the volume if the paramater snap is passed as True, else a dictionary describing the volume. |
Return type: |
dict or list |
You will also notice the API glossary also tells you which API call to look at in the REST guide. So figure out which parameter you want to add and put it in the call. So if I want additional space detail, I would add space=true. Though, I cannot type it exactly like that, you need to enter the value in quotes like: space=”true. My volume name is just “myvolume”.
Python Command:
1 |
array.get_volume(“myvolume”,space=“true”) |
JSON Response:
1 2 |
{‘name’: myvolume‘, ‘system‘: None, ‘snapshots‘: 0, ‘total_reduction‘: 26.32162155418513, ‘volumes‘: 411738871808L, ‘data_reduction‘: 1.077714314109616, ‘total‘: 411738871808L, ‘shared_space‘: None, ‘thin_provisioning‘: 0.9590559300500899, ‘size‘: 10995116277760L} |
What if you want more than one parameter? Just add them comma separated. So if I want historical space/capacity information from the last hour, I would run this:
Python Command:
1 |
<span style=“text-decoration: underline;”>array.get_volume(“myvolume”,space=“true”,historical=“1h”)</span> |
JSON Response (excerpt):
1 2 |
[{‘name’: ‘myvolume’, ‘system’: 0, ‘snapshots’: 0, ‘total_reduction’: None, ‘volumes’: 411737860096L, ‘time’: ‘2016-07-06T17:15:05Z’, ‘data_reduction’: 1.077696047285853, ‘total’: 411737860096L, ‘shared_space’: 0, ‘thin_provisioning’: None, ‘size’: 10995116277760L}, etc... |
So just because the API glossary doesn’t explicitly list a feature of the command, it does not mean you cannot do it. This architecture of the toolkit allows you to leverage new REST features that might be introduced after the toolkit.