Greetings and welcome to our next article in the PowerCLI 5.8 series for the new vSphere Policy Based Management cmdlets. In today’s article we are going to dive right in and start building our own vSphere storage policies leveraging the new SPBM cmdlets within PowerCLI.
Before we begin though, if you have not yet had an opportunity to familiarize yourself with vSphere Storage Policy Based Management, here are a few key blog articles that can help you build a good foundation.
- vSphere Storage Policy Based Management Overview – Part 1
- vSphere Storage Policy Based Management Overview – Part 2
- vSphere PowerCLI 5.8 SPBM Walkthrough – Part 1: Introduction
VMware Hands on Labs
Here is a great tip brought to you by our friends at the VMware Hands on Labs. If you would like an excellent shortcut to getting “hands on” with the new vSphere Power CLI cmdlets try out the lab below:
Building a vSphere Storage Policy
Now we will demonstrate how to leverage the new PowerCLI cmdlets for vSphere Storage Policy Based Management to create vSphere Storage Policies that will be used to ensure the availability, performance, and provisioning requirements for our example virtual machine.
Example Provisioning Scenario
For our example today, we will use a simple provisioning scenario of a virtual machine with a single virtual disk we intend to place on a Virtual SAN datastore.
See here for more information on creating a vSphere Storage Policy for Virtual SAN using the vCenter web client.
1. Open PowerCLI and connect to vCenter:
1 |
Connect-VIServer -Server 192.168.100.1 -user corpAdministrator -password vmware |
Note: To obtain a full listing of commands and examples of the new PowerCLI 5.8 cmdlets for vSphere Policy Based Management you can use the following commands within the PowerCLI shell.
1 2 |
Get-Command "*Spbm*" Get-Help <enter_desired_cmdlet> -full |
2. Examining Storage Capabilities
Storage systems that use vStorage APIs for Storage Awareness (VASA) are represented by storage providers. Storage providers inform vCenter Server about specific storage devices, and present characteristics of the devices and datastores deployed on the devices as storage capabilities.
Storage capabilities outline the quality of service that the storage system can deliver. They guarantee that the storage system can provide a specific set of characteristics for capacity, performance, availability, redundancy, etc. SPBM is Each storage system has the potential to advertise multiple, vendor-specific, system-defined capabilities.
These vendor-specific storage capabilities appear in the Storage Policy-Based Management (SPBM) system. When you create a storage policy for your virtual machine(s), you reference these vendor-specific storage capabilities. The SPBM management service then directs the virtual machine to be placed on a datastore that complies with these capabilities.
To begin creating our own vSphere Storage Policy with PowerCLI, we need to first discover what storage capabilities are published by the storage provider for our datastore. Since there is only 1 datastore (vsanDatastore) in our example environment, we do not need to specify it on the command line. If more datastores were present, this command would output the capabilities for each datastore with a supported storage provider.
1 |
Get-SpbmCapability | Select Name,ValueType,Description | FL |
There are a number of options to format the output. I chose the PowerShell’s format-list cmdlet for this example.
Rule Sets within a vSphere Storage Policy are made up of individual rules that mirror the application’s storage requirements. Storage capabilities are published by Storage Providers and refer to what capabilities a storage system can offer for application consumption.
Each storage policy is not only a set of constraints that apply simultaneously but can also include alternative rule-sets that represent equally acceptable storage requirements. The virtual machine home files (.vmx, .vmsd, .nvram, .log, and so on) and the virtual disks (.vmdk) can even have separate storage policies.
Next we will want to choose a value for each capability that will match the application(s) with the capabilities of the datastore. The image to the left contains the rules that we will use in our example policy:
4. Creating our vSphere Storage Policy PowerCLI command string
We can use the following three cmdlets to form the complete command string we need to build our vSphere Storage Policy. Below each cmdlet are listed the properties we need to populate for our policy.
New-SpbmStoragePolicy | New-SpbmRuleSet | New-SpbmRule |
Name | Name | Capability |
RuleSet | AllOfRules |
4a) Single line format
Sometimes it helps me to understand the relationship between cmdlets in a longer command string by creating a single line format. Where possible I will include single line formats as well as multi-line formats for each of the examples in our series.
1 |
New-SpbmStoragePolicy –Name GoldPolicy –RuleSet (New-SpbmRuleSet –Name “GoldRuleSet” –AllOfRules @((New-SpbmRule –Capability VSAN.hostFailuresToTolerate 1)) |
4b) Multi-line Script form
Here we have the multi-line format where we leverage variables to assist in simplifying the command string.
1 2 3 4 5 |
$StoragePolicy = "GoldPolicy" $RuleSet = "GoldRuleSet" $Rule = (New-SpbmRule -Capability VSAN.hostFailuresToTolerate 1) $RuleSetRules = (New-SpbmRuleSet -Name $RuleSet -AllOfRules @(($Rule))) New-SpbmStoragePolicy -Name $StoragePolicy -RuleSet $RuleSet |
In the example above we have created 4 variables to help simplify our command string.
- $StoragePolicy: Enter the desired name for the vSphere Storage Policy.
- $RuleSet: Enter the desired name for the vSphere Storage Policy Rule Set.
- $Rule: Use a capability from the output of the Get-SpbmCapability cmdlet in step 2 along with a value to populate the capability property in the New-SpbmRule cmdlet.
- $RuleSetRules: Combine the rules created with the New-SpbmRule cmdlet into an array to populate the -AllOfRules property of the New-SpbmRuleSet cmdlet.
When we execute the command string, we will have a new policy created with the name “GoldPolicy”. We can now begin applying this policy to both new and existing virtual machines.
5) Validating Storage Policies
We can use the Get-SpbmStoragePolicy cmdlet to validate our newly created vSphere Storage Policy. In the example below we can see the vSphere Storage Policy name, the rules making up our Rule Set, as well as a number of other items that we can use for reporting and auditing purposes (There is much more to come on reporting and auditing).
Hopefully this article helps clarify not only the process to create a vSphere Storage Policy but also a bit of background on vSphere Storage Policy Based Management as well. We will be publishing many more articles and scripting examples in this series over the course of the next few weeks. Now you can start creating your very own vSphere Storage Policies through PowerCLI! Enjoy!
Resources
- vSphere Storage Policy Based Management Overview – Part1
- vSphere Storage Policy Based Management Overview – Part 2
- vSphere PowerCLI 5.8 SPBM Walkthrough – Part 1: Introduction
- Download and Install PowerCLI 5.8 Release 1
- Download and Install PowerCLI for vCD and vCloud Air Tenants 5.8 Release 1
- HOL-SDC-1427 – VMware Software Defined Storage: Module 5: Advanced Software-Defined Storage With SPBM and PowerCLI (30 minutes)
- VMware vSphere PowerCLI 5.8 Release 1 Cmdlet Reference
- VMware PowerCLI Blog: 5.8 Release 1 Announcement
- VMware vSphere PowerCLI 5.8 Release 1 Release Notes
- VMware PowerCLI 5.8 Release 1 Changelog
- VMware PowerCLI Community Pages
- Storage Policy Based Management (SPBM) Configuration Maximums (2062751)