deepak_ashwath
VMware Employee
VMware Employee

How to find the storage of a VM in Cloud director

Hi All,

When I use the below command

Get-CIVM -OrgVdc "MyOrgVDC1", it lists all the VMs under the Organization VDC. And for each VM it gives the vCPU and Memory details.

I also want the storage of the VM, like each VM's storage, does any one have any idea how to get it ?

Thanks,

Deepak

0 Kudos
9 Replies
LucD
Leadership
Leadership

Thread moved to the vCloud Director PowerCLI community


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
deepak_ashwath
VMware Employee
VMware Employee

Thanks LuCD

0 Kudos
jake_robinson_b
Hot Shot
Hot Shot

Hi Deepak,

The VM harddisk quantity is a bit buried. You can find the storage for a particular harddisk of a particular VM like so:

$vm = get-civm

$hardware = $vm.ExtensionData.GetVirtualHardwareSection()

($hardware.Item | where {$_.resourcetype.value -eq "17"}).hostresource[0].anyattr[0]."#text"

If you are querying more than 1 VM, or a VM with more than 1 harddisk, you will have to modify this accordingly.

Cheers,

Jake

Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
deepak_ashwath
VMware Employee
VMware Employee

Thanks Jake, it would be very helpful if you can explain the above code, have you made use of vCloud APIs ?

From where did you get "GetVirtualHardwareSection", is it the vsphere power cli method ?

Thanks,

Deep

0 Kudos
jake_robinson_b
Hot Shot
Hot Shot

Hi Deepak,

The GetVirtualHardwareSection method is actually a REST method from the vCloud API:

https://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/operations/GET-VirtualHardwareSection.h...

I frequently use the REST API references:

1.5 - http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/index.html

5.1 - http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/right-pane.html

The PowerCLI team has turned most (if not all) of the REST methods into .NET methods found under the .extensiondata, or .NET view of the object. You can find all REST methods implemented with the following line of code. You can replace $vm with any vCloud object, and the extensiondata and methods will be different.

$vm.extensiondata | get-member -membertype method
Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
0 Kudos
jake_robinson_b
Hot Shot
Hot Shot

I suppose it would help if I told you how I actually found the disk capacity as well... Smiley Happy

The .NET objects do not match up 1:1 with what the API gives us as XML, so in this case it was easier to find it in the XML first, and then figure out where they put it in the .NET object.

The disk size happens to be in the OVF schema, which is referenced here:

http://www.vmware.com/support/vcd/doc/rest-api-doc-1.5-html/types/RasdItemsListType.html

which leads you to the XML schema definition:

http://schemas.dmtf.org/ovf/envelope/1/dsp8023.xsd

and then you can search for "VirtualDisk," which gives you the complex type with the capacity in it. Smiley Happy

<xs:complexType name="VirtualDiskDesc_Type">
        <xs:annotation>
            <xs:documentation>Type for virtual disk descriptor</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:any namespace="##other" processContents="lax" minOccurs="0"
                maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="diskId" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Identifier for virtual disk</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="fileRef" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Reference to virtual disk content. If not specified a
                    blank virtual disk is created of size given by capacity
                attribute</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="capacity" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation>Virtual disk capacity, can be specified as either an
                    xs:long size or as a reference to a property using ${property_name}.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="capacityAllocationUnits" type="xs:string" default="byte" use="optional">
            <xs:annotation>
                <xs:documentation>Unit of allocation for ovf:capacity. If not specified
                    default value is bytes. Value shall match a recognized value for the
                    UNITS qualifier in DSP0004.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="format" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Format of virtual disk given as a URI that identifies
                    the disk type</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="populatedSize" type="xs:long" use="optional">
            <xs:annotation>
                <xs:documentation>Estimated populated size of disk in
                bytes</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="parentRef" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>Reference to potential parent disk</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute namespace="##any" processContents="lax"/>
    </xs:complexType>

Once you know how the object is laid out, you can go back to the PowerCLI .NET object and discover where the capacity is fairly easily!

Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
0 Kudos
gary1012
Expert
Expert

I'm trying to follow this thread but am not grasping the XML schema extension. I understand the ExtensionData.GetVirtualHardwareSection but that only provides allocated storage. I'm trying to produce a report that included used disk space on all virtual disk per VM. This may be a dumb question but I'm wondering if it possible to use both standard PowerCLI cmdlets and vCloud cmdlets in the same script. Although get-civm | get-ciview and get-vm are very similar, get-vm has the ability to pull in UsedSpaceGB whereas get-civm does not. Since this is the case and I cannot figure out the XML schema extension, I thought it might possible to combine the two in a report. I've tried the script below but I'm getting a pipelining error.

$HostReport = @()

Get-CIVM | sort-object name | foreach ($_.name){

$Report = "" | select Hostname, Org, OrgVdc, Status, CpuCount, MemoryMB, Status, ProvisionedSpaceGB, UsedSpaceGB

$Report.Hostname = $_.Name

$report.Org = $_.Org

$report.OrgVdc = $_.OrgVdc

$report.Status = $_.Status

$report.CpuCount = $_.CpuCount

$report.MemoryMB = $_.MemoryMB

$report.Status = $_.Status

$report.ProvisionedSpaceGB = ($_|Get-VM).ProvisionedSpaceGB

$report.UsedSpaceGB = ($_|Get-VM).UsedSpaceGB

$HostReport += $Report

}

$HostReport | Export-Csv -Path c:\TEMP\vm-hw.csv -NoTypeInformation -UseCulture

Does anyone see any issues with the script or trying to combine get-civm and get-vm?

Community Supported, Community Rewarded - Please consider marking questions answered and awarding points to the correct post. It helps us all.
0 Kudos
jake_robinson_b
Hot Shot
Hot Shot

As long as you have admin access to both vCD and vSphere, you can relate objects between the two. Alan Renouf has a excellent explanation here: http://www.virtu-al.net/2013/03/08/relating-vcloud-director-to-vcenter-in-powercli/

You are correct in your assessment that the Get-CIVM cmdlet does not have used disk space. The vCloud API does not have it either, for that matter.

In regards to your code, check your foreach statement. You have foreach ($_.name), then the code block. Try removing the ($_.name)

Jake Robinson VCP, vExpert - geekafterfive.com - Twitter: @jakerobinson
0 Kudos
gautam_johar
Contributor
Contributor

0 Kudos