[PATCH v2 03/23] src: add constants for guest info 'timezone.' parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 include/libvirt/libvirt-domain.h | 19 +++++++++++++++++++
 src/libvirt-domain.c             |  8 +++-----
 src/qemu/qemu_agent.c            |  4 ++--
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 683c0321e5..dc2af359b9 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -6601,6 +6601,25 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain,
  */
 #define VIR_DOMAIN_GUEST_INFO_OS_VARIANT_ID "os.variant-id"
 
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME:
+ *
+ * The name of the timezone as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME "timezone.name"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET:
+ *
+ * The offset to UTC in seconds as an int.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET "timezone.offset"
+
 /**
  * virDomainGuestInfoTypes:
  *
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index bbc6cfef9e..9c858622c2 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13213,11 +13213,9 @@ virDomainSetVcpu(virDomainPtr domain,
  *  keys.
  *
  * VIR_DOMAIN_GUEST_INFO_TIMEZONE:
- *  Returns information about the timezone within the domain. The typed
- *  parameter keys are in this format:
- *
- *      "timezone.name" - the name of the timezone as a string
- *      "timezone.offset" - the offset to UTC in seconds as an int
+ *  Returns information about the timezone within the domain.
+ *  The VIR_DOMAIN_GUEST_INFO_TIMEZONE_* constants define the known typed parameter
+ *  keys.
  *
  * VIR_DOMAIN_GUEST_INFO_FILESYSTEM:
  *  Returns information about the filesystems within the domain.  The typed
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 40cfe4fe3a..6f5aab5bf2 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2316,7 +2316,7 @@ qemuAgentGetTimezone(qemuAgent *agent,
     }
 
     if ((name = virJSONValueObjectGetString(data, "zone")))
-        virTypedParamListAddString(list, name, "timezone.name");
+        virTypedParamListAddString(list, name, VIR_DOMAIN_GUEST_INFO_TIMEZONE_NAME);
 
     if ((virJSONValueObjectGetNumberInt(data, "offset", &offset)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2324,7 +2324,7 @@ qemuAgentGetTimezone(qemuAgent *agent,
         return -1;
     }
 
-    virTypedParamListAddInt(list, offset, "timezone.offset");
+    virTypedParamListAddInt(list, offset, VIR_DOMAIN_GUEST_INFO_TIMEZONE_OFFSET);
 
     return 0;
 }
-- 
2.48.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux