rhtyd commented on a change in pull request #1302: CLOUDSTACK-9104: VM naming 
convention in case vmware is used
URL: https://github.com/apache/cloudstack/pull/1302#discussion_r113886159
 
 

 ##########
 File path: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
 ##########
 @@ -2226,13 +2227,30 @@ int getReservedCpuMHZ(VirtualMachineTO vmSpec) {
         return new String[] {datastoreDiskPath};
     }
 
-    // Pair<internal CS name, vCenter display name>
-    private Pair<String, String> composeVmNames(VirtualMachineTO vmSpec) {
-        String vmInternalCSName = vmSpec.getName();
-        String vmNameOnVcenter = vmSpec.getName();
-        if (_instanceNameFlag && vmSpec.getHostName() != null) {
-            vmNameOnVcenter = vmSpec.getHostName();
+    /**
+     * This method generates VM name for Vcenter and Cloudstack( when 
Hypervisor is VMware).
+     * It generates VM name according to  _instanceNameFlag setting.
+     *
+     * @param VirtualMachineTO
+     *        vmSpec
+     * @return Pair<internal CS name, vCenter display name>. A pair which 
contain 'internal CS name'  and
+     *         'vCenter display name'(vCenter knows VM by this name).
+     **/
+    protected Pair<String, String> composeVmNames(VirtualMachineTO vmSpec) 
throws CloudRuntimeException {
+
+        String vmInternalCSName = "";
+        String vmNameOnVcenter  = "";
+        if(vmSpec == null) {
+            throw new CloudRuntimeException("vmSpec is null");
         }
+
+        vmInternalCSName = vmNameOnVcenter = vmSpec.getName();
+        if (_instanceNameFlag && vmSpec.getType() == VirtualMachine.Type.User) 
{
+           String[] tokens = vmInternalCSName.split("-");
+           if(tokens.length<3) throw new 
InvalidParameterValueException("Invalid vmInternalCSName format: 
"+vmInternalCSName+" expected format : *-*-* (e.g -> i-x-y)"); // 
vmInternalCSName has format i-x-y-<instance.name>
+              vmNameOnVcenter = String.format("%s-%s-%s-%s", tokens[0], 
tokens[1], tokens[2], vmSpec.getHostName());
 
 Review comment:
   Should we validate here that tokens items are not null or empty; or we might 
get a vm name that has null in its name?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to