Search our Blogs
Showing results for 
Search instead for 
Do you mean 
 

PowerShell-defined infrastructure at your fingertips!

 

PowerShell-defined infrastructure at your fingertips!

 

 

In previous articles (First steps with programming the HPE Composable Infrastructure API, Authenticating against HPE Composable Infrastructure API and Surviving in the Schema… while running our first inventory), we used POSTman to experiment with the Composable Infrastructure API. We then reused some of these learnings, to script some automation using cURL ("cURL-ing" through the HPE Composable Infrastructure API) in a Linux Shell script. We also managed to do the same on Windows but it required a little more "patience". Well, here is the good news. For Windows there is a far better solution to script and automate a HPE Composable Infrastructure, and it uses Windows PowerShell.

 

Windows PowerShell is THE Command Language Interface (CLI) and scripting language unanimously adopted by all Windows administrators for several reasons including:

 

  • Its standard and normalized syntax. PowerShell uses the syntax of verb-noun to interact with the system. You use the Get verb to query and provide the object noun to specify the resource. For example, Get-Process returns list of processes, Get-EventLog returns list of event logs. To create new resources, you use the verb new, to update, you use the verb set…. You learn the syntax once and apply the same pattern for different resources[1]

  • Its extensibility. By default, Windows PowerShell provides commands or precisely Cmdlets to interact with the OS. Microsoft also provides a rich set of libraries to interact with other components of Windows such as Active Directory, DHCP, network... Libraries are packaged as modules and administrators simply import the modules to get access to Cmdlets related to components. For example, to get a list of Active Directory users, you can run Get-ADuser; to get a list of disk volumes you can use Get-Volumes. Going further, any Microsoft product is shipped with its own PowerShell module and as a result, Windows PowerShell can be seen as a management platform rather than just a rigid CLI.

On that trend, HPE provides an HPE OneView PowerShell module, which consists of a set of script functions exported as Cmdlets. Script functions wraps PowerShell code around the REST API and hides the complexity of using REST API to interact with HPE OneView. Windows administrators now can use their familiar syntax to interact with HPE Oneview, for example Get-HPOVNetwork, get-HPOVServer and so on.

 

Installing the HPE OneView PowerShell module

 

The HPE OneView PowerShell library is an HPE Open Source project that is hosted on GitHub.

 

image001.gif

 

The easiest way to install the PowerShell library is to select and download the installer to run. The Installer provides digitally signed assets and verifies system requirements. You can also download the repository (zip or tar.gz), which will only contain the library components, and it is up to the administrator to put the library into the required directory and validate that their system meets the requirements. Once it is installed, you can use it in your PowerShell environment (interactive or script) using an import-module command:

 

import-module hponeview.200

 

image002.gif

 

Looking for help?

 

We can check what this library offers with the following command:

 

get-command -module hponeview.200

 

There is a long list of commands available. You can get more details on a given Cmdlet using the help command:

 

help connect-hpovmgmt

 

image003.gif

 

Connect…

 

Let us try this immediately

 

Connect-HPOVMgmt 213.30.139.22:37441 -username administrator -password password

 

image004.gif

 

And start scripting!

 

Once connected we can use the different Cmdlets to start automating an HPE Composable Infrastructure from PowerShell. For example, let us gather versions:

 

Get-HPOVVersion

Get-HPOVVersion -ApplianceVer

 

image005.gif

 

As we did in previous articles using POSTman or cURL, let us now retrieve the enclosures managed in this HPE Composable Infrastructure using:

 

Get-HPOVEnclosure

 

image006.gif

 

We can also retrieve the list of servers available:

 

Get-HPOVServer

 

image007.gif

 

You can see that, the PowerShell library handles a lot of the hard work we had to do while programming directly against the REST API. The HPE OneView PowerShell library handles for us things such as HTTP Headers or JSON parsing.

 

We can always REST

 

However, what if we need to get something, which does not have a Cmdlet available yet? For example in our REST based inventory, we listed the datacenters managed by the HPE OneView appliance, but there is no GET-HPOVDatacenter in the HPE OneView Module. Well, there is a solution for this in the library, it is called Send-HPOVRequest, and it is a great way to access the REST API directly. Send-HPOVRequest is very similar to what we did with cURL in a previous article.

Let us use this to retrieve our datacenter list:

 

$datacenters=Send-HPOVRequest "/rest/datacenters"

$datacenters.count

1

$datacenters.members[0].name

 

image008.gif

 

We can use help Send-HPOVRequest to find out more about the Cmdlet, and this shows that the default verb is GET, but we can also use other HTTP verbs, for example let us say we want to change the currency property of our Sophia Antipolis datacenter from USD to Euros:

 

$datacenters.members[0].currency

USD

$datacenters.members[0].currency="Euros"

Send-HPOVRequest $datacenters.members[0].uri "PUT" $datacenters.members[0]

 

image009.gif

 

Feel like contributing?

 

Well, even better. If you think that instead of using Send-HPOVRequest, it would be better to write a CmdLet for GET-HPOVDatacenter, and you feel like doing it yourself, then you can contribute using the following procedure:

 

  • From GitHub, fork the repo
  • Make the code change to add your contribution
  • From GitHub, submit a Pull request for review

 

Beware with asynchronous operations

 

By design, HPE OneView is an asynchronous task-based system. Therefore, Cmdlets might initiate an asynchronous operation, and return immediately (this is documented in the CmdLet help). In these cases, it is best practice to retrieve that task object returned by the Cmdlet and use the Wait-HPOVTaskComplete to wait for task completion before moving on to the next step. For example, let us use this technique to create a new server profile:

 

New-HPOVServerProfile -name TestProfile -assignmentType 'unassigned' -serverhardwaretype "BL460c Gen8 1" -enclosuregroup "HPE Composable Infrastructure Enclosures" | Wait-HPOVTaskComplete

 

The sky is the limit!

 

Well, I hope I gave you enough details to get your attention so that you can start writing your own PowerShell scripts. We have also made available on the Wiki of the GitHub page, a number of sample scripts, so do not hesitate to leverage these as well. We will come back to some of these in upcoming articles.

Comments
Gary Stevens
| ‎07-08-2016 06:36 AM

Very Clear introduction for how to interact with HPE's management layer with PowerShell! A good read for a Friday

Christian Wörtz
| ‎12-27-2016 07:11 AM

Very nice, but how can I manipulate a remoteSupportUri?

 

PowerCLI> Search-HPOVIndex -Category datacenters -Search test


type : IndexResourceV300
name : Test
description :
attributes : @{derating_type=NaJp; derating_percentage=20.0; default_power_line_voltage=220; cooling_multiplier=1.5;
uuid=69b7193b-991c-432c-bfe1-39f1bf044d53; currency=}
multiAttributes :
ownerId : erm
state : Unmanaged
status : OK
created : 2016-12-27T15:57:49.291Z
modified : 2016-12-27T15:57:49.319Z
eTag : 2016-12-27T15:57:49.319Z
category : datacenters
uri : /rest/datacenters/69b7193b-991c-432c-bfe1-39f1bf044d53
applianceId : 2e339250-8c34-49cf-a5ef-75f556f4643f
scopeUris :
ApplianceConnection : @{ConnectionId=1; Name=appl.usa.com}

 

 

PowerCLI> Send-HPOVRequest (Search-HPOVIndex -Category datacenters -Search test).uri


width : 1000
depth : 1000
coolingCapacity :
costPerKilowattHour :
currency :
deratingType : NaJp
deratingPercentage : 20,0
coolingMultiplier : 1,5
contents : {}
remoteSupportUri : /rest/support/datacenters/69b7193b-991c-432c-bfe1-39f1bf044d53
defaultPowerLineVoltage : 220
uri : /rest/datacenters/69b7193b-991c-432c-bfe1-39f1bf044d53
created : 2016-12-27T15:57:49.291Z
eTag : 2016-12-27T15:57:49.297Z
modified : 2016-12-27T15:57:49.297Z
uuid : 69b7193b-991c-432c-bfe1-39f1bf044d53
status : OK
name : Test
id : 69b7193b-991c-432c-bfe1-39f1bf044d53
state : Unmanaged
category : datacenters
ApplianceConnection : @{ConnectionId=1; Name=appl.usa.com}

 


PowerCLI> Send-HPOVRequest (Send-HPOVRequest (Search-HPOVIndex -Category datacenters -Search test).uri).remoteSupportUri


type : DataCenterSupportSettings
primaryContactUri : /rest/support/contacts/2909312d-fcfe-4572-a625-85cd8073eaf8
primaryContactInheritedFrom :
secondaryContactUri :
secondaryContactInheritedFrom :
city : City
siteKey : 55cc29f0-8c88-4cd6-ba79-55085c5d29a3
streetAddress1 : Street 2
streetAddress2 :
provinceState : State
postalCode :
countryCode : US
timeZone : America/Anchorage
modified : 2016-12-27 15:59:50.23
eTag :
created : 2016-12-27 15:59:50.165
category : datacenters
uri : /rest/support/datacenters/69b7193b-991c-432c-bfe1-39f1bf044d53
ApplianceConnection : @{ConnectionId=1; Name=appl.usa.com}

chhiara marie
| ‎02-10-2017 03:52 PM

API chang ,119.30.39.93

Social Media
† The opinions expressed above are the personal opinions of the authors, not of HPE. By using this site, you accept the Terms of Use and Rules of Participation