diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index b96fe250aa..524a7bf9e8 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -333,6 +333,7 @@ typedef enum { VIR_ERR_NO_NETWORK_PORT = 107, /* network port not found */ VIR_ERR_NO_HOSTNAME = 108, /* no domain's hostname found */ VIR_ERR_CHECKPOINT_INCONSISTENT = 109, /* checkpoint can't be used */ + VIR_ERR_MULTIPLE_DOMAINS = 110, /* more than one matching domain found */ # ifdef VIR_ENUM_SENTINELS VIR_ERR_NUMBER_LAST diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 1200bf02ff..2e18ef6691 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -1118,6 +1118,13 @@ hypervDomainLookupByName(virConnectPtr conn, const char *name) if (hypervGetVirtualSystemByName(priv, name, &computerSystem) < 0) goto cleanup; + if (computerSystem->next) { + virReportError(VIR_ERR_MULTIPLE_DOMAINS, + _("Multiple domains exist with the name '%s': repeat the request using a UUID"), + name); + goto cleanup; + } + hypervMsvmComputerSystemToDomain(conn, computerSystem, &domain); cleanup: diff --git a/src/util/virerror.c b/src/util/virerror.c index 9e3bad97eb..14054add41 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1229,8 +1229,10 @@ static const virErrorMsgTuple virErrorMsgStrings[] = { N_("no hostname found: %s") }, [VIR_ERR_CHECKPOINT_INCONSISTENT] = { N_("checkpoint inconsistent"), - N_("checkpoint inconsistent: %s") - }, + N_("checkpoint inconsistent: %s") }, + [VIR_ERR_MULTIPLE_DOMAINS] = { + N_("multiple matching domains found"), + N_("multiple matching domains found: %s") }, }; G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) == VIR_ERR_NUMBER_LAST);