[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH] Require datetime values written to the DB to end with a 'Z'


  • To: xen-api <xen-api@xxxxxxxxxxxxxxxxxxx>
  • From: Rob Hoes <rob.hoes@xxxxxxxxxx>
  • Date: Wed, 1 Sep 2010 13:49:25 +0100
  • Delivery-date: Wed, 01 Sep 2010 05:49:41 -0700
  • List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>

# HG changeset patch
# User Rob Hoes <rob.hoes@xxxxxxxxxx>
Require datetime values written to the DB to end with a 'Z'

All datetime values in the DB need to be UTC dates, and are required to ISO 
8601 formatted with a trailing 'Z' to indicate they are UTC. The XenAPI did not 
have any functions that allow users to write datetimes directly to the DB... 
until recently (e.g. VMPP.set_archive_last_run_time)! It is therefore now 
necessary to enforce that the datetime values in the parameters of such 'set' 
functions have the correct form.

For backwards compatibility, XenAPI functions such as message.get_since still 
allow dates without 'Z', and will assume these are UTC dates.

Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx>

diff -r 7545e82ed747 ocaml/idl/ocaml_backend/exnHelper.ml
--- a/ocaml/idl/ocaml_backend/exnHelper.ml
+++ b/ocaml/idl/ocaml_backend/exnHelper.ml
@@ -47,10 +47,10 @@
     | Db_cache.Read_missing_uuid (tbl,ref,uuid) ->
        uuid_invalid, [ tbl; uuid ]
          
-    | Db_actions.DM_to_String.StringEnumTypeError s ->
-       invalid_value, [ s ]
+    | Db_actions.DM_to_String.StringEnumTypeError s
+    | Db_actions.DM_to_String.DateTimeError s
     | Db_actions.String_to_DM.StringEnumTypeError s ->
-       invalid_value, [ s ]
+        invalid_value, [ s ]
          
 (* These are the two catch-all patterns. If ever an Errors.Server_error 
exception   *)
 (* is raised, this is assumed to be an API error, and passed straight on. Any 
other *)
diff -r 7545e82ed747 ocaml/idl/ocaml_backend/gen_db_actions.ml
--- a/ocaml/idl/ocaml_backend/gen_db_actions.ml
+++ b/ocaml/idl/ocaml_backend/gen_db_actions.ml
@@ -52,7 +52,7 @@
   let ty_fun ty =
     let body = match ty with
       | DT.Bool -> "string_of_bool"
-      | DT.DateTime -> "fun x -> Date.to_string x"
+      | DT.DateTime -> "fun x -> (try Date.assert_utc x with Invalid_argument 
s -> raise (DateTimeError s)); Date.to_string x"
       | DT.Enum(name, cs) ->
           let aux (c, _) = (OU.constructor_of c)^" -> \""^c^"\"" in
           "\n    fun v -> match v with\n      "^
@@ -80,6 +80,7 @@
   O.Module.make
     ~name:_dm_to_string
     ~preamble: [ "exception StringEnumTypeError of string";
+                 "exception DateTimeError of string";
                  "open String_marshall_helper" ]
     ~letrec:true
     ~elements:(List.map (fun ty -> O.Module.Let (ty_fun ty)) tys) ()

Attachment: ca43587
Description: Text document

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.