Getting Started
This document describes how to use a Python based script and API keys to execute IWO API calls.
Summary steps
- Log in to an Intersight account that has the Account Administrator Role and generate API keys.
- Run the Python script and specify the API and payload.
Prerequisites
- Ensure Python is installed in your system.
- Download and install Python, if necessary.
- We recommend using a virtual environment to run the script.
Base URI
Every API request will begin with the following Base URI.
Copyhttps://intersight.com
Setup
Create an
iwo-api
directory and initiate a python virtual environment within it.Code SnippetCopy
# Virtual Env Creation mkdir iwo-api ; cd iwo-api python3 -m venv iwo-api-shell source iwo-api-shell/bin/activate # For exiting out of virtual env deactivate
Install Intersight Python SDK:
pip3 install intersight
Generate an API key and private key from your Intersight account. The key is only displayed once.
Note: See Intersight API Overview and Generating API keys for more information.
- Go to https://intersight.com/an/settings/api-keys/ and log in to your account with the Account Administrator role.
- Click Generate API Key.
- Select OpenAPI schema version 3 and click Generate.
- Copy the API key ID to your clipboard for later use in step 4. Save the Secret key to a file. We recommend keeping it within the
iwo-api
directory created above. If you do this, set the file permission to read-only. For example:Code SnippetCopy
chmod 400 <Location of API secret key>
Copy the three script files into the
iwo-api
directory created above:Code SnippetCopy
* ``iwo-script.py`` * ``credentials.py`` * ``env.sh``
For example:
Code SnippetCopy
``` cp <Location of iwo-script.py> <Location of iwo-api directory> cp <Location of credentials.py> <Location of iwo-api directory> cp <Location of env.sh> <Location of iwo-api directory> ```
In the
env.sh
file, replace the sample values for the INTERSIGHT_API_KEY_ID__ and __INTERSIGHT_API_PRIVATE_KEY variables with the values got in step 3d.Source the
env.sh
file and execute theiwo-script
.The Settings PUT API is executed and changes the plan retention period to 90 days. The script also prints the new plan retention period.
Note: The
iwo-script.py
includes POST and GET API examples, which are commented out. You can modify the script to uncomment them and try executing the APIs.Code SnippetCopy
source env.sh python3 iwo-script.py --url=https://intersight.com
If successful, the output should be similar to the following:
Code SnippetCopy
{'uuid': 'planRetentionDays', 'displayName': 'Saved plans [Days]', 'value': '90.0', 'defaultValue': '14.0', 'valueType': 'NUMERIC', 'valueObjectType': 'String', 'min': 1.0, 'max': 365.0, 'scope': 'GLOBAL'}
About the downloadable script files
Use the following three Python script files (iwo-script.py
, credentials.py
, env.sh
) to execute the IWO API.
iwo-script.py
This script executes the API and requires that the IWO API endpoints are specified.
Note: The url=https://intersight.com flag specifies where to execute the API.
credentials.py
This script is used to authorize API calls made from iwo-script.py
.
env.sh
This requires the api key and private key generated from an intersight account specified as environment variables.
This script must be sourced before executing iwo-script.py
.