Getting Started

This document describes how to use a Python based script and API keys to execute IWO API calls.

Summary steps

  1. Log in to an Intersight account that has the Account Administrator Role and generate API keys.
  2. 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.

https://intersight.com

Setup

  1. Create an iwo-api directory and initiate a python virtual environment within it.

    # 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
    
  2. Install Intersight Python SDK:

    pip3 install intersight

  3. 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.

    1. Go to https://intersight.com/an/settings/api-keys/ and log in to your account with the Account Administrator role.
    2. Click Generate API Key.
    3. Select OpenAPI schema version 3 and click Generate.
    4. 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:
      chmod 400 <Location of API secret key>
      
  4. Download the IWO API scripts.

  5. Copy the three script files into the iwo-api directory created above:

     * ``iwo-script.py``
     * ``credentials.py``
     * ``env.sh``
    

    For example:

     ```
     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>
     ```
    
  6. 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.

  7. Source the env.sh file and execute the iwo-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.

    source env.sh
    python3 iwo-script.py --url=https://intersight.com
    

    If successful, the output should be similar to the following:

    {'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.

Download iwo-script.py

credentials.py

This script is used to authorize API calls made from iwo-script.py.

Download credentials.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.

Download env.sh