From: Matthias Goergens Date: Tue, 12 Oct 2010 09:52:34 +0000 (+0100) Subject: CA-43574 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2f14b567162b717c931b613831d0facfa07cd991;p=xcp%2Fxen-api.git CA-43574 The build-number that xapi displays for a host now comes from /etx/xensource-inventory instead of the branded in build-number, when xapi is build. The former behaviour lead to discrepancies. Signed-off-by: Matthias Goergens --- diff --git a/Makefile b/Makefile index 4a7bff04..749d870f 100644 --- a/Makefile +++ b/Makefile @@ -84,12 +84,13 @@ import-v6: .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: diff --git a/ocaml/util/OMakefile b/ocaml/util/OMakefile index 3e28587c..fa72bd94 100644 --- a/ocaml/util/OMakefile +++ b/ocaml/util/OMakefile @@ -1,5 +1,7 @@ -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) diff --git a/ocaml/util/util_globs_inventory.ml b/ocaml/util/util_globs_inventory.ml new file mode 100644 index 00000000..797a88f2 --- /dev/null +++ b/ocaml/util/util_globs_inventory.ml @@ -0,0 +1,2 @@ +(* path to the xensource inventory file *) +let inventory_filename = "/etc/xensource-inventory" diff --git a/ocaml/util/util_inventory.ml b/ocaml/util/util_inventory.ml new file mode 100644 index 00000000..8e675a23 --- /dev/null +++ b/ocaml/util/util_inventory.ml @@ -0,0 +1,105 @@ +(* + * 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" diff --git a/ocaml/util/util_inventory.mli b/ocaml/util/util_inventory.mli new file mode 100644 index 00000000..b8d89ac1 --- /dev/null +++ b/ocaml/util/util_inventory.mli @@ -0,0 +1,108 @@ +(* + * 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 diff --git a/ocaml/util/version.mli b/ocaml/util/version.mli new file mode 100644 index 00000000..3a5ef6e4 --- /dev/null +++ b/ocaml/util/version.mli @@ -0,0 +1,6 @@ +val hg_id : string +val hostname : string +val date : string +val product_version : string +val product_brand : string +val build_number : string diff --git a/ocaml/xapi/OMakefile b/ocaml/xapi/OMakefile index 8e83061c..36872d5a 100644 --- a/ocaml/xapi/OMakefile +++ b/ocaml/xapi/OMakefile @@ -1,5 +1,5 @@ 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/ \ diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index b211a819..ced62435 100644 --- a/ocaml/xapi/xapi_globs.ml +++ b/ocaml/xapi/xapi_globs.ml @@ -16,6 +16,7 @@ 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 @@ -90,9 +91,6 @@ let host_assumed_dead_interval = 600.0 (* 10 minutes *) 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." diff --git a/ocaml/xapi/xapi_inventory.ml b/ocaml/xapi/xapi_inventory.ml index 617b7652..11086a35 100644 --- a/ocaml/xapi/xapi_inventory.ml +++ b/ocaml/xapi/xapi_inventory.ml @@ -1,113 +1,2 @@ -(* - * 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 diff --git a/ocaml/xapi/xapi_inventory.mli b/ocaml/xapi/xapi_inventory.mli deleted file mode 100644 index b8d89ac1..00000000 --- a/ocaml/xapi/xapi_inventory.mli +++ /dev/null @@ -1,108 +0,0 @@ -(* - * 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