You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sh...@apache.org on 2023/04/17 05:56:05 UTC
[cloudstack] branch 4.17 updated: Set hypervisor hostname via userdata only when the global settings are allowed (#7360)
This is an automated email from the ASF dual-hosted git repository.
shwstppr pushed a commit to branch 4.17
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.17 by this push:
new 96897f07f28 Set hypervisor hostname via userdata only when the global settings are allowed (#7360)
96897f07f28 is described below
commit 96897f07f2865bb3a79b59487e30dd9e2edd9064
Author: Harikrishna <ha...@gmail.com>
AuthorDate: Mon Apr 17 11:25:56 2023 +0530
Set hypervisor hostname via userdata only when the global settings are allowed (#7360)
* Set hypervisor hostname via userdata only when the corresponding global settings are enabled
* reformat code
---
.../engine/orchestration/NetworkOrchestrator.java | 39 ++++++++++++++--------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 3284511e01a..45f52e404ae 100644
--- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -236,6 +236,7 @@ import com.cloud.vm.UserVmManager;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VirtualMachine.Type;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
@@ -1811,20 +1812,32 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
@Override
public void setHypervisorHostname(VirtualMachineProfile vm, DeployDestination dest, boolean migrationSuccessful) throws ResourceUnavailableException {
- final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
- for (final NicVO nic : nics) {
- final NetworkVO network = _networksDao.findById(nic.getNetworkId());
- final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
- final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
- _networkModel.getNetworkTag(vm.getHypervisorType(), network));
- for (final NetworkElement element : networkElements) {
- if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && element instanceof UserDataServiceProvider) {
- if (element instanceof ConfigDriveNetworkElement && !migrationSuccessful || element instanceof VirtualRouterElement && migrationSuccessful) {
- final UserDataServiceProvider sp = (UserDataServiceProvider) element;
- if (!sp.saveHypervisorHostname(profile, network, vm, dest)) {
- throw new CloudRuntimeException("Failed to Add hypervisor hostname");
- }
+ String hypervisorHostName = VirtualMachineManager.getHypervisorHostname(dest.getHost().getName());
+ if (StringUtils.isNotEmpty(hypervisorHostName)) {
+ final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
+ for (final NicVO nic : nics) {
+ final NetworkVO network = _networksDao.findById(nic.getNetworkId());
+ final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
+ final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
+ _networkModel.getNetworkTag(vm.getHypervisorType(), network));
+ setHypervisorHostnameInNetwork(vm, dest, network, profile, migrationSuccessful);
+ }
+ }
+ }
+
+ private void setHypervisorHostnameInNetwork(VirtualMachineProfile vm, DeployDestination dest, Network network, NicProfile profile, boolean migrationSuccessful) {
+ for (final NetworkElement element : networkElements) {
+ if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && element instanceof UserDataServiceProvider
+ && (element instanceof ConfigDriveNetworkElement && !migrationSuccessful || element instanceof VirtualRouterElement && migrationSuccessful)) {
+ String errorMsg = String.format("Failed to add hypervisor host name while applying the userdata during the migration of VM %s, " +
+ "VM needs to stop and start to apply the userdata again", vm.getInstanceName());
+ try {
+ final UserDataServiceProvider sp = (UserDataServiceProvider) element;
+ if (!sp.saveHypervisorHostname(profile, network, vm, dest)) {
+ s_logger.error(errorMsg);
}
+ } catch (ResourceUnavailableException e) {
+ s_logger.error(String.format("%s, error states %s", errorMsg, e));
}
}
}