Skip to contentSkip to conversation

qga: Add `guest-get-timezone` command

PATCH Superseded Vinzenz 'evilissimo' Feenstra 2 participants 3 messages Mar 22, 2017

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga: Add `guest-get-timezone` command

From: Vinzenz Feenstra <[email protected]>

Adds a new command guest-get-timezone reporting the currently configured timezone on the system. The information on what timezone is currently is configured is useful in case of Windows VMs where the offset of the hardware clock is required to have the same offset. This can be used for management systems like oVirt to detect the timezone difference and warn administrators of the misconfiguration.

---
 qga/commands.c       | 19 +++++++++++++++++++
 qga/qapi-schema.json | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
qga/commands.c +19 -0
index 4d92946..83d7f99 100644
@@ -499,3 +499,22 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
     error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
     return -1;
 }
+
+GuestTimezone *qmp_guest_get_timezone(Error **errp)
+{
+    GuestTimezone *info = g_new0(GuestTimezone, 1);
+    GTimeZone *tz = g_time_zone_new_local();
+    gint32 interval = g_time_zone_find_interval(tz, G_TIME_TYPE_STANDARD, 0);
+    gchar const *name = g_time_zone_get_abbreviation(tz, interval);
+    if (name != NULL) {
+        info->offset = g_time_zone_get_offset(tz, interval) / 60;
+        info->zone = g_strdup(name);
+    } else {
+        error_setg(errp, "Timezone lookup failed");
+        g_free(info);
+        info = NULL;
+    }
+    g_time_zone_unref(tz);
+    return info;
+}
+
qga/qapi-schema.json +25 -0
index a02dbf2..6683aae 100644
@@ -1042,3 +1042,28 @@
   'data':    { 'path': 'str', '*arg': ['str'], '*env': ['str'],
                '*input-data': 'str', '*capture-output': 'bool' },
   'returns': 'GuestExec' }
+
+
+##
+# @GuestTimezone:
+#
+# @zone:    Timezone name
+# @offset:  Offset to UTC in minutes
+#
+# Since: 2.10
+##
+{ 'struct': 'GuestTimezone',
+  'data':   { 'zone': 'str', 'offset': 'int' } }
+
+
+##
+# @guest-get-timezone:
+#
+# Retrieves the timezone information from the guest.
+#
+# Returns: The guest timezone GuestTimezone information on success.
+#
+# Since: 2.10
+##
+{ 'command': 'guest-get-timezone',
+  'returns': 'GuestTimezone' }
Signature · 1 line
2.9.3
#1 lore raw

Sorry I meant to add you Michael not Paolo -_-

Quoted 80 lines · Vinzenz 'evilissimo' Feenstra

From: Vinzenz Feenstra <[email protected]>

Adds a new command guest-get-timezone reporting the currently configured timezone on the system. The information on what timezone is currently is configured is useful in case of Windows VMs where the offset of the hardware clock is required to have the same offset. This can be used for management systems like oVirt to detect the timezone difference and warn administrators of the misconfiguration.

---
qga/commands.c | 19 +++++++++++++++++++
qga/qapi-schema.json | 25 +++++++++++++++++++++++++

2 files changed, 44 insertions(+)
qga/commands.c +19 -0
index 4d92946..83d7f99 100644
@@ -499,3 +499,22 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
    error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
    return -1;
 }
+
+GuestTimezone *qmp_guest_get_timezone(Error **errp)
+{
+    GuestTimezone *info = g_new0(GuestTimezone, 1);
+    GTimeZone *tz = g_time_zone_new_local();
+    gint32 interval = g_time_zone_find_interval(tz, G_TIME_TYPE_STANDARD, 0);
+    gchar const *name = g_time_zone_get_abbreviation(tz, interval);
+    if (name != NULL) {
+        info->offset = g_time_zone_get_offset(tz, interval) / 60;
+        info->zone = g_strdup(name);
+    } else {
+        error_setg(errp, "Timezone lookup failed");
+        g_free(info);
+        info = NULL;
+    }
+    g_time_zone_unref(tz);
+    return info;
+}
+
qga/qapi-schema.json +25 -0
index a02dbf2..6683aae 100644
@@ -1042,3 +1042,28 @@
  'data':    { 'path': 'str', '*arg': ['str'], '*env': ['str'],
               '*input-data': 'str', '*capture-output': 'bool' },
  'returns': 'GuestExec' }
+
+
+##
+# @GuestTimezone:
+#
+# @zone:    Timezone name
+# @offset:  Offset to UTC in minutes
+#
+# Since: 2.10
+##
+{ 'struct': 'GuestTimezone',
+  'data':   { 'zone': 'str', 'offset': 'int' } }
+
+
+##
+# @guest-get-timezone:
+#
+# Retrieves the timezone information from the guest.
+#
+# Returns: The guest timezone GuestTimezone information on success.
+#
+# Since: 2.10
+##
+{ 'command': 'guest-get-timezone',
+  'returns': 'GuestTimezone' }
Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#2 lore raw
In reply to Vinzenz 'evilissimo' Feenstra
Quoted 1 line · Vinzenz 'evilissimo' Feenstra

From: Vinzenz Feenstra <[email protected]>

This is not a trivial patch (it is adding a new feature), so including qemu-trivial is not necessary, and it should be merged through the qga maintainer.

Quoted 18 lines

Adds a new command guest-get-timezone reporting the currently configured timezone on the system. The information on what timezone is currently is configured is useful in case of Windows VMs where the offset of the hardware clock is required to have the same offset. This can be used for management systems like oVirt to detect the timezone difference and warn administrators of the misconfiguration.

---
 qga/commands.c       | 19 +++++++++++++++++++
 qga/qapi-schema.json | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

+++ b/qga/qapi-schema.json

qga/qapi-schema.json +0 -0
@@ -1042,3 +1042,28 @@
   'data':    { 'path': 'str', '*arg': ['str'], '*env': ['str'],

qga/qapi-schema.json line 1052

Quoted 10 lines
qga/qapi-schema.json +8 -0
                '*input-data': 'str', '*capture-output': 'bool' },
   'returns': 'GuestExec' }
+
+
+##
+# @GuestTimezone:
+#
+# @zone:    Timezone name
+# @offset:  Offset to UTC in minutes
+#

Is it worth clarifying that negative numbers imply west of UTC? (There are some places that get offsets backwards from the usual POSIX notation, so it never hurts to be specific which direction is intended).

qga/qapi-schema.json line 1064

Quoted 6 lines
qga/qapi-schema.json +6 -0
+##
+# @guest-get-timezone:
+#
+# Retrieves the timezone information from the guest.
+#
+# Returns: The guest timezone GuestTimezone information on success.

Sounds rather repetitive; and a struct return is implicitly only possible on success. Perhaps it could be shortened to:

# Retrieves timezone information from the guest.
#
# Returns: A GuestTimezone dictionary.

qga/qapi-schema.json line 1069

Quoted 6 lines
qga/qapi-schema.json +5 -0
+#
+# Since: 2.10
+##
+{ 'command': 'guest-get-timezone',
+  'returns': 'GuestTimezone' }

But the overall idea makes sense to me, so whether or not you wordsmith the documentation in the .json file,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org