5454import com .vmware .vim25 .BoolPolicy ;
5555import com .vmware .vim25 .ClusterDasConfigInfo ;
5656import com .vmware .vim25 .ComputeResourceSummary ;
57+ import com .vmware .vim25 .CustomFieldStringValue ;
5758import com .vmware .vim25 .DVPortConfigInfo ;
5859import com .vmware .vim25 .DVPortConfigSpec ;
5960import com .vmware .vim25 .DatastoreSummary ;
@@ -5740,10 +5741,16 @@ public PingCommand getCurrentStatus(long id) {
57405741
57415742 if (_recycleHungWorker ) {
57425743 s_logger .info ("Scan hung worker VM to recycle" );
5744+
5745+ int key = ((HostMO )hyperHost ).getCustomFieldKey ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
5746+ if (key == 0 ) {
5747+ s_logger .warn ("Custom field " + CustomFieldConstants .CLOUD_VM_INTERNAL_NAME + " is not registered ?!" );
5748+ }
5749+ String instanceNameCustomField = "value[" + key + "]" ;
57435750
57445751 // GC worker that has been running for too long
57455752 ObjectContent [] ocs = hyperHost .getVmPropertiesOnHyperHost (
5746- new String [] {"name" , "config.template" , "runtime.powerState" , "runtime.bootTime" });
5753+ new String [] {"name" , "config.template" , "runtime.powerState" , "runtime.bootTime" , instanceNameCustomField });
57475754 if (ocs != null ) {
57485755 for (ObjectContent oc : ocs ) {
57495756 List <DynamicProperty > props = oc .getPropSet ();
@@ -5757,6 +5764,10 @@ public PingCommand getCurrentStatus(long id) {
57575764 for (DynamicProperty prop : props ) {
57585765 if (prop .getName ().equals ("name" ))
57595766 vmName = prop .getVal ().toString ();
5767+ else if (prop .getName ().startsWith ("value[" )) {
5768+ if (prop .getVal () != null )
5769+ internalName = ((CustomFieldStringValue )prop .getVal ()).getValue ();
5770+ }
57605771 else if (prop .getName ().equals ("config.template" ))
57615772 template = (Boolean )prop .getVal ();
57625773 else if (prop .getName ().equals ("runtime.powerState" ))
@@ -5766,15 +5777,13 @@ else if(prop.getName().equals("runtime.bootTime"))
57665777 }
57675778
57685779 VirtualMachineMO vmMo = new VirtualMachineMO (hyperHost .getContext (), oc .getObj ());
5769- // Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
5770- internalName = vmMo .getCustomFieldValue (CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
5771-
57725780 String name = null ;
57735781 if (internalName != null ) {
57745782 name = internalName ;
57755783 } else {
57765784 name = vmName ;
57775785 }
5786+
57785787 if (!template && name .matches ("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" )) {
57795788 boolean recycle = false ;
57805789
@@ -6215,9 +6224,16 @@ private VirtualMachineGuestOsIdentifier translateGuestOsIdentifier(String cpuArc
62156224
62166225 private HashMap <String , State > getVmStates () throws Exception {
62176226 VmwareHypervisorHost hyperHost = getHyperHost (getServiceContext ());
6227+
6228+ int key = ((HostMO )hyperHost ).getCustomFieldKey ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6229+ if (key == 0 ) {
6230+ s_logger .warn ("Custom field " + CustomFieldConstants .CLOUD_VM_INTERNAL_NAME + " is not registered ?!" );
6231+ }
6232+ String instanceNameCustomField = "value[" + key + "]" ;
6233+
62186234 // CLOUD_VM_INTERNAL_NAME stores the internal CS generated vm name. This was earlier stored in name. Now, name can be either the hostname or
62196235 // the internal CS name, but the custom field CLOUD_VM_INTERNAL_NAME always stores the internal CS name.
6220- ObjectContent [] ocs = hyperHost .getVmPropertiesOnHyperHost (new String [] { "name" , "runtime.powerState" , "config.template" });
6236+ ObjectContent [] ocs = hyperHost .getVmPropertiesOnHyperHost (new String [] { "name" , "runtime.powerState" , "config.template" , instanceNameCustomField });
62216237
62226238 HashMap <String , State > newStates = new HashMap <String , State >();
62236239 if (ocs != null && ocs .length > 0 ) {
@@ -6238,13 +6254,15 @@ private HashMap<String, State> getVmStates() throws Exception {
62386254 powerState = (VirtualMachinePowerState ) objProp .getVal ();
62396255 } else if (objProp .getName ().equals ("name" )) {
62406256 name = (String ) objProp .getVal ();
6241- } else {
6257+ } else if (objProp .getName ().contains (instanceNameCustomField )) {
6258+ if (objProp .getVal () != null )
6259+ VMInternalCSName = ((CustomFieldStringValue )objProp .getVal ()).getValue ();
6260+ }
6261+ else {
62426262 assert (false );
62436263 }
62446264 }
6245- VirtualMachineMO vmMo = new VirtualMachineMO (hyperHost .getContext (), oc .getObj ());
6246- // Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
6247- VMInternalCSName = vmMo .getCustomFieldValue (CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6265+
62486266 if (VMInternalCSName != null )
62496267 name = VMInternalCSName ;
62506268
@@ -6276,8 +6294,14 @@ private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Ex
62766294 }
62776295 }
62786296 }
6297+
6298+ int key = ((HostMO )hyperHost ).getCustomFieldKey ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6299+ if (key == 0 ) {
6300+ s_logger .warn ("Custom field " + CustomFieldConstants .CLOUD_VM_INTERNAL_NAME + " is not registered ?!" );
6301+ }
6302+ String instanceNameCustomField = "value[" + key + "]" ;
62796303
6280- ObjectContent [] ocs = hyperHost .getVmPropertiesOnHyperHost (new String [] {"name" , "summary.config.numCpu" , "summary.quickStats.overallCpuUsage" });
6304+ ObjectContent [] ocs = hyperHost .getVmPropertiesOnHyperHost (new String [] {"name" , "summary.config.numCpu" , "summary.quickStats.overallCpuUsage" , instanceNameCustomField });
62816305 if (ocs != null && ocs .length > 0 ) {
62826306 for (ObjectContent oc : ocs ) {
62836307 List <DynamicProperty > objProps = oc .getPropSet ();
@@ -6290,16 +6314,17 @@ private HashMap<String, VmStatsEntry> getVmStats(List<String> vmNames) throws Ex
62906314 for (DynamicProperty objProp : objProps ) {
62916315 if (objProp .getName ().equals ("name" )) {
62926316 vmNameOnVcenter = objProp .getVal ().toString ();
6293- } else if (objProp .getName ().equals ("summary.config.numCpu" )) {
6317+ } else if (objProp .getName ().contains (instanceNameCustomField )) {
6318+ if (objProp .getVal () != null )
6319+ vmInternalCSName = ((CustomFieldStringValue )objProp .getVal ()).getValue ();
6320+ }
6321+ else if (objProp .getName ().equals ("summary.config.numCpu" )) {
62946322 numberCPUs = objProp .getVal ().toString ();
62956323 } else if (objProp .getName ().equals ("summary.quickStats.overallCpuUsage" )) {
62966324 maxCpuUsage = objProp .getVal ().toString ();
62976325 }
62986326 }
62996327 VirtualMachineMO vmMo = new VirtualMachineMO (hyperHost .getContext (), oc .getObj ());
6300- // Check if vmMo has the custom property CLOUD_VM_INTERNAL_NAME set.
6301- vmInternalCSName = vmMo .getCustomFieldValue (CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6302-
63036328 if (vmInternalCSName != null ) {
63046329 name = vmInternalCSName ;
63056330 } else {
0 commit comments