We are encountering an issue while asigning policy to a VM using vSphere SDK.
Issue: at the time of un-registering a VM the VM loses its profile, while registering it again we wish to reapply the policy.
As per our understanding this can be done using re-configuring the VM. We tried to apply the policy to the VM at the time of reconfiguration using the property VirtualMachineDefinedProfileSpec.
Please find the code snippet for the same below:
l_VMConfSpec --> configuration specs for VM config specification.
ns2__VirtualMachineDefinedProfileSpec *pVDevProfileConfSpec2 = soap_new_ns2__VirtualMachineDefinedProfileSpec(m_vim.soap, -1);
pVDevProfileConfSpec2->profileData = soap_new_ns2__VirtualMachineProfileRawData(m_vim.soap, -1);
pVDevProfileConfSpec2->profileId = m_wsStoragePolicyId; //unique id of profile
l_VMConfSpec.vmProfile.push_back(pVDevProfileConfSpec2);
No error is returned from VMware at the time of reconfiguration.
Is this the correct way to assign profile to a VM?