]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: add constants for guest info 'os.' parameters
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 27 Feb 2025 13:42:08 +0000 (13:42 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 12 Mar 2025 09:57:56 +0000 (09:57 +0000)
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.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
include/libvirt/libvirt-domain.h
src/libvirt-domain.c
src/qemu/qemu_agent.c

index 22597d2d0eb50218798795747fe2210cff53f751..d4d67e6c3840f0888308e893a2ce8157c272d237 100644 (file)
@@ -6504,6 +6504,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:
  *
index f073c27788da44cb5b5605d164d665e787469110..bbc6cfef9e76c85b562f40357637bb1783e6d77b 100644 (file)
@@ -13208,27 +13208,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
index fe2d65ccf30dfebb8a538b8c385832d0b5c83172..40cfe4fe3a5c9944606f048fae9619411ddc6931 100644 (file)
@@ -2271,16 +2271,16 @@ qemuAgentGetOSInfo(qemuAgent *agent,
             virTypedParamListAddString(list, result, param_string_); \
         } \
     } 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;
 }