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@citrix.com>
| 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 *)
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 "^
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) ()