Merge remote-tracking branch 'origin/4.17' into 4.18

This commit is contained in:
Harikrishna Patnala 2023-04-17 11:46:17 +05:30
commit 2a68259d0d

View File

@ -241,6 +241,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;
@ -1923,20 +1924,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));
}
}
}