The Pure Storage PowerShell SDK presents opportunities to automate tasks in a variety of different applications, services and tools. In this post, I want to provide a simple example of how to leverage the PowerShell SDK with Microsoft System Center 2012 Orchestrator. Unless you are using the Microsoft System Center suite of products you may not be familiar with Orchestrator so I’ll take a moment to explain it briefly. Orchestrator is a workflow management solution for the data center. Orchestrator lets you automate the creation, monitoring, and deployment of resources in your environment. For more information read the following Microsoft TechNet article on Orchestrator. Using Orchestrator along with the Pure Storage PowerShell SDK could provide some interesting scenarios to automate Dev/Test operations for example.
Now with a basic understanding of Orchestrator let’s look at an example of using the PowerShell SDK within Orchestrator. There are a # of different Activities that come out of the box with Orchestrator which we will leverage to create this simple Runbook. The two Activities we will use are Initialize Data and Run .Net Script. Initiate Data is required for all Run Book’s which as it states initiates the orchestrations.
In the Initiate Data step I have setup five parameters:
- Username — User name to login into the FlashArray. I use the built in pureuser account.
- Password — Password for user name.
- Volume — Volume to create a snapshot.
- Suffix – Suffix of the snapshot.
- FlashArray — DNS or IP Address of the Pure Storage FlashArray
To setup the Runbook perform the following steps.
Open the Runbook Control Activities tile and drag-n-drop the Initialize Data activity onto the Runbook design canvas. When a new Runbook is created and an activity is placed on the design canvas it will ask to checkout the Runbook, choose Yes.
Double-click the Initialize Data activity to customize the properties of the activity. We first start with setting up the General properties. Customize the Name and Description.
Next we add the different parameters described earlier. Notice all of the data types are of type String.
Leave the Run Behavior options to their default settings. We are now finished setting up the Initialize Data activity and will move into the Run .Net Script activity.
Just as we did with the Initialize Data activity, open up the System activities tile and select the Run .Net Script. Drag and drop this activity onto the design canvas. It does not matter where you drop it but it is best to place near the Initialize Data step as we will be connecting these activities in a few more steps.
Now we have two activities that we will be working with on the design canvas. The Initialize Data activity has the parameters defined that will be published to the newly added Run .Net Script activity.
Let’s start configuring the activity by double-clicking to open up the properties dialog. First enter a custom name and description.
In the Script field enter in the following PowerShell script:
$Session = New-PSSession -ComputerName localhost
$ReturnArray = Invoke-Command -Session $Session -ScriptBlock
Import-Module -Name PureStoragePowerShellSDK
$username = “USERNAME-PLACEHOLDER"
$pwd = ConvertTo-SecureString -String “PASSWORD-PLACEHOLDER" -AsPlainText -Force
$Creds = New-Object System.Management.Automation.PSCredential ($username, $pwd)
$FlashArray = New-PfaArray -EndPoint “FLASHARRAY-PLACEHOLDER" -Credentials $Creds –IgnoreCertificateError
New-Item -Path 'C:TempOrchestrator-Log.txt' -ItemType 'File'
New-PfaVolumeSnapshots -Array $FlashArray -Sources “VOLUME-PLACEHOLDER" -Suffix “SUFFIX-PLACEHOLDER" | Add-Content -Path 'C:TempOrchestrator-Log.txt'
You will notice there are some VARIABLE-PLACEHOLDER in the above PowerShell script which will be filled out in the next step. Don’t worry about entering any script or references in those placeholders that is shown in the Step 6 screenshot.
By default, the Run .Net Script activity runs scripts with Windows PowerShell 2.0; this lacks many of the new features found in PowerShell 3.0, 4.0 and 5.0. So in order to workaround this limitation a New-PSSession is created on the server which hosts the Runbook and will execute in the latest version of PowerShell installed on the host.
Before we are able to consume Published Data the Run .Net Script activity needs to be connected or subscribed to the Initialize Data activity. On the Runbook design canvas select the Initialize Data activity. When the mouse hovers over the activity you will notice a small arrow on the right side of the activity. Using the mouse start dragging that arrow to the Run .Net Script activity to create a connection between both of the activities. See the screenshot below for an example connecting both activities.
With the Initialize Data and Run .Net Script connected the script can consume the Published Data from the Initialize Data activity. Double-click the Run .Net Script to open up the activity and then click on the Details to view the PowerShell script inserted in Step 6. This can be a little tricky as you need to place your cursor between the quotation marks (“ “) and then right-click to insert Published Data.
- Right-click to insert between the quotation marks (eg. $username = “<PLACE CURSOR>”)
- Click Subscribe
- Click Published Data
- Select the appropriate Published Data item, for example choose the Username for the $username variable. Repeat this step for all of the other four VARIABLE-PLACEHOLDER spots in the PowerShell script. Each Published Data name corresponds to a variable placeholder.
- After all of the Published Data variables have been added to the script you should see the following:
The next step is to test the newly created Runbook using the Runbook Tester tool provided by Orchestrator.
The Runbook Tester can be used to view the individual activity variables or associated scripts. Think of the Runbook Tester as a debugger. The screenshots below shows the two activities and the properties that can be viewed.
Run on the toolbar to execute the Runbook. The first action of the Runbook is to collect the variables defined in the Initialize Data activity. Enter the variable information as appropriate for the environment.
After entering the variables click OK to execute the activities.
As seen in the Log section both activities completed successfully! Checking the Pure Storage FlashArray we can see that for the TEST-VOLUME a snapshot named TEST-VOLUME.SCO has been created.
This is a very simple example of what can be achieved using the Pure Storage PowerShell SDK and System Center 2012 Orchestrator.