Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

HPE OneView Python Lab Guide

Felipe Garcia Bulsoni edited this page Oct 11, 2017 · 4 revisions

Table of Contents generated with DocToc

❗️ NOTE: This 'HPE OneView Python LAB' document is outdated and may contain mentions to deprecated or removed scripts. Any specific information in it should be taken with a grain of salt. In case of divergences or doubts, verify the README for setup instructions, and the examples folder for examples on how to run each and every resource available to the SDK.

HPE OneView Python LAB

Objectives

This lab is designed to provide you with a basic understand of the HPE OneView Python library and the example scripts. After completing this lab, you will be able to identify and utilize the example scripts included with the OneView Python library to configure and support HPE OneView environments.

Description

In this lab, you will utilize the HPE OneView Appliance and the HPE OneView Python library and sample scripts to configure HPE OneView, networks, Interconnects, server profiles and more.

Prerequisites

It is expected that the following setup has been installed, prior to using this guide. NOTE: This guide was created for a use in a dedicated LAB environment with multiple hardware resources available. If you are using this guide in your own environment you might not have the exact type of hardware that is described in the section. However, the example of the script usage should still be a valid reference point. Please see Appendix A in this Lab guide for additional information.

  • Python 3.4.x installed and up to date
  • Notepad++ is installed
  • HPE OneView Appliance running and configured for use
  • Hardware that can be managed and monitored by the appliance (HPE C7000 Enclosure with Virtual Connect, ProLiant BL servers, ProLiant DL servers)
  • The HPE OneView Python library has been downloaded from GitHub and install

Exercise 1: Validating Pre-Requisite Installation

Description

This lab will validate the correct version of Python is installed, the python-hpOneView library with example scripts is installed and that the example scripts can connect to the running HPE OneView appliance.

Task 1. Validate Python version and connection to the HPE OneView Appliance

Open a command prompt and type python to validate that Python 3.4.x is installed and in the system path:

  1. This will launch the python interpreter and show the version. Type “exit()” and press return to exit back to the command prompt.

  2. If you get the message ‘python’ is not recognized as an internal or external interpreter see “Case 3” in the troubleshooting appendix.

    Windows Python Setup Screen

  3. Change directories to the location where you unpacked the example Python library, you should see a list of the available scripts as shown below.

    • cd C:\Users<UserName>\python-hpOneView\example\scripts:

    Windows Python Setup Screen

  4. Script usage information is provided for each script. In general each of the scripts accept the same base arguments. “-a -u -p ”.

  5. Validate that the scripts can connect and authenticate with the appliance using the get-xapi.py script, enter –a -u -p of the appliance via the command line arguments.

    Windows Python Setup Screen

  6. Execute additional example scripts;

    • a. get-health-status.py

      Windows Python Setup Screen

    • b. get-spp.py (NOTE: if you get an error displaying the output of this script see the troubleshooting appendix in this guide)

      Windows Python Setup Screen

Task 2. Optional: examine the HPE OneView user interface

In this task, you access the HPE OneView appliance from a browser and examine the user interface.

  1. Open a browser and specify the IP address or hostname of your HPE OneView appliance.

    Windows Python Setup Screen

  2. Specify your credentials and click Login.

    Windows Python Setup Screen

    The default page displayed is the Dashboard. This page provides an at-a-glance view of the configured elements and any alerts that may exist.

    Windows Python Setup Screen

  3. On the upper right side of the Dashboard page, click the Activity icon. At this time, there is not likely to be any activity displayed.

    Windows Python Setup Screen

  4. Click the Session icon.

    Your user ID and time logged in during this session appears.

    Windows Python Setup Screen

  5. Click the Help icon.

    You can browse help for this page, browse through the help guide, and access the HPE OneView forum.

  6. Click HPE OneView Forum.

    A second tab opens displaying various postings. Close the tab when done.

    Windows Python Setup Screen

  7. In the main menu, click the down arrow to view the choices.

  8. Click Settings.

    Windows Python Setup Screen

    A variety of information can be viewed and edited from this page including system-wide settings for the appliance, configuration of addresses and identifiers, and security settings.

    Windows Python Setup Screen

  9. Click Overview to view the drop-down menu.

    Windows Python Setup Screen

  10. Scroll down the listing to see the various options available.

    Windows Python Setup Screen

  11. Click any of the other options in the drop-down menu to see the settings and information available. Note the version of the OneView Appliance that you have installed.

  12. On the Settings page, click Actions on the right side to see the functions that are available. The Actions drop-down menu displayed is context sensitive; it will vary depending on the page you are on.

    Windows Python Setup Screen

Task 3. Locate the HPE OneView Python Library and Example Scripts

In this task, you will locate the HPE OneView Python Library and example scripts.

  1. Using Windows explorer, navigate to the python-hpOneView folder. At the top level there is a setup.py file that is used to install the python-hpOneView library on the system. The hpOneView folder contains the source code of the library itself and the examples folder contains the example scripts.

    Windows Python Setup Screen

  2. Using Windows explorer, navigate to the python-hpOneView\examples\scripts folder:

    Windows Python Setup Screen

    The example scripts in this folder serve two distinct purposes. First, they demonstrate at a python source code level how to use the OneView library. Second, they function as independent executable commands that can be used directly with no knowledge of Python. This lab focuses on the later functionality.

  3. Locate the build.bat file, right click on it and select edit with Notepad++

    Windows Python Setup Screen

  4. The buid.bat file demonstrates how some of the example scripts can be used to stand up a OneView environment. At the top of the file there are a few variables that need to be defined to match the environment that is going to be managed by HPE OneView.

    Windows Python Setup Screen

    Continue to scroll down through the build.bat script. After setting up the environmental variables the batch file starts by defining new Ethernet networks VLAN’s 10, 20, 30, 40, 50 and 60 in an Active/Active configuration using the define-ethernet-network.py example script. It does this with multiple calls to the script using a “for” loop. The important part to understand is that the define-ethernet-network.py script can be used to define new networks in HPE OneView. For example, to define an Ethernet network named VLAN-80 using a VLAN ID of 80:

    python define-ethernet-network.py -a <HOST> -u <USER> -p <PASS> -n VLAN-80 –v 80
    

    The define-ethernet-network.py example script can be used directly to add networks to OneView. The example build.bat file is simply a collection of examples that will build up a complete environment in OneView using the example python scripts. Continue to walk through the bat file and examine how it builds out the environment. Notice in each section a different example script is being used to perform a new task. The Windows batch file is simply being used to group multiple scripts together in order to demonstrate automating the scripting processes.

  5. Open a command prompt and locate the location where you unpacked the sample scripts;

    • C:\Windows<User>\Downloads\python-hpOneView\example\scripts
  6. Use the define-ethernet-network.py script to define a VLAN-80 as described above.

    Windows Python Setup Screen

  7. Use the web interface to access the networks section in HPE OneView to see that the new network has been defined.

    Windows Python Setup Screen

  8. Use the define-ethernet-network.py script to create a VLAN-90 with the Preferred Bandwidth set to 1GB and the Maximum bandwidth set to 4GB. (Hint: use the –h flag to see the script help)

Summary

During this lab exercise, you examined the structure of the example scripts and used a script to define new networks in HPE OneView.

Exercise 2: Automating HPE OneView via scripting with the example Windows build batch file.

Description

This lab will utilize the build.bat batch file to stand up a complete managed environment in HPE OneView.

Task 1. Edit build.bat using Notepad++

  1. Using Windows explorer, navigate to the python-hpOneView\examples\scripts folder. Locate the build.bat file, right click on it and select edit with Notepad++

    Windows Python Setup Screen

  2. This file needs to be modified to match the Lab environment.

    Windows Python Setup Screen

    Change the lines to match your environment including your username and password for your Enclosure OA's (ENC_USR and PASS), Your 3PAR storage (STO_USR and PASS) and your DL iLO credentials (SRV_USR and PASS):

    HOST=<ONEVIEW APPLIANCE IP>
    PASS=HP1nvent
    ENC_USR=<USERNAME>
    ENC_PASS=<PASSWORD>
    STO_USR=<USERNAME>
    STO_PASS=<PASSWORD>
    SRV_ADDR=<ProLiant DL ilO address>
    SRV_USR=<USERNAME>
    SRV_PASS=<PASSWORD>
    
  3. Open a command prompt and locate the location where you unpacked the sample scripts;

    • C:\Windows<User>\Downloads\python-hpOneView\example\scripts
  4. Run the build.bat file:

    Windows Python Setup Screen

  5. Running the bat file will take a while, make sure to watch the output to see the status of each of the steps.

  6. Use the HPE OneView web interface to see each of the elements being added.

    Windows Python Setup Screen

  7. The HPE OneView activity screen will show a live list of the activities

    Windows Python Setup Screen

  8. Once the build.bat file has completed you will have full environment, including Networks, Network Sets, Logical Interconnect Group, Enclosure Group, 3Par Storage, Enclosure, Blades, DL’s, Assigned and Unassigned Server profiles with provisioned storage, etc.

    Windows Python Setup Screen

  9. NOTE: A second batch file name clean.bat is also included with the example scripts. The clean.bat will REMOVE EVERYTHING from the HPE OneView appliance. DO NOT RUN the clean.bat file as part of this lab.

Exercise 3: Using Individual Scripts

Description

This lab will utilize the add-enclosure.py script to import an enclosure in Monitored mode. Task 1. Execute the Add Enclosure script to import the enclosure in monitored mode.

  1. From the command prompt in the example scripts directory run the “add-enclosure.py” script. This script will allow you to import an enclosure in either a Managed or Monitored state. The example in the build.bat file imports the enclosure as Managed You will need to supply the OA IP Address, and login details using the –oa , -eu , -ep and -m arguments. MAKE SURE TO USE the –m argument to import the enclosure in monitored mode.

  2. Import the enclosure into OneView using add-enclosure.py script

    Primary OA IP: <OA IP>
    Login: <USERNAME>
    Password: <PASSWORD>
    

    Windows Python Setup Screen

  3. Once the script has completed open the Web UI and verify that the new enclosure has been added. Tour around the Web interface and examine the differences between a Managed and a Monitored enclosure.

    Windows Python Setup Screen

Task 2. Get a List of Enclosures that are Managed or Monitored by HPE OneView

  1. From the command prompt in the example scripts directory run the “get-enclosure.py” script. Use this output to get the name of the monitored enclosure.

    Windows Python Setup Screen

  2. Run it again but this time use the –r argument. Many of the example scripts will display the full JSON output that was received directly from the appliance. Some, scripts also offer an argument that will format the output in a more human readable way as in the case with this example.

    Windows Python Setup Screen

Task 3. Remove the Monitored enclosure

  1. From the command prompt in the example scripts directory run the “del-enclosure.py” script. You will need the name of the Monitored enclosure that you found in task 2 above.

  2. Use the get-enclousre.py script to verify that the enclosure has been removed.

Task 4. Add a DL360 Gen 9 as a managed device

  1. From the command prompt in the example scripts directory run the “add-server.py” script. Use the iLO ip address of the server.

    Windows Python Setup Screen

Task 5. Add a DL380p Gen 8 as a monitored device

  1. From the command prompt in the example scripts directory run the “add-server.py” script. Use the iLO ip address of the server. Make sure to add it as monitored and not managed server!

    Windows Python Setup Screen

  2. Once the script has completed open the Web UI and verify that the new servers been added. Tour around the Web interface and examine the differences between a Managed and a Monitored server hardware!

Summary

During this lab exercise, you executed the add-enclosure.py script. This script imported a C7000 Enclosure and associated systems as monitored devices. The add-enclosure.py script can be used to add a c7000 Enclosure as either a Managed or a Monitored device. You also used the get-enclosure.py scrip to get a report to the enclosures that have been imported into HPE OneView. Next, you used the del-enclosure.py script to remove an enclosure from HPE OneView. Finally, you used the add-server.py script to import standalone/rack mount DL servers as both monitored and managed resources into HPE OneView.

Exercise 4: Create a Server profile

Description

This lab will utilize the define-profile.py script to create a server profile.

Task 1. Execute the define-profile.py script help

  1. From the command prompt in the example scripts directory run the “define-profile.py” script with the –h argument. Server profiles can be extremely complex because they can define everything from firmware levels, to network and storage connections, to local storage, to BIOS and boot order settings, and even contain the ability to automatically carve out LUNs on 3par storage, add the host to the storage system, setup the zoning through the fabric and present the LUN to the physical server. As such the define-profile.py script is the most complex example script. Examine the help output:

    Windows Python Setup Screen

Task 2. Use the define-profile.py script to create a DL server profile

  1. From the command prompt in the example scripts directory run the “define-profile.py” script. You will use the script to create a profile on the managed DL360 Gen 9 that was imported in Exercise 3 Task 4. The profile will manage the firmware using the SPP from Nov 2014 (you can use the get-spp.py script to get a list of the SPP’s that have been uploaded to the HPE OneView appliance) .

  2. Create the server profile in HPE OneView using define-profile.py script

    • Profile name: ESX1
    • iLO IP:
    • spp: bp-hp-service-pack-for-proliant-oneview-2014-11-30-05.iso

    Windows Python Setup Screen

  3. It will take a while to create this server profile since the firmware needs to be applied to the server. During this time, use the web GUI to explore the server profiles that were created via the build.bat.

Task 3. Use the define-connection-list.py and define-profile.py scripts to create a BL server profile with Ethernet connections and boot from SAN FC connections

  1. From the command prompt in the example scripts directory run the “define-connection-list.py” script. You will use the script to create a file that contains the connection definitions. The script needs to be run once for each connection. Run the script with the –h argument and examine the help output:

    Windows Python Setup Screen

  2. From the command prompt in the example scripts directory run the “define-connection-list.py” script. You will use this script to define four connections, two Ethernet connections using the network sets and two FibreChannel connections that were all created via build.bat. The network sets will bring down all of our VLANs to our host and the FC will provide our storage connectivity and the ability to boot from SAN.

  3. Create the server profile in HPE OneView using define-connection-list.py, the exact commands are (4 individual, single lines):

    python define-connection-list.py -a <host> -u Administrator -p HP1nvent -n "Prod-A" -net "Production-A" -func Ethernet -gbps 6 -cl connection.lst -i 1 -ns
    python define-connection-list.py -a <host> -u Administrator -p HP1nvent -n "Prod-B" -net "Production-B" -func Ethernet -gbps 6 -cl connection.lst -i 2 -ns -app
    python define-connection-list.py -a <host> -u Administrator -p HP1nvent -n "FC-A" -net "3PAR SAN A" -func FibreChannel -bp "Primary" -cl connection.lst -i 3 –app
    python define-connection-list.py -a <host> -u Administrator -p HP1nvent -n "FC-B" -net "3PAR SAN B" -func FibreChannel -bp "Secondary" -cl connection.lst -i 4 –app
    
  4. Using Windows explorer, navigate to the python-hpOneView\examples\scripts folder and use notepad++ to examine the connection.lst file that you just created. Ensure that there are four connections listed in the file but do not make any changes.

  5. From the command prompt in the example scripts directory run the “define-san-storage-list.py” script. You will use the script to create to define the LUNs to be created, presented and zoned. The script needs to be run once for each LUN. Run the script with the –h argument and examine the help output:

    Windows Python Setup Screen

  6. From the command prompt in the example scripts directory run the “define-san-storage-list.py” script. You will use this script to create a new boot LUN that is unique to each host and a connection to the existing “datastore1” share LUN.

  7. Create the server profile in HPE OneView using “define-san-storage-list.py, the exact commands are:

    python define-san-storage-list.py -a <host> -u Administrator -p HP1nvent -o VMware -n boot3 -sl san.lst -cl connection.lst
    python define-san-storage-list.py -a <host> -u Administrator -p HP1nvent -o VMware -n datastore1 -sl san.lst -cl connection.lst  -app
    
  8. From the command prompt in the example scripts directory run the “define-profile.py” script. You will use the script to create a profile on the BL460c Gen 8 in Enclosure 1 Bay 3 was imported via the build.bat.

  9. Create the server profile in HPE OneView using define-profile.py script

    • Profile name: Profile-Enc1Bay3
    • Server name: “Encl1, bay 3”
    • Connection list: connection.lst
    • SAN list: san.lst

    Windows Python Setup Screen

Summary

During this lab exercise, you executed the define-profile.py script. This script created a server profile and assigned it to the first available blade in the enclosure. Take some extra time and take a closer look at the code in the script that was used to create the server profiles.

Appendix A: Pre-Requisites installation

Task 1. Install version 3.4.x of the Python Interpreter

  1. Download the Windows Python 64-bit installer and run it to start the installation:

    https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi

  2. During the installation accept all of the defaults until the following screen comes up. Make sure to install the “Add python.exe to Path” feature.

    Windows Python Setup Screen

Task 2. Download and install the latest version of the Python library for HPE OneVew.

  1. Download the latest version of the Python library for HPE OneView from GitHub. When you download from this URL the current top of tree source will be downloaded. In other words if you download the file today and download it again tomorrow it may be different:

    https://github.com/HewlettPackard/python-hpOneView/archive/master.zip

  2. Unpack the python-hpOneView zip file that you downloaded

  3. Open a command prompt and cd to the directory where you unpacked the python-hpOneView.zip file and run the command “python setup.py install” to install the library.

Appendix B: Troubleshooting

Case 1. UnicodeEncodeError: ‘charmap’ codec can’t encode character

If you get an error that looks like this it is because the default Windows terminal is not set to display Unicode characters.

Windows Python Setup Screen

This can be resolved by changing the code page that is used for the console display by using the “Change Code Page” command in the command prompt “chcp 65001”. 65001 is Microsoft’s name for the UTF-8 character encoding scheme.

Windows Python Setup Screen

NOTE: Entering this command only temporarily changes the code page for this single instance of the command prompt. There is a registry entry that can be modified to make the default code page be UTF-8 instead of ASCII but that is beyond the scope of this document.

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.