HP OneView Deployment and Management Guide 1.10
Technical white paper | HP OneView Deployment and Management Guide
150
The HP OneView PowerShell library is a self-contained module that you first need to import, or add to your PowerShell
Session Profile. After the module has been successfully imported, you must first execute Connect-HPOVmgmt in order to
authenticate to the appliance. You can then execute other cmdlets to perform the desired action.
1. Execute Import-Module HPOneView
A. Example:
PS C:\Users\User> Import-Module HPOneView
Welcome to the HP OneView POSH Library, v1.06.95906
---------------------------------------------------
To get a list of available CMDLETs in this library, type : Get-Help hpov
To get help for a specific command, type: get-help [verb]-HPOV[noun]
To get extended help for a specific command, type: get-help [verb]-HPOV[noun] –full
Module sample scripts are located at:
C:\Users\User\WindowsPowerShell\Modules\HPOneView\Samples
If you need further help, please consult one of the following:
• Get-Help about_HPOneView
• Oneline documentation at https://hponeview.codeplex.com/documentation
• Oneline Issues Tracker at https://hponeview.codeplex.com/workitem/list/basic
Copyright (C) 2014 Hewlett-Packard
2. Execute the Connect-HPOVmgmt CMDLET
A. Example
[HPONEVIEW]: [Not Connected] PS> Connect-HPOVmgmt -appliance appliance.example.com –user
Administrator –password hp1nvent
[HPONEVIEW]: administrator@appliance.example.com PS>
3. Once you have authenticated to the appliance, you can execute different CMDLETs provided by the library
A. Example
[HPONEVIEW]: administrator@appliance.example.com PS> New-HPOVNetwork –Type “Ethernet” –Name
“Blue” –VLANID 100
Creating Blue Ethernet Network
Accessing the ReST API with Python
Python comes with a few libraries that can complete REST requests like httplib2 and urllib2, these libraries are rather
difficult to use and require a lengthy learning curve. Another python library called "Requests" has solved the learning curve,
cleaned up REST requests and made them very easy to use. For a full comparison take a look at
http://isbullsh.it/2012/06/Rest-api-in-python/
This overview of using Python to create REST requests will feature the Requests library.
The full HP OneView Python Library can be found at https://github.com/HewlettPackard/python-hpOneView.
Requests
Requests (http://docs.python-requests.org/en/latest/) is an easy to use REST request Python library.
How to get Requests
To get requests follow the steps on the Requests website here: http://docs.python-
requests.org/en/latest/user/install/#install
The best method would be to use pip (the python package manager) to install requests:
> pip install requests
Creating and executing a request
To execute a request is very simple. First look at the following code:
uri = '/rest/login-sessions'
method = 'POST'
data = {