PowerCLI and VVols Part III: Getting VVol UUIDs from the FlashArray

The next step if you want to do correlation between a VMware VVol VMDK pointer and its corresponding FlashArray volume using PowerCLI.

As a review, here are the previous posts in this series:

If you followed part 2, you now have your VVol UUID, so how do I correlate it to a volume? Well you could use the VM name and then look at the name of the volume and size, but this is not scientific, and certainly not exact.

The Easy Way

Use my PowerShell module!

Install it if you havent with:

install-module Cody.PureStorage.FlashArray.VMware

Then import it:

import-module Cody.PureStorage.FlashArray.VMware

Now connect to your FlashArray and vCenter: (note you need PowerCLI and the Pure Storage PowerShell SDK installed as well).

$fa = new-pfaarray -EndPoint <FlashArray> -Credentials (get-credential) -IgnoreCertificateError

connect-viserver -Server <vCenter>

Now get your VM:

$vm - get-vm <VM name>

Then get the disks:

$disks = $vm |get-harddisk

Then get the UUID from that disk:

$uuid = $disks[<index to disk you want>] | get-vvolUuidFromHardDisk

Then get the FlashArray volume:

get-faVolumeNameFromVvolUuid -vvolUUID $uuid -flasharray $fa

Full example:

import-module Cody.PureStorage.FlashArray.VMware
$fa = new-pfaarray -EndPoint flasharray-x70-a -Credentials (get-credential) -IgnoreCertificateError
connect-viserver -Server ac-vcenter-1
$vm = get-vm App01
$disks = $vm |get-harddisk
$uuid = $disks[0] | get-vvolUuidFromHardDisk
get-faVolumeNameFromVvolUuid -vvolUUID $uuid -flasharray $fa

Explaining the Details

So how does this work? Let me start with this: the FlashArray VVol implementation uses key/value tags for VVol information–we did not create a custom database for this stuff. Doing so is a step in the complexity direction–so we used something we already had: tags. The benefit of this, besides being flexible, is that they are stored with your volumes and their data, so there is no special database to backup/protect. Currently, tags are not really exposed to end users though. This is on purpose–we are still working on how to properly expose them in the GUI and how to handle some other parts around their use–so fully exposed tagging management is not quite ready.

But with that being said, we realized that the ability to pull this information was important. So this is available in our REST API.

Please note that the ability to pull tags from the FlashArray is still in tech preview, so the APIs or process to do so may change between now and when the tag feature is officially GA.

Eagle-eyed API document readers may notice this is not documented and they would be correct. I already make extensive use of tag retrieval in the VVol Workflow Package I wrote for vRO.

So how do you do it? Well in the body of certain REST calls to the array, you can query for tags. There are a few places to do this today. They are all GET calls (read-only data retrievals):

  • Get all of the tags for all volumes
  • Get tags for a specific volume
  • Get tags for all snapshots
  • Get tags for a specific snapshot
  • Get tags for a specific volumes snapshots

All of the REST calls are similar just with an additional parameter tags=true.

The call to get a volume information is like below:

GET https://pure01.example.com/api/1.14/volume

The call to get a volumes tags would be like below:

GET https://pure01.example.com/api/1.14/volume?tags=true

The response is returned in JSON and you would see the tags returned.

A tag has three parts:

  • Value: this is the actual data you want to pull out.
  • Name: this is the name of the object the tag is assigned to, so either a snapshot or a volume
  • Key: this is the name of the tag.

So how do I pull this with PowerCLI, or rather PowerShell?

Like I said, since tags are still in tech preview it is not yet built into our PowerShell SDK to do this. So you need to it the old fashioned way at this point.

Directly authenticate with PowerShell and use invoke-restmethod. I’ve walked through authenticating here:

https://www.codyhosterman.com/2014/07/powershell-and-pure-storage-rest-api-scripting/ 

So check that out if you want to know how. At this point, I will assume you have authenticated and are ready to move on.


Note you might need to use both of these posts to connect depending on your certificate situation. If you get an error at retrieving the API token, look at these:

https://www.codyhosterman.com/2016/06/force-the-invoke-restmethod-powershell-cmdlet-to-use-tls-1-2/

https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error


So if I want to pull tags for all of the volumes now, I can use invoke-restmethod to get them. The command would look like this:

Invoke-RestMethod -Method Get -Uri "https://${purevip}/api/1.14/volume?tags=true" -WebSession $Session

When run, there will be a response with tags for all of the volumes (in this case). I will store it in a variable called $allTags:

$allTags = Invoke-RestMethod -Method Get -Uri "https://${purevip}/api/1.14/volume?tags=true"
-WebSession $Session

$allTags is an array of the tags. So $allTags[0] would return to me the first listing.

$allTags[0].key would give me the tag name (remember the name listing is the volume name, key is the name of the tag itself, i.e. key/value)

Now you can either parse this with PowerShell, or you can use our REST filtering. So if I want to find the volume with rfc4122.e09df235-ce50-4b27-9e64-201d577af6eb as the VVol UUID, I would change it to look like so:

Invoke-RestMethod -Method Get -Uri "https://${purevip}/api/1.14/volume?tags=true&filter=value='rfc4122.e09df235-ce50-4b27-9e64-201d577af6eb'" -WebSession $Session

In the filtering case the “name” column will contain the volume name you are looking for! You can then do what you need to with that volume (snapshot, report on, etc.).

6 thoughts on “PowerCLI and VVols Part III: Getting VVol UUIDs from the FlashArray”

  1. These posts are very helpful!

    One question I have is how can we map exactly vvols from the Pure side to the VMware side so that we can determine programmatically if there are orphaned volumes or volume groups?
    We can’t use # of connections for the volumes as it will show a count of 0 for normal situations where the vm is powered off. The volume group name may contain a partial piece of the original vm name which may have changed so that won’t do the trick.
    I am guessing the secret is the hex #s in the volume/volume group names but I have been unable to match them to anything meaningful.
    For example, one of our volume group names is vvol-0edtest-rhel7b-0ef6be94-vg. Can we correlate 0ef6be94 with something in vmware? Similarly, a volume in that group is called Config-1668c742, Can we correlate that string with something?

    Thanks and much appreciated,
    Ed

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.