3535import com .vmware .vim25 .AlreadyExistsFaultMsg ;
3636import com .vmware .vim25 .ClusterDasConfigInfo ;
3737import com .vmware .vim25 .ComputeResourceSummary ;
38+ import com .vmware .vim25 .CustomFieldStringValue ;
3839import com .vmware .vim25 .DatastoreSummary ;
3940import com .vmware .vim25 .DynamicProperty ;
4041import com .vmware .vim25 .HostConfigManager ;
@@ -577,8 +578,14 @@ public boolean createVm(VirtualMachineConfigSpec vmSpec) throws Exception {
577578 }
578579
579580 public HashMap <String , Integer > getVmVncPortsOnHost () throws Exception {
581+
582+ int key = getCustomFieldKey ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
583+ if (key == 0 ) {
584+ s_logger .warn ("Custom field " + CustomFieldConstants .CLOUD_VM_INTERNAL_NAME + " is not registered ?!" );
585+ }
586+
580587 ObjectContent [] ocs = getVmPropertiesOnHyperHost (
581- new String [] { "name" , "config.extraConfig[\" RemoteDisplay.vnc.port\" ]" }
588+ new String [] { "name" , "config.extraConfig[\" RemoteDisplay.vnc.port\" ]" , "value[" + key + "]" }
582589 );
583590
584591 HashMap <String , Integer > portInfo = new HashMap <String , Integer >();
@@ -592,14 +599,15 @@ public HashMap<String, Integer> getVmVncPortsOnHost() throws Exception {
592599 for (DynamicProperty objProp : objProps ) {
593600 if (objProp .getName ().equals ("name" )) {
594601 vmName = (String )objProp .getVal ();
602+ } else if (objProp .getName ().startsWith ("value[" )) {
603+ if (objProp .getVal () != null )
604+ vmInternalCSName = ((CustomFieldStringValue )objProp .getVal ()).getValue ();
595605 } else {
596606 OptionValue optValue = (OptionValue )objProp .getVal ();
597607 value = (String )optValue .getValue ();
598608 }
599609 }
600- VirtualMachineMO vmMo = new VirtualMachineMO (_context , oc .getObj ());
601- // Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
602- vmInternalCSName = vmMo .getCustomFieldValue (CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
610+
603611 if (vmInternalCSName != null && isUserVMInternalCSName (vmInternalCSName ))
604612 vmName = vmInternalCSName ;
605613
0 commit comments