Getting IDs from VC VirtualMachine

Mindwatering Incorporated

Author: Tripp W Black

Created: 10/14 at 08:00 PM

 

Category:
VMWare
vRO - VCAC

Task:
Get the VM IDs or update/replace a couple of them.


The following VM's ID properties are useful for identification:

vm1:VC:VirtualMachine:
System.debug('VM1Props- name: ' + vm1.name);
System.debug('VM1Props- displayName: ' + vm1.displayName);
System.debug('VM1Props- biosId: ' + vm1.biosId);
System.debug('VM1Props- id: ' + vm1.id);
System.debug('VM1Props- instanceId: ' + vm1.instanceId);
System.debug('VM1Props- vimId: ' + vm1.vimId);
System.debug('VM1Props- moref: ' + vm1.moref);
System.debug('VM1Props- config.managedBy: ' + vm1.config.managedBy);
var vm1ExtraConfig = vm1.config.extraConfig;
var vm1MoiI = '';
if (vm1ExtraConfig != null) {
for each(var ecEntry in vm1ExtraConfig) {
var ecEntryKey = ecEntry.key;
var ecEntryValue = ecEntry.value;
if (ecEntryKey == 'viv.moid') {
vm1MoiID = ecEntryValue;
}
}
}
System.debug('VM1Props- vm1MoiID: ' + vm1MoiID);


vm2:VC:VirtualMachine:
System.debug('VM2Props- name: ' + vm2.name);
System.debug('VM2Props- displayName: ' + vm2.displayName);
System.debug('VM2Props- biosId: ' + vm2.biosId);
System.debug('VM2Props- id: ' + vm2.id);
System.debug('VM2Props- instanceId: ' + vm2.instanceId);
System.debug('VM2Props- moref: ' + vm2.moref);

VirtualMachineConfigSpec(vim.vm.ConfigSpec)
- uuid xsd:string
- - 128-bit SMBIOS UUID of a virtual machine represented as a hexadecimal string in "12345678-abcd-1234-cdef-123456789abc" format.

- guestId xsd:string
- - Short guest operating system identifier. (holds a moref ID)

- instanceUuid xsd:string
- - VirtualCenter-specific 128-bit UUID of a virtual machine, represented as a hexadecimal string. This identifier is used by VirtualCenter to uniquely identify all virtual machine instances in the Virtual Infrastructure environment, including those that may share the same SMBIOS UUID.
- - Normally, this property is not set by a client, allowing the Virtual Infrastructure environment to assign or change it when VirtualCenter detects an identifier conflict between virtual machines. This identifier can be modified even when a virtual machine is powered on. Clients can specify that vCenter Server reassign a new identifier by a providing an empty string. Reassigning the identifier is not allowed for Fault Tolerance virtual machines.

Note:
VM biosId = spec.uuid
VM instanceId = spec.InstanceUuid

Example of setting VM configuration values using the ConfigSpec and reconfigVM_Task:
var vm1Spec = new VcVirtualMarchineConfigSpec();
// viv.moid - options are an array containing the OptionValue object
var vm1UpdatedOptions = [];
var vm1NewOptionValue = new VcOptionValue;
vm1NewOptionValue.key = 'viv.moid';
vm1NewOptionValue.value_AnyValue = vm2MoiID;
vm1UpdatedOptions.push(vm1NewOptionValue);
// biosId
vm1Spec.uuid = vm2.biosId;
// uuid instanceId
vm1Spec.instanceUuid = vm2.instanceId;
vm1Task = vm1.reconfigVM_Task(vm1Spec);

var vm2Spec = new VcVirtualMarchineConfigSpec();
// biosId
vm2Spec.uuid = vm1.biosId;
// uuid instanceId
vm2Spec.instanceUuid = vm1.instanceId;
vm2Task = vm2.reconfigVM_Task(vm2Spec);




previous page