0

I am currently trying to extract a list of VSAN Disk Group UUIDs using python with pyVmomi, however I cannot find the UUIDs anywhere.

I connect to vCenter and get the content and clusters. I have looked through both of them and have yet to find the Disk Group UUIDs. I have, however, found disk UUIDs for the cache and capacity disks. Has anyone else encountered this before, or am I looking in the wrong place? Any help is greatly appreciated.

from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect
import ssl
import json
import requests
si = None

# Disable SSL certificate verification
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.verify_mode = ssl.CERT_NONE

# Connect to vCenter server
server = 'myserver'
username = 'myusername'
password = 'mypassword'
si = SmartConnect(host=server, user=username, pwd=password, sslContext=context)

# Retrieve content and clusters
content = si.RetrieveContent()
clusters = content.rootFolder.childEntity[0].hostFolder.childEntity

for cluster in clusters:
    cluster_name = cluster.name

    # Retrieve the vSAN configuration
    host_info = cluster.configurationEx.vsanHostConfig

    #Get UUIDs for various elements, disk group tbd
    ssd_disk_uuids = []
    nonssd_disk_uuids = []
    disk_group_uuids = []
    for host_config in host_info:
        for disk_map in host_config.storageInfo.diskMapping:
            ssd_disk_uuids.append(disk_map.ssd.uuid)
            for nonssd in disk_map.nonSsd:
                nonssd_disk_uuids.append(nonssd.uuid)

UPDATE:

An update for anyone looking how to do this in the future: There's currently no good way to do this. The best way is to get the data from the performance metric as shown below:

def disk_group_uuids(cluster):
    vsanPerfSystem = vcMos['vsan-performance-manager']
    entityTypes = vsanPerfSystem.VsanPerfGetSupportedEntityTypes()
    # query interval, last 10 minutes -- UTC !!!
    endTime = datetime.utcnow()
    startTime = endTime + timedelta(minutes=-10)
    cluster_entities = ['disk-group']
    uuids = []
    for entities in entityTypes:
        if entities.name in cluster_entities:
            entitieName = entities.name
            labels = []
            for entity in entities.graphs:
                for metric in entity.metrics:
                        labels.append(metric.label)
            entity = '%s:*' % (entities.name)
            spec = vim.cluster.VsanPerfQuerySpec(
                endTime=endTime,
                entityRefId=entity,
                labels=labels,
                startTime=startTime
            )
            try:
                metrics = vsanPerfSystem.VsanPerfQueryPerf(
                    querySpecs=[spec],
                    cluster=cluster
                )
            except Exception as e:
                print("Caught exception : " + str(e))
                continue
            disk_group_uuid_list = []
            for metric in metrics:
                    device_uuid = (metric.entityRefId.split(":"))[1]
                    disk_group_uuid_list.append(device_uuid)
    return(disk_group_uuid_list)

0 Answers0