.PHONY: version
version:
- echo "let hg_id = \"$(shell hg id | sed -r 's/(.+)\s.*/\1/g')\"" > ocaml/util/version.ml
+ echo "(* This file is autogenerated. Grep for e17512ce-ba7c-11df-887b-0026b9799147 (random uuid) to see where it comes from. ;o) *)" > ocaml/util/version.ml
+ echo "let hg_id = \"$(shell hg id | sed -r 's/(.+)\s.*/\1/g')\"" >> ocaml/util/version.ml
echo "let hostname = \"$(shell hostname)\"" >> ocaml/util/version.ml
echo "let date = \"$(shell date -u +%Y-%m-%d)\"" >> ocaml/util/version.ml
echo "let product_version = \"$(PRODUCT_VERSION)\"" >> ocaml/util/version.ml
echo "let product_brand = \"$(PRODUCT_BRAND)\"" >> ocaml/util/version.ml
- echo "let build_number = \"$(BUILD_NUMBER)\"" >> ocaml/util/version.ml
+ echo "let build_number = Util_inventory.lookup \"BUILD_NUMBER\" (* \"$(BUILD_NUMBER)\" *)" >> ocaml/util/version.ml
.PHONY: clean
clean:
-OCamlLibrary(version, version)
-OCamlDocLibrary(version, version)
+#OCamlLibrary(util_globs_inventory, util_globs_inventory)
+OCamlLibrary(util_inventory, util_globs_inventory util_inventory)
+OCamlLibrary(version, util_globs_inventory util_inventory version)
+#OCamlDocLibrary(version, version_pre)
OCamlLibrary(sanitycheck, sanitycheck)
OCamlLibrary(stats, stats)
--- /dev/null
+(* path to the xensource inventory file *)
+let inventory_filename = "/etc/xensource-inventory"
--- /dev/null
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+(* Code to parse the XenSource inventory file *)
+
+open Pervasiveext
+open Stringext
+open Threadext
+
+module D = Debug.Debugger(struct let name="xapi" end)
+open D
+
+let loaded_inventory = ref false
+let inventory = Hashtbl.create 10
+let inventory_m = Mutex.create ()
+
+(* trim any quotes off the ends *)
+let strip_quotes v =
+ if String.length v >= 2
+ && v.[0] = '\''
+ && v.[String.length v - 1] = '\''
+ then String.sub v 1 (String.length v - 2)
+ else v
+
+let parse_inventory_entry line =
+ match String.split ~limit:2 '=' line with
+ | [k; v] ->
+ (* trim whitespace *)
+ Some (k, strip_quotes ++ String.strip String.isspace $ v)
+ | _ -> None
+
+let read_inventory_contents () =
+ (* Perhaps we should blank the old inventory before we read the new one?
+ What is the desired behaviour? *)
+ Unixext.file_lines_iter (fun line ->
+ match parse_inventory_entry line with
+ | Some (k, v) -> Hashtbl.add inventory k v
+ | None -> warn
+ "Failed to parse line from xensource-inventory file: %s" line)
+ Util_globs_inventory.inventory_filename;
+ loaded_inventory := true
+
+let read_inventory () = Mutex.execute inventory_m read_inventory_contents
+let reread_inventory () = Mutex.execute inventory_m (fun () ->
+ Hashtbl.clear inventory;
+ read_inventory_contents ())
+
+exception Missing_inventory_key of string
+
+let lookup key =
+ if not (!loaded_inventory) then read_inventory();
+ if not (Hashtbl.mem inventory key)
+ then raise (Missing_inventory_key key);
+ Hashtbl.find inventory key
+
+let flush_to_disk_locked () =
+ let lines = Hashtbl.fold
+ (fun k v acc -> Printf.sprintf "%s='%s'\n" k v :: acc)
+ inventory [] in
+ Unixext.write_string_to_file Util_globs_inventory.inventory_filename
+ $ String.concat "" lines
+
+let update key value = Mutex.execute inventory_m (fun () ->
+ Hashtbl.clear inventory;
+ read_inventory_contents ();
+ Hashtbl.replace inventory key value;
+ flush_to_disk_locked ())
+
+let remove key = Mutex.execute inventory_m (fun () ->
+ Hashtbl.clear inventory;
+ read_inventory_contents ();
+ Hashtbl.remove inventory key;
+ flush_to_disk_locked ())
+
+let _product_brand = "PRODUCT_BRAND"
+let _product_name = "PRODUCT_NAME"
+let _product_version = "PRODUCT_VERSION='0.5.1'"
+let _build_number = "BUILD_NUMBER"
+let _kernel_version = "KERNEL_VERSION"
+let _xen_version = "XEN_VERSION"
+let _installation_date = "INSTALLATION_DATE"
+let _default_sr = "DEFAULT_SR"
+let _primary_disk = "PRIMARY_DISK"
+let _backup_partition = "BACKUP_PARTITION"
+let _installation_uuid = "INSTALLATION_UUID"
+let _default_sr_physdevs = "DEFAULT_SR_PHYSDEVS"
+let _control_domain_uuid = "CONTROL_DOMAIN_UUID"
+let _management_interface = "MANAGEMENT_INTERFACE"
+let _current_interfaces = "CURRENT_INTERFACES"
+let _dom0_mem = "DOM0_MEM"
+let _oem_manufacturer = "OEM_MANUFACTURER"
+let _oem_model = "OEM_MODEL"
+let _oem_build_number = "OEM_BUILD_NUMBER"
+let _machine_serial_number = "MACHINE_SERIAL_NUMBER"
+let _machine_serial_name = "MACHINE_SERIAL_NAME"
--- /dev/null
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+(** Interface to the Inventory file *)
+
+(** The inventory file is a file containing key-value pair of information
+ * related to the host. It is stored at /etc/xensource-inventory. *)
+
+(** Thrown when trying to retrieve a non-existing key. *)
+exception Missing_inventory_key of string
+
+(** Reads the inventory file from disk. *)
+val read_inventory: unit -> unit
+
+(** Clears the copy of the inventory file in memory and reads the file from disk. *)
+val reread_inventory: unit -> unit
+
+(** Return the value of key [key] in the inventory file. Throws {!Missing_inventory_key}
+ * if the key does not exist. *)
+val lookup: string -> string
+
+(** Remove the key with the given name from the inventory file, if it exists. *)
+val remove: string -> unit
+
+(** Change the contents of key [key] in the inventory file to [value]. The key
+ * is added if it does not yet exist. *)
+val update: string -> string -> unit
+
+(** Parses a line [line] from the inventory file, and returns a key-value pair if successful. *)
+val parse_inventory_entry: string -> (string * string) option
+
+(* Keys defined in Geneva *)
+(** Brand name, such as "XenServer" *)
+val _product_brand : string
+
+(** Product name, such as "xenenterprise" *)
+val _product_name : string
+
+(** Product version *)
+val _product_version : string
+
+(** Build number *)
+val _build_number : string
+
+(** Dom0 kernel version *)
+val _kernel_version : string
+
+(** Xen version *)
+val _xen_version : string
+
+(** Date on which the host was installed *)
+val _installation_date : string
+
+(** UUID of the default SR (?) *)
+val _default_sr : string
+
+(** Device path of primary disk *)
+val _primary_disk : string
+
+(** Device path of backup partition *)
+val _backup_partition : string
+
+(** UUID of the Host object in the xapi database *)
+val _installation_uuid : string
+
+(** Device path of the default SR used for local storage *)
+val _default_sr_physdevs : string
+
+(** Memory size of dom0 (?) *)
+val _dom0_mem : string
+
+
+(* Keys defined in Rio *)
+(** UUID of the control domain (dom0) *)
+val _control_domain_uuid : string
+
+(** UUID of the management PIF *)
+val _management_interface : string
+
+(* Keys defined in Miami *)
+(** OEM manufacturer name *)
+val _oem_manufacturer : string
+
+(** OEM model name *)
+val _oem_model : string
+
+(** OEM edition build number *)
+val _oem_build_number : string
+
+(** Machine serial number *)
+val _machine_serial_number : string
+
+(** Machine serial name *)
+val _machine_serial_name : string
+
+(* Keys defined in Orlando, redefined in MNR *)
+(** List of bridges that are automatically brought up when the host starts up *)
+val _current_interfaces : string
--- /dev/null
+val hg_id : string
+val hostname : string
+val date : string
+val product_version : string
+val product_brand : string
+val build_number : string
OCAMLPACKS = xml-light2 cdrom pciutil sexpr log stunnel http-svr rss xen-utils netdev tapctl vhd xs
-OCAML_LIBS = ../util/version ../util/vm_memory_constraints ../util/sanitycheck ../util/stats \
+OCAML_LIBS = ../util/version ../util/vm_memory_constraints ../util/sanitycheck ../util/stats \
../idl/ocaml_backend/common ../idl/ocaml_backend/client ../idl/ocaml_backend/server ../util/ocamltest
OCAMLINCLUDES = ../idl ../idl/ocaml_backend \
../autogen ../database/ \
open Stringext
open Printf
+open Util_globs_inventory
(* xapi process returns this code on exit when it wants to be restarted *)
let restart_return_code = 123
let http_realm = "xapi"
-(* path to the xensource inventory file *)
-let inventory_filename = "/etc/xensource-inventory"
-
(* Special XS entry looked for by the XenSource PV drivers (see xenagentd.hg:src/xad.c) *)
let xe_key = "/mh/XenSource-TM_XenEnterprise-TM"
let xe_val = "XenSource(TM) and XenEnterprise(TM) are registered trademarks of XenSource Inc."
-(*
- * Copyright (C) 2006-2009 Citrix Systems Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *)
-(* Code to parse the XenSource inventory file *)
-
-open Pervasiveext
-open Stringext
-open Threadext
-
-module D = Debug.Debugger(struct let name="xapi" end)
-open D
-
-let loaded_inventory = ref false
-let inventory = Hashtbl.create 10
-let inventory_m = Mutex.create ()
-
-let parse_inventory_entry line =
- match String.split ~limit:2 '=' line with
- | [k; v] ->
- (* trim whitespace *)
- let v = String.strip String.isspace v in
- (* trim any quotes off the ends *)
- let v = if String.length v >= 2 && v.[0] = '\'' && v.[String.length v - 1] = '\''
- then String.sub v 1 (String.length v - 2)
- else v in
- Some (k, v)
- | _ -> None
-
-
-let read_inventory_contents () =
- let ic = open_in Xapi_globs.inventory_filename in
- finally
- (fun () ->
- try
- while true do
- let line = input_line ic in
- match parse_inventory_entry line with
- | Some (k, v) ->
- Hashtbl.add inventory k v
- | None -> warn "Failed to parse line from xensource-inventory file: %s" line
- done
- with End_of_file -> ()) (fun () -> loaded_inventory := true; close_in ic)
-
-let read_inventory () = Mutex.execute inventory_m read_inventory_contents
-let reread_inventory () = Mutex.execute inventory_m
- (fun () ->
- Hashtbl.clear inventory;
- read_inventory_contents ())
-
-exception Missing_inventory_key of string
-
-let lookup key =
- if not(!loaded_inventory) then read_inventory();
- if not(Hashtbl.mem inventory key)
- then raise (Missing_inventory_key key);
- Hashtbl.find inventory key
-
-let flush_to_disk_locked () =
- let lines = Hashtbl.fold (fun k v acc -> Printf.sprintf "%s='%s'\n" k v :: acc) inventory [] in
- let one_big_line = String.concat "" lines in
- Unixext.write_string_to_file Xapi_globs.inventory_filename one_big_line
-
-let update key value =
- Mutex.execute inventory_m
- (fun () ->
- Hashtbl.clear inventory;
- read_inventory_contents ();
- Hashtbl.replace inventory key value;
- flush_to_disk_locked ()
- )
-
-let remove key =
- Mutex.execute inventory_m
- (fun () ->
- Hashtbl.clear inventory;
- read_inventory_contents ();
- Hashtbl.remove inventory key;
- flush_to_disk_locked ()
- )
-
-
-let _product_brand = "PRODUCT_BRAND"
-let _product_name = "PRODUCT_NAME"
-let _product_version = "PRODUCT_VERSION='0.5.1'"
-let _build_number = "BUILD_NUMBER"
-let _kernel_version = "KERNEL_VERSION"
-let _xen_version = "XEN_VERSION"
-let _installation_date = "INSTALLATION_DATE"
-let _default_sr = "DEFAULT_SR"
-let _primary_disk = "PRIMARY_DISK"
-let _backup_partition = "BACKUP_PARTITION"
-let _installation_uuid = "INSTALLATION_UUID"
-let _default_sr_physdevs = "DEFAULT_SR_PHYSDEVS"
-let _control_domain_uuid = "CONTROL_DOMAIN_UUID"
-let _management_interface = "MANAGEMENT_INTERFACE"
-let _current_interfaces = "CURRENT_INTERFACES"
-let _dom0_mem = "DOM0_MEM"
-let _oem_manufacturer = "OEM_MANUFACTURER"
-let _oem_model = "OEM_MODEL"
-let _oem_build_number = "OEM_BUILD_NUMBER"
-let _machine_serial_number = "MACHINE_SERIAL_NUMBER"
-let _machine_serial_name = "MACHINE_SERIAL_NAME"
+include Util_inventory
+++ /dev/null
-(*
- * Copyright (C) 2006-2009 Citrix Systems Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *)
-(** Interface to the Inventory file *)
-
-(** The inventory file is a file containing key-value pair of information
- * related to the host. It is stored at /etc/xensource-inventory. *)
-
-(** Thrown when trying to retrieve a non-existing key. *)
-exception Missing_inventory_key of string
-
-(** Reads the inventory file from disk. *)
-val read_inventory: unit -> unit
-
-(** Clears the copy of the inventory file in memory and reads the file from disk. *)
-val reread_inventory: unit -> unit
-
-(** Return the value of key [key] in the inventory file. Throws {!Missing_inventory_key}
- * if the key does not exist. *)
-val lookup: string -> string
-
-(** Remove the key with the given name from the inventory file, if it exists. *)
-val remove: string -> unit
-
-(** Change the contents of key [key] in the inventory file to [value]. The key
- * is added if it does not yet exist. *)
-val update: string -> string -> unit
-
-(** Parses a line [line] from the inventory file, and returns a key-value pair if successful. *)
-val parse_inventory_entry: string -> (string * string) option
-
-(* Keys defined in Geneva *)
-(** Brand name, such as "XenServer" *)
-val _product_brand : string
-
-(** Product name, such as "xenenterprise" *)
-val _product_name : string
-
-(** Product version *)
-val _product_version : string
-
-(** Build number *)
-val _build_number : string
-
-(** Dom0 kernel version *)
-val _kernel_version : string
-
-(** Xen version *)
-val _xen_version : string
-
-(** Date on which the host was installed *)
-val _installation_date : string
-
-(** UUID of the default SR (?) *)
-val _default_sr : string
-
-(** Device path of primary disk *)
-val _primary_disk : string
-
-(** Device path of backup partition *)
-val _backup_partition : string
-
-(** UUID of the Host object in the xapi database *)
-val _installation_uuid : string
-
-(** Device path of the default SR used for local storage *)
-val _default_sr_physdevs : string
-
-(** Memory size of dom0 (?) *)
-val _dom0_mem : string
-
-
-(* Keys defined in Rio *)
-(** UUID of the control domain (dom0) *)
-val _control_domain_uuid : string
-
-(** UUID of the management PIF *)
-val _management_interface : string
-
-(* Keys defined in Miami *)
-(** OEM manufacturer name *)
-val _oem_manufacturer : string
-
-(** OEM model name *)
-val _oem_model : string
-
-(** OEM edition build number *)
-val _oem_build_number : string
-
-(** Machine serial number *)
-val _machine_serial_number : string
-
-(** Machine serial name *)
-val _machine_serial_name : string
-
-(* Keys defined in Orlando, redefined in MNR *)
-(** List of bridges that are automatically brought up when the host starts up *)
-val _current_interfaces : string