[PATCH 02/19] src: add constants for guest info 'os.' 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 | 97 ++++++++++++++++++++++++++++++++
 src/libvirt-domain.c             | 24 +-------
 src/qemu/qemu_agent.c            | 20 +++----
 3 files changed, 110 insertions(+), 31 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index cef8bd4dbe..cbf1f6304c 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -6491,6 +6491,103 @@ int virDomainSetLaunchSecurityState(virDomainPtr domain,
  */
 #define VIR_DOMAIN_GUEST_INFO_USER_SUFFIX_LOGIN_TIME ".login-time"
 
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_ID:
+ *
+ * A string identifying the operating system.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_ID "os.id"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_NAME:
+ *
+ * The name of the operating system, suitable for presentation to a user, as
+ * a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_NAME "os.name"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_PRETTY_NAME:
+ *
+ * A pretty name for the operating system, suitable for presentation to a
+ * user, as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_PRETTY_NAME "os.pretty-name"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_VERSION:
+ *
+ * The version of the operating system suitable for presentation to a user,
+ * as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_VERSION "os.version"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_VERSION_ID:
+ *
+ * The version id of the operating system suitable for processing by scripts,
+ * as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_VERSION_ID "os.version-id"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_KERNEL_RELEASE:
+ *
+ * The release of the operating system kernel, as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_KERNEL_RELEASE "os.kernel-release"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_KERNEL_VERSION:
+ *
+ * The version of the operating system kernel, as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_KERNEL_VERSION "os.kernel-version"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_MACHINE:
+ *
+ * The machine hardware name as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_MACHINE "os.machine"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_VARIANT:
+ *
+ * A specific variant or edition of the operating system suitable for
+ * presentation to a user, as a string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_VARIANT "os.variant"
+
+/**
+ * VIR_DOMAIN_GUEST_INFO_OS_VARIANT_ID:
+ *
+ * The id for a specific variant or edition of the operating system, as a
+ * string.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_GUEST_INFO_OS_VARIANT_ID "os.variant-id"
+
 /**
  * virDomainGuestInfoTypes:
  *
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 8485dad668..77f1865c21 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13205,27 +13205,9 @@ virDomainSetVcpu(virDomainPtr domain,
  *  keys.
  *
  * VIR_DOMAIN_GUEST_INFO_OS:
- *  Return information about the operating system running within the guest. The
- *  typed parameter keys are in this format:
- *
- *      "os.id" - a string identifying the operating system
- *      "os.name" - the name of the operating system, suitable for presentation
- *                  to a user, as a string
- *      "os.pretty-name" - a pretty name for the operating system, suitable for
- *                         presentation to a user, as a string
- *      "os.version" - the version of the operating system suitable for
- *                     presentation to a user, as a string
- *      "os.version-id" - the version id of the operating system suitable for
- *                        processing by scripts, as a string
- *      "os.kernel-release" - the release of the operating system kernel, as a
- *                            string
- *      "os.kernel-version" - the version of the operating system kernel, as a
- *                            string
- *      "os.machine" - the machine hardware name as a string
- *      "os.variant" - a specific variant or edition of the operating system
- *                     suitable for presentation to a user, as a string
- *      "os.variant-id" - the id for a specific variant or edition of the
- *                        operating system, as a string
+ *  Return information about the operating system running within the guest.
+ *  The VIR_DOMAIN_GUEST_INFO_OS_* constants define the known typed parameter
+ *  keys.
  *
  * VIR_DOMAIN_GUEST_INFO_TIMEZONE:
  *  Returns information about the timezone within the domain. The typed
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index cb9cce7f6a..88b293b29e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -2294,16 +2294,16 @@ qemuAgentGetOSInfo(qemuAgent *agent,
             } \
         } \
     } while (0)
-    OSINFO_ADD_PARAM("id", "os.id");
-    OSINFO_ADD_PARAM("name", "os.name");
-    OSINFO_ADD_PARAM("pretty-name", "os.pretty-name");
-    OSINFO_ADD_PARAM("version", "os.version");
-    OSINFO_ADD_PARAM("version-id", "os.version-id");
-    OSINFO_ADD_PARAM("machine", "os.machine");
-    OSINFO_ADD_PARAM("variant", "os.variant");
-    OSINFO_ADD_PARAM("variant-id", "os.variant-id");
-    OSINFO_ADD_PARAM("kernel-release", "os.kernel-release");
-    OSINFO_ADD_PARAM("kernel-version", "os.kernel-version");
+    OSINFO_ADD_PARAM("id", VIR_DOMAIN_GUEST_INFO_OS_ID);
+    OSINFO_ADD_PARAM("name", VIR_DOMAIN_GUEST_INFO_OS_NAME);
+    OSINFO_ADD_PARAM("pretty-name", VIR_DOMAIN_GUEST_INFO_OS_PRETTY_NAME);
+    OSINFO_ADD_PARAM("version", VIR_DOMAIN_GUEST_INFO_OS_VERSION);
+    OSINFO_ADD_PARAM("version-id", VIR_DOMAIN_GUEST_INFO_OS_VERSION_ID);
+    OSINFO_ADD_PARAM("machine", VIR_DOMAIN_GUEST_INFO_OS_MACHINE);
+    OSINFO_ADD_PARAM("variant", VIR_DOMAIN_GUEST_INFO_OS_VARIANT);
+    OSINFO_ADD_PARAM("variant-id", VIR_DOMAIN_GUEST_INFO_OS_VARIANT_ID);
+    OSINFO_ADD_PARAM("kernel-release", VIR_DOMAIN_GUEST_INFO_OS_KERNEL_RELEASE);
+    OSINFO_ADD_PARAM("kernel-version", VIR_DOMAIN_GUEST_INFO_OS_KERNEL_VERSION);
 
     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