We are trying to modify the VM CPU Cores value using the vCloud Director PowerCLI and REST API. We have been successful in doing this for Number of CPUs and Memory assigned to a VM, but the same approach is not working for CPU Cores.
Our PowerShell code performs the following…this is simply a GET to extract and read the property values
# Retrieve VM CPU Information
$headers += @{"Authorization"="Basic $($EncodedPassword)"}
$headers += @{"Content-Type"="application/vnd.vmware.vcloud.rasdItem+xml"}
Write-Host "Getting CPU Info"
$resource = "/vApp/"
$task = "/virtualHardwareSection/cpu"
$url = $baseurl + $resource + $vmid + $task
Write-Host "URL:" $url
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method GET -WebSession $MYSESSION
The response from the GET is as follows…
<Item xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:href="https://xxxxxxx/api/vApp/vm-1b260fa7-5c45-4b7d-87f1-10de84443faa/virtualHardwareSection/cpu" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="http://www.vmware.com/schema/ovf http://www.vmware.com/schema/ovf http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://146.122.24.16/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>2 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>4</rasd:InstanceID>
<rasd:Reservation>0</rasd:Reservation>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>2</rasd:VirtualQuantity>
<rasd:Weight>0</rasd:Weight>
<vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket>
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml" href="https://xxxxxx/api/vApp/vm-1b260fa7-5c45-4b7d-87f1-10de84443faa/virtualHardwareSection/cpu"/>
</Item>
When we attempt to read the values of the 3 CPU properties with the following…
Write "CPU: " $response.Item.VirtualQuantity }
Write "Element Name: " $ response.Item.ElementName }
Write "Cores Per Socket: " $ response.Item.CoresPerSocket }
Writing out the VirtualQuantity and ElementName work fine. But, nothing is returned for CoresPerSocket.
When we attempt to update the response before sending back to vCD, we do the following. This works fine for Virtual Quantity and ElementName, but not CoresPerSocket.
# Update VM CPU Information in Response Object
$response.Item.VirtualQuantity = $cpuval
$response.Item.ElementName = $cpuval + " virtual CPU(s)"
$response.Item.CoresPerSocket=$cores
What is the approach (using REST and Powershell) necessary to read or update the CoresPerSocket value in the REST payload to be sent back with a PUT command.