Update CoresPerSocket using REST and or Powershell


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="" xmlns:ovf="" xmlns:rasd="" xmlns:vmw="" xmlns:xsi="" xmlns:vcloud="" vcloud:href="https://xxxxxxx/api/vApp/vm-1b260fa7-5c45-4b7d-87f1-10de84443faa/virtualHardwareSection/cpu" vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" xsi:schemaLocation="">


    <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>


    <rasd:Description>Number of Virtual CPUs</rasd:Description>


    <rasd:ElementName>2 virtual CPU(s)</rasd:ElementName>












    <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"/>





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)"






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.


0 Kudos
0 Replies