rhtyd closed pull request #2645: config-drive: use hostname of VM instance of 
internal VM id
URL: https://github.com/apache/cloudstack/pull/2645
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/api/src/com/cloud/network/NetworkModel.java 
b/api/src/com/cloud/network/NetworkModel.java
index 35a6a63a992..a5bf5e44610 100644
--- a/api/src/com/cloud/network/NetworkModel.java
+++ b/api/src/com/cloud/network/NetworkModel.java
@@ -73,7 +73,7 @@
             AVAILABILITY_ZONE_FILE, "availability_zone",
             LOCAL_HOSTNAME_FILE, "hostname",
             VM_ID_FILE, "uuid",
-            INSTANCE_ID_FILE, "name"
+            PUBLIC_HOSTNAME_FILE, "name"
     );
 
     static final ConfigKey<Integer> MACIdentifier = new 
ConfigKey<Integer>("Advanced",Integer.class, "mac.identifier", "0",
@@ -313,7 +313,7 @@
     boolean getNetworkEgressDefaultPolicy(Long networkId);
 
     List<String[]> generateVmData(String userData, String serviceOffering, 
long datacenterId,
-                                  String vmName, long vmId, String vmUuid, 
String guestIpAddress, String publicKey, String password, Boolean isWindows);
+                                  String vmName, String vmHostName, long vmId, 
String vmUuid, String guestIpAddress, String publicKey, String password, 
Boolean isWindows);
 
     String getValidNetworkCidr(Network guestNetwork);
 
diff --git 
a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java 
b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 6cf9452add1..5135c0fde79 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -2525,7 +2525,7 @@ private void orchestrateMigrateWithStorage(final String 
vmUuid, final long srcHo
                     final String serviceOffering = 
_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), 
vm.getServiceOfferingId()).getDisplayText();
                     boolean isWindows = 
_guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
 
-                    vmData = 
_networkModel.generateVmData(userVm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getId(),
+                    vmData = 
_networkModel.generateVmData(userVm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(),
                             vm.getUuid(), defaultNic.getMacAddress(), 
userVm.getDetail("SSH.PublicKey"), (String) 
profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
                     String vmName = vm.getInstanceName();
                     String configDriveIsoRootFolder = "/tmp";
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java 
b/server/src/com/cloud/network/NetworkModelImpl.java
index 60b21c382eb..31cdf914d5f 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -2346,7 +2346,7 @@ public boolean getNetworkEgressDefaultPolicy(Long 
networkId) {
 
     @Override
     public List<String[]> generateVmData(String userData, String 
serviceOffering, long datacenterId,
-                                         String vmName, long vmId, String 
vmUuid,
+                                         String vmName, String vmHostName, 
long vmId, String vmUuid,
                                          String guestIpAddress, String 
publicKey, String password, Boolean isWindows) {
 
         DataCenterVO dcVo = _dcDao.findById(datacenterId);
@@ -2361,11 +2361,11 @@ public boolean getNetworkEgressDefaultPolicy(Long 
networkId) {
         }
         vmData.add(new String[]{METATDATA_DIR, SERVICE_OFFERING_FILE, 
StringUtils.unicodeEscape(serviceOffering)});
         vmData.add(new String[]{METATDATA_DIR, AVAILABILITY_ZONE_FILE, 
StringUtils.unicodeEscape(zoneName)});
-        vmData.add(new String[]{METATDATA_DIR, LOCAL_HOSTNAME_FILE, 
StringUtils.unicodeEscape(vmName)});
+        vmData.add(new String[]{METATDATA_DIR, LOCAL_HOSTNAME_FILE, 
StringUtils.unicodeEscape(vmHostName)});
         vmData.add(new String[]{METATDATA_DIR, LOCAL_IPV4_FILE, 
guestIpAddress});
 
         String publicIpAddress = guestIpAddress;
-        String publicHostName = StringUtils.unicodeEscape(vmName);
+        String publicHostName = StringUtils.unicodeEscape(vmHostName);
 
         if (dcVo.getNetworkType() != DataCenter.NetworkType.Basic) {
             if (publicIp != null) {
diff --git 
a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java 
b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
index cc1df935388..585b443557b 100644
--- a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
+++ b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
@@ -381,7 +381,7 @@ private boolean updateConfigDrive(VirtualMachineProfile 
profile, String publicKe
             final String serviceOffering = 
_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), 
vm.getServiceOfferingId()).getDisplayText();
             boolean isWindows = 
_guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
 
-            List<String[]> vmData = 
_networkModel.generateVmData(vm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getId(),
+            List<String[]> vmData = 
_networkModel.generateVmData(vm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(),
                     vm.getUuid(), nic.getIPv4Address(), publicKey, (String) 
profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
             profile.setVmData(vmData);
             
profile.setConfigDriveLabel(VirtualMachineManager.VmConfigDriveLabel.value());
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/com/cloud/vm/UserVmManagerImpl.java
index c798c820250..ecdd1125aab 100644
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -4087,7 +4087,7 @@ public boolean 
finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
                 final String serviceOffering = 
_serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), 
vm.getServiceOfferingId()).getDisplayText();
                 boolean isWindows = 
_guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
 
-                List<String[]> vmData = 
_networkModel.generateVmData(vm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getId(),
+                List<String[]> vmData = 
_networkModel.generateVmData(vm.getUserData(), serviceOffering, 
vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(),
                         vm.getUuid(), defaultNic.getIPv4Address(), 
vm.getDetail("SSH.PublicKey"), (String) 
profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
                 String vmName = vm.getInstanceName();
                 String configDriveIsoRootFolder = "/tmp";
diff --git a/server/test/com/cloud/network/MockNetworkModelImpl.java 
b/server/test/com/cloud/network/MockNetworkModelImpl.java
index f8580056e22..d14255432e7 100644
--- a/server/test/com/cloud/network/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/network/MockNetworkModelImpl.java
@@ -898,7 +898,7 @@ public boolean getNetworkEgressDefaultPolicy(Long 
networkId) {
     }
 
     @Override
-    public List<String[]> generateVmData(String userData, String 
serviceOffering, long datacenterId, String vmName, long vmId, String vmUuid, 
String guestIpAddress, String publicKey, String password, Boolean isWindows) {
+    public List<String[]> generateVmData(String userData, String 
serviceOffering, long datacenterId, String vmName, String vmHostName, long 
vmId, String vmUuid, String guestIpAddress, String publicKey, String password, 
Boolean isWindows) {
         return null;
     }
 
diff --git 
a/server/test/com/cloud/network/element/ConfigDriveNetworkElementTest.java 
b/server/test/com/cloud/network/element/ConfigDriveNetworkElementTest.java
index 7d5041536f0..ff3f40b2645 100644
--- a/server/test/com/cloud/network/element/ConfigDriveNetworkElementTest.java
+++ b/server/test/com/cloud/network/element/ConfigDriveNetworkElementTest.java
@@ -98,13 +98,13 @@
     public static final long NETWORK_ID = 1L;
     private final long DATACENTERID = NETWORK_ID;
     private final String ZONENAME = "zone1";
-    private final String VMINSTANCENAME = "vm_name";
+    private final String VMINSTANCENAME = "i-x-y";
+    private final String VMHOSTNAME = "vm-hostname";
     private final String VMOFFERING = "custom_instance";
     private final long VMID = 30L;
     private final String VMUSERDATA = 
"H4sIABCvw1oAAystTi1KSSxJ5AIAUPllwQkAAAA=";
     private final long SOID = 31L;
     private final long HOSTID = NETWORK_ID;
-    private final String HOSTNAME = "host1";
 
     @Mock private ConfigurationDao _configDao;
     @Mock private DataCenterDao _dcDao;
@@ -166,6 +166,7 @@ public void setUp() throws NoSuchFieldException, 
IllegalAccessException {
         when(virtualMachine.getDataCenterId()).thenReturn(DATACENTERID);
         when(virtualMachine.getInstanceName()).thenReturn(VMINSTANCENAME);
         when(virtualMachine.getUserData()).thenReturn(VMUSERDATA);
+        when(virtualMachine.getHostName()).thenReturn(VMHOSTNAME);
         when(deployDestination.getHost()).thenReturn(hostVO);
         when(hostVO.getId()).thenReturn(HOSTID);
         when(nic.isDefaultNic()).thenReturn(true);
@@ -246,7 +247,7 @@ public void testAddPasswordAndUserdata() throws 
InsufficientCapacityException, R
                 new String[]{"userdata", "user_data", VMUSERDATA},
                 new String[]{"metadata", "service-offering", VMOFFERING},
                 new String[]{"metadata", "availability-zone", ZONENAME},
-                new String[]{"metadata", "local-hostname", VMINSTANCENAME},
+                new String[]{"metadata", "local-hostname", VMHOSTNAME},
                 new String[]{"metadata", "local-ipv4", "192.168.111.111"},
                 new String[]{"metadata", "public-hostname", null},
                 new String[]{"metadata", "public-ipv4", "192.168.111.111"},
@@ -269,7 +270,7 @@ public void testAddPasswordAndUserdataStaticNat() throws 
InsufficientCapacityExc
                 new String[]{"userdata", "user_data", VMUSERDATA},
                 new String[]{"metadata", "service-offering", VMOFFERING},
                 new String[]{"metadata", "availability-zone", ZONENAME},
-                new String[]{"metadata", "local-hostname", VMINSTANCENAME},
+                new String[]{"metadata", "local-hostname", VMHOSTNAME},
                 new String[]{"metadata", "local-ipv4", "192.168.111.111"},
                 new String[]{"metadata", "public-hostname", "7.7.7.7"},
                 new String[]{"metadata", "public-ipv4", "7.7.7.7"},
@@ -292,7 +293,7 @@ public void testAddPasswordAndUserdataUuid() throws 
InsufficientCapacityExceptio
                 new String[]{"userdata", "user_data", VMUSERDATA},
                 new String[]{"metadata", "service-offering", VMOFFERING},
                 new String[]{"metadata", "availability-zone", ZONENAME},
-                new String[]{"metadata", "local-hostname", VMINSTANCENAME},
+                new String[]{"metadata", "local-hostname", VMHOSTNAME},
                 new String[]{"metadata", "local-ipv4", "192.168.111.111"},
                 new String[]{"metadata", "public-hostname", null},
                 new String[]{"metadata", "public-ipv4", "192.168.111.111"},
diff --git a/server/test/com/cloud/vpc/MockNetworkModelImpl.java 
b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
index dc2aab4792c..33192a75c59 100644
--- a/server/test/com/cloud/vpc/MockNetworkModelImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkModelImpl.java
@@ -913,7 +913,7 @@ public boolean getNetworkEgressDefaultPolicy(Long 
networkId) {
     }
 
     @Override
-    public List<String[]> generateVmData(String userData, String 
serviceOffering, long datacenterId, String vmName, long vmId, String vmUuid, 
String guestIpAddress, String publicKey, String password, Boolean isWindows) {
+    public List<String[]> generateVmData(String userData, String 
serviceOffering, long datacenterId, String vmName, String vmHostName, long 
vmId, String vmUuid, String guestIpAddress, String publicKey, String password, 
Boolean isWindows) {
         return null;
     }
 


 

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