You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by gi...@git.apache.org on 2017/04/28 11:40:09 UTC

[GitHub] DaanHoogland commented on a change in pull request #1302: CLOUDSTACK-9104: VM naming convention in case vmware is used

DaanHoogland 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_r113907545
 
 

 ##########
 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:
   @rhtyd I don't mind "null" in a name as long as the name is not null or duplicate. (see your comment further on)
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services