Contrary to most APIs returning typed parameters, there are no constants
defined for the guest info data keys. This is was because many of the
keys needs to be dynamically constructed using one or more array index
values.
It is possible to define constants while still supporting dynamic
array indexes by simply defining the prefixes and suffixes as constants.
The consuming code can then combine the constants with array index
value.
With this approach, it is practical to add constants for the guest info
API keys.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
include/libvirt/libvirt-domain.h | 10 ++++++++++
src/libvirt-domain.c | 11 +++++------
src/qemu/qemu_driver.c | 4 +++-
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 29c4d9c9e0..78ff82384c 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -6607,6 +6607,16 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain,
*/
#define VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET "timezone.offset"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_HOSTNAME_HOSTNAME:
+ *
+ * The hostname of the domain as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_HOSTNAME_HOSTNAME "hostname"
+
/**
* virDomainGuestInfoTypes:
*
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index b2dac9864d..bd4ea7c729 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13214,6 +13214,11 @@ virDomainSetVcpu(virDomainPtr domain,
* The VIR_DOMAIN_GUEST_INFO_TIMEZONE_* constants define the known typed parameter
* keys.
*
+ * VIR_DOMAIN_GUEST_INFO_HOSTNAME:
+ * Returns information about the hostname of the domain.
+ * The VIR_DOMAIN_GUEST_INFO_HOSTNAME_* constants define the known typed parameter
+ * keys.
+ *
* VIR_DOMAIN_GUEST_INFO_FILESYSTEM:
* Returns information about the filesystems within the domain. The typed
* parameter keys are in this format:
@@ -13248,12 +13253,6 @@ virDomainSetVcpu(virDomainPtr domain,
* "disk.<num>.guest_alias" - optional alias assigned to the disk, on Linux
* this is a name assigned by device mapper
*
- * VIR_DOMAIN_GUEST_INFO_HOSTNAME:
- * Returns information about the hostname of the domain. The typed
- * parameter keys are in this format:
- *
- * "hostname" - the hostname of the domain
- *
* VIR_DOMAIN_GUEST_INFO_INTERFACES:
* Returns information about the interfaces within the domain. The typed
* parameter keys are in this format:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 80c918312b..bfb4ef9170 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19511,7 +19511,9 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
goto exitagent;
if (hostname &&
- virTypedParamsAddString(params, nparams, &maxparams, "hostname", hostname) < 0)
+ virTypedParamsAddString(params, nparams, &maxparams,
+ VIR_DOMAIN_GUEST_INFO_HOSTNAME_HOSTNAME,
+ hostname) < 0)
goto exitagent;
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_FILESYSTEM) {
--
2.48.1