From 6b970ceff872a0e963983dbd6a273eec7c485f08 Mon Sep 17 00:00:00 2001
From: Jun Futagawa <jfut@integ.jp>
Date: Thu, 5 Nov 2009 13:22:00 +0900
Subject: [PATCH] Add use_localtime parameter for xen-hvm and kvm

Currently xen-hvm and kvm use different real time clock by default. To
reduce confusion, this patch adds an optional use_localtime parameter.

If the real time clock on the instance is set to local time, the
parameter use_localtime should be True. The default is False. Note that
the real time clock changes from local to UTC in xen-hvm with the
default parameter.

Signed-off-by: Jun Futagawa <jfut@integ.jp>
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/constants.py         | 4 ++++
 lib/hypervisor/hv_kvm.py | 4 ++++
 lib/hypervisor/hv_xen.py | 4 +++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/constants.py b/lib/constants.py
index fa799a640..659e26a86 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -391,6 +391,7 @@ HV_USB_MOUSE = "usb_mouse"
 HV_DEVICE_MODEL = "device_model"
 HV_INIT_SCRIPT = "init_script"
 HV_MIGRATION_PORT = "migration_port"
+HV_USE_LOCALTIME = "use_localtime"
 
 HVS_PARAMETER_TYPES = {
   HV_BOOT_ORDER: VTYPE_STRING,
@@ -416,6 +417,7 @@ HVS_PARAMETER_TYPES = {
   HV_DEVICE_MODEL: VTYPE_STRING,
   HV_INIT_SCRIPT: VTYPE_STRING,
   HV_MIGRATION_PORT: VTYPE_INT,
+  HV_USE_LOCALTIME: VTYPE_BOOL,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -623,6 +625,7 @@ HVC_DEFAULTS = {
     HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
     HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
     HV_MIGRATION_PORT: 8002,
+    HV_USE_LOCALTIME: False,
     },
   HT_KVM: {
     HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
@@ -642,6 +645,7 @@ HVC_DEFAULTS = {
     HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
     HV_USB_MOUSE: '',
     HV_MIGRATION_PORT: 8102,
+    HV_USE_LOCALTIME: False,
     },
   HT_FAKE: {
     },
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 1ab71c30d..788d3ddc8 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -73,6 +73,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_USB_MOUSE:
       hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
     constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
+    constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
     }
 
   _MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)',
@@ -402,6 +403,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     else:
       kvm_cmd.extend(['-serial', 'none'])
 
+    if hvp[constants.HV_USE_LOCALTIME]:
+      kvm_cmd.extend(['-localtime'])
+
     # Save the current instance nics, but defer their expansion as parameters,
     # as we'll need to generate executable temp files for them.
     kvm_nics = instance.nics
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index 1addef7a3..63528939c 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -551,6 +551,7 @@ class XenHvmHypervisor(XenHypervisor):
     constants.HV_DEVICE_MODEL: hv_base.REQ_FILE_CHECK,
     constants.HV_VNC_PASSWORD_FILE: hv_base.REQ_FILE_CHECK,
     constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
+    constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
     }
 
   @classmethod
@@ -609,7 +610,8 @@ class XenHvmHypervisor(XenHypervisor):
     config.write("vncpasswd = '%s'\n" % password.rstrip())
 
     config.write("serial = 'pty'\n")
-    config.write("localtime = 1\n")
+    if hvp[constants.HV_USE_LOCALTIME]:
+      config.write("localtime = 1\n")
 
     vif_data = []
     nic_type = hvp[constants.HV_NIC_TYPE]
-- 
GitLab