[GitHub] rhtyd commented on a change in pull request #1302: CLOUDSTACK-9104: VM naming convention in case vmware is used
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 -private PaircomposeVmNames(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. A pair which contain 'internal CS name' and + * 'vCenter display name'(vCenter knows VM by this name). + **/ +protected Pair 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- + 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
[GitHub] rhtyd commented on a change in pull request #1302: CLOUDSTACK-9104: VM naming convention in case vmware is used
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_r113885986 ## File path: server/src/com/cloud/vm/UserVmManagerImpl.java ## @@ -3383,12 +3383,6 @@ protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOf hostName = generateHostName(uuidName); } } -// If global config vm.instancename.flag is set to true, then CS will set guest VM's name as it appears on the hypervisor, to its hostname. -// In case of VMware since VM name must be unique within a DC, check if VM with the same hostname already exists in the zone. Review comment: Instead of removing the check, does it make sense to amend it to verify that with the updated naming convention -- there are no duplicate VMs by 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
[GitHub] rhtyd commented on a change in pull request #1302: CLOUDSTACK-9104: VM naming convention in case vmware is used
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_r113885728 ## File path: plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/resource/VmwareResourceTest.java ## @@ -404,4 +410,46 @@ public void testConfigNestedHVSupportFlagFalse() throws Exception{ verify(vmMo, never()).getRunningHost(); } +@Test +public void testComposeVmNames() throws Exception{ Review comment: @priyankparihar please split the tests into multiple case methods, it's easier to debug failures. 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