HyperFlex API Python Scripts
Via the HyperFlex API Explorer, you can get your token and what is a nice script to get your token ?
Get Access Token Script
First you have to do is to get an Access Token.Via the HyperFlex API Explorer you can get a token, but this token changes every x hours. (HyperFlex DP 3.5 and higher)
Here is the script into small blocks :
Import libraries :
In the lab I don’t have a CA server, so I am going to disable the certificate error :
We need the username and password. If it’s not given as a parameter (unsafe), the script is going to ask for it :
Now we can ask for a token via the API :
When the result is a code 201 (Request has been fulfilled), show the token :
Let’s print an error if there was an error.
And this is the script for getting an Access Token from the HyperFlex Cluster.
Please be aware that this script is in python and that you need the 4 spaces at some lines to indent.
List the datastores of the HyperFlex Cluster
Here is a script to show the datastores of a certain HyperFlex cluster. In this example I am using a fixed ip address in the script, but you can do it with a parameter if you want.
Let’s do the request. you will see the token in the Authorization field below.
Instead of having the whole json file print out, we just want to have the name and the size :
Delete a datastore of the HyperFlex Cluster
For deleting a datastore, you will need to know the datastore id (DSID). To know this you first have to list all datastores. Search for the same name as the script is asking to the user and then delete the DSID.
Start with importing from some files:
Are there any argument in the script ?
Disable the certificate warnings :
Let’s list the datastore :
See if the script can find the datastore with the name and remember the DSID.
if stop == False:
Delelete the Datastore:
If the status is 200 (Successful), show this to the user.
This blog is just an example of how to List and Delete a Datastore. Creating a Datastore is with the same principles.
Use this as an example and create some awesome nice HyperFlex Python Scripts !