diff mbox

qga: Add `guest-get-timezone` command

Message ID 20170322154649.6947-1-vfeenstr@redhat.com
State New
Headers show

Commit Message

Vinzenz 'evilissimo' Feenstra March 22, 2017, 3:46 p.m. UTC
From: Vinzenz Feenstra <vfeenstr@redhat.com>

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.

Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
---
 qga/commands.c       | 19 +++++++++++++++++++
 qga/qapi-schema.json | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

Comments

Vinzenz 'evilissimo' Feenstra March 22, 2017, 3:47 p.m. UTC | #1
Sorry I meant to add you Michael not Paolo -_-

> On Mar 22, 2017, at 4:46 PM, Vinzenz 'evilissimo' Feenstra <vfeenstr@redhat.com> wrote:
> 
> From: Vinzenz Feenstra <vfeenstr@redhat.com>
> 
> 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.
> 
> Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
> ---
> qga/commands.c       | 19 +++++++++++++++++++
> qga/qapi-schema.json | 25 +++++++++++++++++++++++++
> 2 files changed, 44 insertions(+)
> 
> diff --git a/qga/commands.c b/qga/commands.c
> index 4d92946..83d7f99 100644
> --- a/qga/commands.c
> +++ b/qga/commands.c
> @@ -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;
> +}
> +
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index a02dbf2..6683aae 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -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' }
> -- 
> 2.9.3
>
Eric Blake March 22, 2017, 4 p.m. UTC | #2
On 03/22/2017 10:46 AM, Vinzenz 'evilissimo' Feenstra wrote:
> From: Vinzenz Feenstra <vfeenstr@redhat.com>

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.

> 
> 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.
> 
> Signed-off-by: Vinzenz Feenstra <vfeenstr@redhat.com>
> ---
>  qga/commands.c       | 19 +++++++++++++++++++
>  qga/qapi-schema.json | 25 +++++++++++++++++++++++++
>  2 files changed, 44 insertions(+)
> 

> +++ b/qga/qapi-schema.json
> @@ -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
> +#

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).


> +##
> +# @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.

> +#
> +# 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,
Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/qga/commands.c b/qga/commands.c
index 4d92946..83d7f99 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -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;
+}
+
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index a02dbf2..6683aae 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -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' }