Skip to content
Ravindhar Uppada edited this page Oct 6, 2020 · 19 revisions

Welcome to the HPE OneView Python SDK (oneview-python) wiki!

Introduction

HPE OneView makes it simple to deploy and manage today’s complex hybrid cloud infrastructure. HPE OneView can help you transform your data center to software-defined, and it supports HPE’s broad portfolio of servers, storage, and networking solutions, ensuring the simple and automated management of your hybrid infrastructure. Software-defined intelligence enables a template-driven approach for deploying, provisioning, updating, and integrating compute, storage, and networking infrastructure.

The HPE OneView Python library provides a pure Python interface to the HPE OneView REST APIs. It depends on the Python-Future library to provide Python 2/3 compatibility.

You can find the latest supported HPE OneView Python SDK here

Refer to


Installation

HPE OneView SDK for Python can be installed automatically through any of the installation methods described below.

1. From Source

Either:

$ git clone https://github.com/HewlettPackard/oneview-python.git
$ cd oneview-python
$ python setup.py install --user  # to install in the user directory (~/.local)
$ sudo python setup.py install    # to install globally

Or if using PIP:

$ git clone https://github.com/HewlettPackard/oneview-python.git
$ cd oneview-python
$ pip install .

2. From Pypi

$ git clone https://github.com/HewlettPackard/oneview-python.git
$ cd oneview-python
$ pip install hpeOneView

3. From Docker Image / Container

Running Examples with local docker container

If you'd rather run the examples in a Docker container, you can use the Dockerfile at the top level of this repo. All you need is Docker and git (optional).

  1. Clone this repo and cd into it:

    $ git clone https://github.com/HewlettPackard/oneview-python.git
    $ cd oneview-python

    Note: You can navigate to the repo url and download the repo as a zip file if you don't want to use git.

  2. Build the docker image: $ docker build -t oneview-python .

    Note: If you're behind a proxy, please edit the Dockerfile before building, uncommenting/adding the necessary ENV directives for your environment.

  3. Now you can run any of the example in this directory:

    # Run the container, passing in your credentials to OneView and specifying which example recipe to run.
    # -v : The volume on which repo code is mounted
    # Replace "connection_templates" with the name of the example you'd like to run
    # Replace "pwd" with the path of the example file you'd like to run.
    
    $ docker run -it --rm \
      -v $(pwd)/:/root/oneview/
      python examples/connection_templates.py

That's it! If you'd like to modify a example, simply modify the example file (on the host), then re-run the image.

Running Examples with published docker image

We also provide a lightweight and easy way to test and run oneview-python. The hewlettpackardenterprise/hpe-oneview-sdk-for-python:<tag> docker image contains an installation of oneview-python installation you can use by just pulling down the Docker Image:

The Docker Store image tag consist of two sections: <sdk_version-OV_version>

# Download and store a local copy of hpe-oneview-sdk-for-python and
# use it as a Docker image.
$ docker pull hewlettpackardenterprise/hpe-oneview-sdk-for-python:v5.2.0-OV5.2

# Run docker commands and this will in turn create
# a sh session where you can create files, issue commands and execute the tests
$ docker run -it hewlettpackardenterprise/hpe-oneview-sdk-for-python:v5.2.0-OV5.2 /bin/sh

All above installation methods work if you are using virtualenv, which you should be!


Configuration

1. JSON:

Connection properties for accessing the OneView appliance can be set in a JSON file.

Before running the samples or your own scripts, you must create the JSON file. An example can be found at: OneView configuration sample.

Note: If you have an active and valid login session and want to use it, define the sessionID in the Credentials. When sessionID is defined, you can remove username and password from your JSON (they will be disregarded anyway).

Once you have created the JSON file, you can initialize the OneViewClient:

oneview_client = OneViewClient.from_json_file('/path/config.json')

🔒 Tip: Check the file permissions because the password is stored in clear-text.

2. Environment Variables:

Configuration can also be defined through environment variables:

# Required
export ONEVIEWSDK_IP='172.16.102.82'

export ONEVIEWSDK_USERNAME='Administrator'
export ONEVIEWSDK_PASSWORD='secret123'
# Or sessionID
export ONEVIEWSDK_SESSIONID='123'

# Optional
export ONEVIEWSDK_API_VERSION='800'
export ONEVIEWSDK_AUTH_LOGIN_DOMAIN='authdomain'
export ONEVIEWSDK_SSL_CERTIFICATE='<path_to_cert.crt_file>'
export ONEVIEWSDK_PROXY='<proxy_host>:<proxy_port>'
export ONEVIEWSDK_CONNECTION_TIMEOUT='<connection time-out in seconds>'

Once you have defined the environment variables, you can initialize the OneViewClient using the following code snippet:

oneview_client = OneViewClient.from_environment_variables()

🔒 Tip: Make sure no unauthorized person has access to the environment variables, since the password is stored in clear-text.

Note: If you have an active and valid login session and want to use it, define the ONEVIEWSDK_SESSIONID. When a sessionID is defined, it will be used for authentication (username and password will be ignored in this case).

3. Dictionary:

You can also set the configuration using a dictionary. As described above, for authentication you can use username/password:

config = {
    "ip": "172.16.102.82",
    "credentials": {
        "userName": "Administrator",
        "password": "secret123"
    }
}

or if you have an active and valid login session and want to use it, define the sessionID in the Credentials:

config = {
    "ip": "172.16.102.82",
    "credentials": {
        "sessionID": "123"
    }
}

oneview_client = OneViewClient(config)

🔒 Tip: Check the file permissions because the password is stored in clear-text.

4. Logging for Troubleshooting:

This module uses Python’s Standard Library logging module. An example of how to configure logging is provided on /examples/logger.py.

More information about the logging configuration can be found in the Python Documentation.

5. SSL Server Certificates:

To enable the SDK to establish a SSL connection to the HPE OneView server, it is necessary to generate a CA Cert file containing the server credentials.

  1. Fetch the HPE OneView Appliance CA certificate.
$ openssl s_client -showcerts -host <host> -port 443
  1. Copy the server certificate wrapped with a header line and a footer line into a <file_name>.crt file.
-----BEGIN CERTIFICATE-----
... (HPE OneView Appliance certificate in base64 PEM encoding) ...
-----END CERTIFICATE-----

When using HPE Image Streamer, the server certificate for the HPE Image Streamer should also be added to the certificates file. Example:

-----BEGIN CERTIFICATE-----
... (HPE OneView Appliance certificate in base64 PEM encoding) ...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
... (HPE Image Streamer Appliance certificate in base64 PEM encoding) ...
-----END CERTIFICATE-----
  1. Declare the CA Certificate location when creating a config dictionary.
config = {
    "ip": "172.16.102.82",
    "credentials": {
        "userName": "Administrator",
        "password": "secret123"
    },
    "ssl_certificate": "/home/oneview-python/my_ov_certificate.crt"
}

6. Proxy Setting:

If your environment requires a proxy, define the proxy properties in the JSON file using the following syntax:

  "proxy": "<proxy_host>:<proxy_port>"

OR export the ONEVIEWSDK_PROXY environment variable:

export ONEVIEWSDK_PROXY='<proxy_host>:<proxy_port>'

7. Setting your OneView version:

The OneView Python SDK now supports the API endpoints for HPE OneView 5.00, 5.20, 5.30, 5.40

The current default HPE OneView version used by the Python SDK will pick the OneView appliance API version. To use a different API, you must set the API version on the OneViewClient configuration, either using the JSON configuration:

"api_version": "1600"

OR using the Environment variable:

export ONEVIEWSDK_API_VERSION='1600'

If this property is not specified, it will fall back to the default value as per OneView appliance.

The API list is as follows:

  • HPE OneView 5.00 API version: 1200
  • HPE OneView 5.20 API version: 1600
  • HPE OneView 5.30 API version: 1800
  • HPE OneView 5.40 API version: 2000

8. HPE Synergy Image Streamer:

The OneView Python SDK also supports the API endpoints for HPE Synergy Image Streamer. To configure the SDK for Image Streamer, you must set the Image Streamer IP on the OneViewClient configuration, either using the JSON configuration:

"image_streamer_ip": "100.100.100.100"

OR using the Environment variable:

export ONEVIEWSDK_IMAGE_STREAMER_IP='100.100.100.100'

To create the ImageStreamerClient, you must call the create_image_streamer_client method from the pre-existent OneViewClient instance. Through the created ImageStreamerClient, you are able to access the API Clients of the Image Streamer resources:

image_streamer_client = oneview_client.create_image_streamer_client()

build_plans = image_streamer_client.build_plans.get_all()

You can find more usage examples in the folder /examples/image_streamer

9. OneView Connection Timeout:

By default the system timeout is used when connecting to OneView. If you want to change this, then the timeout can be set by either:

  1. Setting the time-out in the JSON configuration file using the following syntax:
"timeout": <timeout in seconds>

or

  1. Setting the appropriate environment variable:
export ONEVIEWSDK_CONNECTION_TIMEOUT='<connection time-out in seconds>'

10. Exception handling:

All exceptions raised by the OneView Python SDK inherit from HPEOneViewException.

HPEOneViewException has the following properties:

  • msg - a string containing the error message sent by the OneView REST API;
  • oneview_response - contains the entire JSON data dictionary with error details that are returned by the OneView Python SDK. It can be: None.
Exception Handling example:
try:
    fc_network_client = oneview_client.fc_networks
    fc_network = fc_network_client.get_by_name(name)
except HPEOneViewException as e:
    print(e.msg)
    if e.oneview_response:
    	pprint(e.oneview_response)

For compatibility purposes, the Exception args property is defined with the error arguments. For example:

except Exception as e:
	print(arg[0]) # e.msg equivalent
    print(arg[1]) # e.oneview_reponse equivalent

Getting Help - How can I get help & support

Are you running into a road block? Have an issue with unexpected behavior? Feel free to open a new issue on the issue tracker

When creating an issue, recommend providing the following and any additional information which would help address quicker.

Scenario/Intent

[What you are trying to achieve but can't?]

Environment Details

  • OneView SDK Version: [Version of this SDK for which you are encountering the issue]
  • OneView Appliance Version: [Version of the OneView appliance you're interacting with]
  • OneView Client API Version: [API version of your client object]
  • Ruby Version: [Version of Python in your environment]
  • Platform: [OS distribution and release version]

Steps to Reproduce

[What are the complete steps needed to do in order to reproduce your problem?]

Expected Result

[What do you expect to happen after taking the steps above?]

Actual Result

[What actually happens after the steps above? Include error output or a link to a gist.]


Additional Resources

SDKs for HPE OneView

HPE OneView Documentation on the HPE Enterprise Information Library

HPE OneView Community

Learn more about HPE OneView at hpe.com/info/oneview


License

This project is licensed under the Apache license. Please see LICENSE for more information.


Version and Changes

To view history and notes for this version, view the Changelog