There are a variety of ways to assign and set a SPBM Policy to a VM. I recently put out a workflow package for vRO to everything PowerCLI VVols and Pure:
I also specifically blogged about assigning a policy to a VM with vRO:
How do you do this with PowerCLI?
Doing this in PowerCLI is fairly straight forward. There are a variety of cmdlets available that make this quite easy:
There are many more SPBM-related cmdlets, but for now let us focus on these.
Getting SPBM Configuration of a VM
The VM I want to assign a policy to is called “testvm”. So I will store that in $vm:
What is the current configuration of my VM now from a SPBM standpoint? What policies are currently assigned? What is the compliance?
The Get-SpbmEntityConfiguration cmdlet will do this! There are two parts of a VM that can have policy assigned to it, the home (config VVol) and its virtual disks (data VVols). The Get-SpbmEntityConfiguration cmdlet will return the storage policy assigned to those objects and its compliance. The object is checks depends on what object you pass into it.
If you pass a VM object into it, it will check the SPBM configuration of the home directory only.
If you pass in a hard disk or multiple hard disks you will get those. So the get-harddisk cmdlet can do that.
Store that in a variable and pipe it into Get-SpbmEntityConfiguration, or just include the cmdlet directly in the line and pipe the result into it:
You can also pass in both at once:
The key is, be explicit with the objects you want to check.
So as you can see, my VM home has the policy of “VVol No Requirements Policy” and so do my two virtual disks.
Checking SPBM Compliance
One of the great benefits of SPBM and PowerCLI VVols is the ability to not only set configuration, but ensure that configuration is still properly applied. This can be achieved through compliance checks.
Running a compliance check is done through the Get-SpbmEntityConfiguration, just like above. There is just one eccentricity you should be aware of.
There is a parameter to the cmdlet called “CheckComplianceNow”. When that is NOT added, the cmdlet will only return the latest compliance status. It does not actually check to see if the VM is still compliant.
If you add the CheckComplianceNow parameter, it will actually have vCenter ask the underlying array, is the storage still configured according to the assigned policy?
So my utterly profound thoughts:
- If you just want to retrieve the storage policy of the object, leave off the compliance parameter–there is no need to add it.
- If you want to check compliance, add it.
Pretty straight forward. The cmdlet does return the time stamp of the last compliance check if you need to know.
Getting SPBM Policies
You can list your storage policies like so:
If you want to filter by provider you can use the namespace parameter. So if I want to only find Pure Storage policies, you can use “com.purestorage.storage.policy”:
One of my policies is called FlashArrayVVol and all it says is that any VM or virtual disk assigned to it should be VVol-based and on any given FlashArray.
I will store this in a variable called $policy:
You can see the policy rules in the AnyOfRuleSets property:
Assigning a SPBM Policy
My virtual machine home and its two virtual disks currently have the default PowerCLI VVol policy. I want to assign them a new policy.
This is done via the Set-SpbmEntityConfiguration command. It works in a very similar way as Get-SpbmEntityConfiguration.
The main difference, is you do not pass in the VM or harddisks directly, you pass in their storage policy result, which is yielded by the Get-SpbmEntityConfiguration.
So I would store the Get-SpbmEntityConfiguration result in a variable I will call $vmConfig:
The key here again, is specify the configuration of every object you want to change. List the VM config and each hard disk config you want to change. If it is not listed, it will not be changed.
So let’s assign it a policy that just says, I want this VM to always be on VVol and a FlashArray. So the policy described in the previous section–“FlashArrayVVol” . My policy is still stored in $policy.
So I will pass my $vmConfig in and also my policy. You can pipe in the VM/harddisk configs, or add it with the configuration parameter.
This will set the policy to the VM and/or disks and return the new status.
Assigning a SPBM Policy and Replication Group
The above assigns a standard PowerCLI VVol SPBM policy. But if you use a “replication” type policy, you also need to set a replication group (consistency group). For a FlashArray perspective, this means that you are using a VM storage policy that has either a local snapshot capability, or a replication capability.
In other words, the policy uses the namespace “com.purestorage.storage.replication”
If I assign this policy, I need to also assign a replication group. From a FlashArray perspective, this is what we call a “protection group”. It is a array consistency group that has a local snapshot policy and/or a replication policy.
Though you can’t just assign any replication group–it has to be one that adheres to that policy.
This can be identified also fairly easily.
The policy I want to assign requires that my storage be configured with a local snapshot interval of 1 hour and a remote replication interval of 1 hour. I called this policy “1 hour rep one hour snap”.
I stored that in my $policy variable.
Next I can pipe that to the cmdlet get-spbmreplicationpolicy. This will return all replication groups that are compliant with that policy.
I will then store the result in $repGroups. I can now assign this to my VM. Using the same method as the previous section, but adding the replication group. I want to add it to my “gold” group, so I will pass only that in by indexing to that part of the variable $repGroups ($repGroups)
I can now assign the policy and the replication group:
We can see in the vSphere Web Client that the VM is fully configured with the policy and the replication group:
If we look at the array itself, we can see the corresponding volumes are in the FlashArray protection group with a 1 hour replication policy and a 1 hour snapshot policy
That’s it for the first post! I will be digging into a lot more with PowerCLI and SPBM and VVols quite soon. Stay tuned.