Fix issue with multiple KVM Host entries in host table (#12589)

This commit is contained in:
Nicolas Vazquez 2026-02-11 09:47:21 -03:00 committed by GitHub
parent 4de8c2b6f6
commit b7c970f45f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions

View File

@ -154,6 +154,8 @@ public interface ResourceManager extends ResourceService, Configurable {
public HostVO findHostByGuid(String guid);
HostVO findHostByGuidPrefix(String guid);
public HostVO findHostByName(String name);
HostStats getHostStatistics(Host host);

View File

@ -2261,15 +2261,26 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
private HostVO getNewHost(StartupCommand[] startupCommands) {
StartupCommand startupCommand = startupCommands[0];
HostVO host = findHostByGuid(startupCommand.getGuid());
String fullGuid = startupCommand.getGuid();
logger.debug(String.format("Trying to find Host by guid %s", fullGuid));
HostVO host = findHostByGuid(fullGuid);
if (host != null) {
logger.debug(String.format("Found Host by guid %s: %s", fullGuid, host));
return host;
}
host = findHostByGuid(startupCommand.getGuidWithoutResource());
String guidPrefix = startupCommand.getGuidWithoutResource();
logger.debug(String.format("Trying to find Host by guid prefix %s", guidPrefix));
host = findHostByGuidPrefix(guidPrefix);
return host; // even when host == null!
if (host != null) {
logger.debug(String.format("Found Host by guid prefix %s: %s", guidPrefix, host));
return host;
}
logger.debug(String.format("Could not find Host by guid %s", fullGuid));
return null;
}
protected HostVO createHostVO(final StartupCommand[] cmds, final ServerResource resource, final Map<String, String> details, List<String> hostTags,
@ -3296,6 +3307,15 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
public HostVO findHostByGuid(final String guid) {
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getGuid(), Op.EQ, guid);
sc.and(sc.entity().getRemoved(), Op.NULL);
return sc.find();
}
@Override
public HostVO findHostByGuidPrefix(String guid) {
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getGuid(), Op.LIKE, guid + "%");
sc.and(sc.entity().getRemoved(), Op.NULL);
return sc.find();
}
@ -3303,6 +3323,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
public HostVO findHostByName(final String name) {
final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
sc.and(sc.entity().getName(), Op.EQ, name);
sc.and(sc.entity().getRemoved(), Op.NULL);
return sc.find();
}

View File

@ -460,6 +460,11 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana
return null;
}
@Override
public HostVO findHostByGuidPrefix(String guid) {
return null;
}
/* (non-Javadoc)
* @see com.cloud.resource.ResourceManager#findHostByName(java.lang.String)
*/