Blame SOURCES/qemuga-qga-Add-guest-get-timezone-command.patch

3f2699
From c3d3a693c4bb181f6673071de95e79fd97eda526 Mon Sep 17 00:00:00 2001
3f2699
From: Miroslav Rezanina <mrezanin@redhat.com>
3f2699
Date: Thu, 19 Apr 2018 12:33:44 -0300
3f2699
Subject: [PATCH 3/7] qga: Add `guest-get-timezone` command
3f2699
MIME-Version: 1.0
3f2699
Content-Type: text/plain; charset=UTF-8
3f2699
Content-Transfer-Encoding: 8bit
3f2699
3f2699
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
3f2699
Message-id: <605280b778254624582ec8aa72c72155d2206948.1524139831.git.mrezanin@redhat.com>
3f2699
Patchwork-id: 79705
3f2699
O-Subject: [RHEL-7.5.z qemu-guest-agent PATCH 3/7] qga: Add `guest-get-timezone` command
3f2699
Bugzilla: 1598210
3f2699
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
3f2699
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
3f2699
RH-Acked-by: Tomáš Golembiovský <tgolembi@redhat.com>
3f2699
3f2699
From: Vinzenz Feenstra <vfeenstr@redhat.com>
3f2699
3f2699
Adds a new command `guest-get-timezone` reporting the currently
3f2699
configured timezone on the system. The information on what timezone is
3f2699
currently is configured is useful in case of Windows VMs where the
3f2699
offset of the hardware clock is required to have the same offset. This
3f2699
can be used for management systems like `oVirt` to detect the timezone
3f2699
difference and warn administrators of the misconfiguration.
3f2699
3f2699
Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
3f2699
Reviewed-by: Sameeh Jubran <sameeh@daynix.com>
3f2699
Tested-by: Sameeh Jubran <sameeh@daynix.com>
3f2699
* moved stub implementation to end of function for consistency
3f2699
* document that timezone names are for informational use only.
3f2699
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
3f2699
(cherry picked from commit 53c58e64d0a27c59d763778faa2b5a522c544719)
3f2699
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
3f2699
---
3f2699
 qga/commands.c       | 38 ++++++++++++++++++++++++++++++++++++++
3f2699
 qga/qapi-schema.json | 25 +++++++++++++++++++++++++
3f2699
 2 files changed, 63 insertions(+)
3f2699
3f2699
diff --git a/qga/commands.c b/qga/commands.c
3f2699
index 8c09938e28..5b73cd0e4d 100644
3f2699
--- a/qga/commands.c
3f2699
+++ b/qga/commands.c
3f2699
@@ -510,3 +510,41 @@ GuestHostName *qmp_guest_get_host_name(Error **err)
3f2699
     }
3f2699
     return result;
3f2699
 }
3f2699
+
3f2699
+GuestTimezone *qmp_guest_get_timezone(Error **errp)
3f2699
+{
3f2699
+#if GLIB_CHECK_VERSION(2, 28, 0)
3f2699
+    GuestTimezone *info = NULL;
3f2699
+    GTimeZone *tz = NULL;
3f2699
+    gint64 now = 0;
3f2699
+    gint32 intv = 0;
3f2699
+    gchar const *name = NULL;
3f2699
+
3f2699
+    info = g_new0(GuestTimezone, 1);
3f2699
+    tz = g_time_zone_new_local();
3f2699
+    if (tz == NULL) {
3f2699
+        error_setg(errp, QERR_QGA_COMMAND_FAILED,
3f2699
+                   "Couldn't retrieve local timezone");
3f2699
+        goto error;
3f2699
+    }
3f2699
+
3f2699
+    now = g_get_real_time() / G_USEC_PER_SEC;
3f2699
+    intv = g_time_zone_find_interval(tz, G_TIME_TYPE_UNIVERSAL, now);
3f2699
+    info->offset = g_time_zone_get_offset(tz, intv);
3f2699
+    name = g_time_zone_get_abbreviation(tz, intv);
3f2699
+    if (name != NULL) {
3f2699
+        info->has_zone = true;
3f2699
+        info->zone = g_strdup(name);
3f2699
+    }
3f2699
+    g_time_zone_unref(tz);
3f2699
+
3f2699
+    return info;
3f2699
+
3f2699
+error:
3f2699
+    g_free(info);
3f2699
+    return NULL;
3f2699
+#else
3f2699
+    error_setg(errp, QERR_UNSUPPORTED);
3f2699
+    return NULL;
3f2699
+#endif
3f2699
+}
3f2699
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
3f2699
index 1695afe3a9..5af73fedae 100644
3f2699
--- a/qga/qapi-schema.json
3f2699
+++ b/qga/qapi-schema.json
3f2699
@@ -1079,3 +1079,28 @@
3f2699
 ##
3f2699
 { 'command': 'guest-get-users',
3f2699
   'returns': ['GuestUser'] }
3f2699
+
3f2699
+##
3f2699
+# @GuestTimezone:
3f2699
+#
3f2699
+# @zone:    Timezone name. These values may differ depending on guest/OS and
3f2699
+#           should only be used for informational purposes.
3f2699
+# @offset:  Offset to UTC in seconds, negative numbers for time zones west of
3f2699
+#           GMT, positive numbers for east
3f2699
+#
3f2699
+# Since: 2.10
3f2699
+##
3f2699
+{ 'struct': 'GuestTimezone',
3f2699
+  'data':   { '*zone': 'str', 'offset': 'int' } }
3f2699
+
3f2699
+##
3f2699
+# @guest-get-timezone:
3f2699
+#
3f2699
+# Retrieves the timezone information from the guest.
3f2699
+#
3f2699
+# Returns: A GuestTimezone dictionary.
3f2699
+#
3f2699
+# Since: 2.10
3f2699
+##
3f2699
+{ 'command': 'guest-get-timezone',
3f2699
+  'returns': 'GuestTimezone' }
3f2699
-- 
3f2699
2.13.6
3f2699