Add use_localtime parameter for xen-hvm and kvm
authorJun Futagawa <jfut@integ.jp>
Thu, 5 Nov 2009 04:22:00 +0000 (13:22 +0900)
committerIustin Pop <iustin@google.com>
Fri, 6 Nov 2009 12:06:49 +0000 (13:06 +0100)
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
lib/hypervisor/hv_kvm.py
lib/hypervisor/hv_xen.py

index fa799a6..659e26a 100644 (file)
@@ -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: {
     },
index 1ab71c3..788d3dd 100644 (file)
@@ -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
index 1addef7..6352893 100644 (file)
@@ -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]