<commit_before>(*
 * 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.
 *)

(** A central location for settings related to xapi *)

open Xstringext
open Printf

module D = Debug.Make(struct let name="xapi_globs" end)

(* set this to true to enable XSM to out-of-pool SRs with matching UUID *)
let relax_xsm_sr_check = ref true

(* xapi process returns this code on exit when it wants to be restarted *)
let restart_return_code = 123

let pool_secret = ref ""

let localhost_ref : [`host] Ref.t ref = ref Ref.null

(* xapi version *)
let version_major = Version.xapi_version_major
let version_minor = Version.xapi_version_minor
let xapi_user_agent = "xapi/"^(string_of_int version_major)^"."^(string_of_int version_minor)

(* api version *)
(* Normally xencenter_min_verstring and xencenter_max_verstring below should be set to the same value,
 * but there are exceptions: please consult the XenCenter maintainers if in doubt. *)
let api_version_major = 2L
let api_version_minor = 5L
let api_version_string =
  Printf.sprintf "%Ld.%Ld" api_version_major api_version_minor
let api_version_vendor = "XenSource"
let api_version_vendor_implementation = []

(* version of latest tools ISO in filesystem *)
let tools_version_none = (-1, -1, -1, -1)

let tools_version = ref tools_version_none

(* client min/max version range *)
(* xencenter_min should be the lowest version of XenCenter we want the new server to work with. In the
 * (usual) case that we want to force the user to upgrade XenCenter when they upgrade the server,
 * xencenter_min should equal the current version of XenCenter.
 *
 * xencenter_max is not what you would guess after reading the previous paragraph, which would involve
 * predicting the future. Instead, it should always equal the current version of XenCenter. It must not
 * change without issuing a new version of XenCenter. This is used to make sure that even if the user is
 * not required to upgrade, we at least warn them.
 *
 * Please consult the XenCenter maintainers before changing these numbers, because a corresponding change
 * will need to be made in XenCenter *)
let xencenter_min_verstring = "2.5"
let xencenter_max_verstring = "2.5"

(* linux pack vsn key in host.software_version (used for a pool join restriction *)
let linux_pack_vsn_key = "<KEY>"
let packs_dir = ref (Filename.concat "/etc/xensource" "installed-repos")

let ssl_pid = ref 0

let default_cleartext_port = 80
let default_ssl_port = 443

let ips_to_listen_on = "0.0.0.0"

let http_port = default_cleartext_port
let https_port = ref default_ssl_port

let xapi_gc_debug = ref true

let unix_domain_socket = Filename.concat "/var/lib/xcp" "xapi"
let local_storage_unix_domain_socket = Filename.concat "/var/lib/xcp" "storage-local"
let storage_unix_domain_socket = Filename.concat "/var/lib/xcp" "storage"
let local_database = Filename.concat "/var/lib/xcp" "local.db"


(* if a slave in emergency "cannot see master mode" then this flag is set *)
let slave_emergency_mode = ref false

(** Whenever in emergency mode we stash an error here so the user can determine what's wrong
    without trawling through logfiles *)
let emergency_mode_error = ref (Api_errors.Server_error(Api_errors.host_still_booting, []))

let http_realm = "xapi"

let log_config_file = ref (Filename.concat "/etc/xensource" "log.conf")
let db_conf_path = ref (Filename.concat "/etc/xensource" "db.conf")
let remote_db_conf_fragment_path = ref (Filename.concat "/etc/xensource" "remote.db.conf")
let cpu_info_file = ref (Filename.concat "/etc/xensource" "boot_time_cpus")
let initial_host_free_memory_file = "/var/run/nonpersistent/xapi/boot_time_memory"
let using_rrds = ref false

let ready_file = ref ""
let init_complete = ref ""

let hg_changeset = ref "unknown"

(* Keys used in both the software_version (string -> string map) and in the import/export code *)
let _hostname = "hostname"
let _date = "date"
let _product_version = "product_version"
let _product_version_text = "product_version_text"
let _product_version_text_short = "product_version_text_short"
let _platform_name = "platform_name"
let _platform_version = "platform_version"
let _product_brand = "product_brand"
let _build_number = "build_number"
let _git_id = "git_id"
let _api_major = "API_major"
let _api_minor = "API_minor"
let _api_vendor = "API_vendor"
let _api_vendor_implementation = "API_vendor_implementation"
let _xapi_major = "xapi_major"
let _xapi_minor = "xapi_minor"
let _export_vsn = "export_vsn"
let _dbv = "dbv"

(* When comparing two host versions, always treat a host that has platform_version defined as newer
 * than any host that does not have platform_version defined.
 * Substituting this default when a host does not have platform_version defined will be acceptable,
 * as long as a host never has to distinguish between two hosts of different versions which are both
 * older than itself. *)
let default_platform_version = "0.0.0"

(* Used to differentiate between 
   Rio beta2 (0) [no inline checksums, end-of-tar checksum table],
   Rio GA (1) [inline checksums, end-of-tar checksum table]
   and Miami GA (2) [inline checksums, no end-of-tar checksum table] *)
let export_vsn = 2

let software_version () =
	(* In the case of XCP, all product_* fields will be blank. *)
	List.filter (fun (_, value) -> value <> "")
		[_product_version, Version.product_version ();
			_product_version_text,       Version.product_version_text ();
			_product_version_text_short, Version.product_version_text_short ();
			_platform_name, Version.platform_name;
			_platform_version, Version.platform_version;
			 _product_brand,   Version.product_brand ();
			 _build_number,    Version.build_number ();
			 _git_id,           Version.git_id;
			 _hostname,        Version.hostname;
			 _date,            Version.date]

let pygrub_path = "/usr/bin/pygrub"
let eliloader_path = "/usr/bin/eliloader"
let supported_bootloaders = [ "pygrub", pygrub_path;
			      "eliloader", eliloader_path ]

(* Deprecated: *)
let is_guest_installer_network = "is_guest_installer_network"

let is_host_internal_management_network = "is_host_internal_management_network"

(* Used to override the check which blocks VM start or migration if a VIF is on an internal
   network which is pinned to a particular host. *)
let assume_network_is_shared = "assume_network_is_shared"

let auto_scan = "auto-scan" (* if set in SR.other_config, scan the SR in the background *)
let auto_scan_interval = "auto-scan-interval" (* maybe set in Host.other_config *)

let cd_tray_ejector = "cd_tray_ejector"

(* These ports are both served up by vncterm the ports used for the RFB and
   text consoles are p+5900 and p+9500 respectively where p is the port
   specified on the vncterm command line:
     -T, --text            provide telnet access too
     -v, --vnclisten       listen for VNC connection at a given address:port
   The init scripts in dom0 spawn vncterm with -T -v 127.0.0.1:0  *)
let host_console_vncport = 5900L
let host_console_textport = 9500L

let vhd_parent = "vhd-parent" (* set in VDIs backed by VHDs *)

let owner_key = "owner" (* set in VBD other-config to indicate that clients can delete the attached VDI on VM uninstall if they want.. *)
let vbd_backend_key = "backend-kind" (* set in VBD other-config *)

let using_vdi_locking_key = "using-vdi-locking" (* set in Pool other-config to indicate that we should use storage-level (eg VHD) locking *)

let mac_seed = "mac_seed" (* set in a VM to generate MACs by hash chaining *)

let ( ** ) = Int64.mul
let vm_minimum_memory = 16L ** 1024L ** 1024L (* don't start VMs with less than 16 Mb *)

let grant_api_access = "grant_api_access"

(* From Miami GA onward we identify the tools SR with the SR.other_config key: *)
let tools_sr_tag = "xenserver_tools_sr"

(* Rio and Miami beta1 and beta2 used the following name-labels: *)
let rio_tools_sr_name = "XenSource Tools"
let miami_tools_sr_name = "XenServer Tools"

let tools_sr_dir = ref "/opt/xensource/packages/iso"

(* let xenprep_iso_name_label = "xenprep.iso" *) (* TODO use this once the xenprep ISO is available *)
let xenprep_iso_name_label = "xs-tools.iso" (* Temporary stopgap value for dev-testing *)

let xenprep_other_config_key = "xenprep_progress"
let xenprep_other_config_iso_inserted = "ISO_inserted"

let default_template_key = "default_template"
let linux_template_key = "linux_template"
let base_template_name_key = "base_template_name"

(* Keys to explain the presence of dom0 block-attached VBDs: *)
let vbd_task_key = "task_id"<commit_msg>CP-13841 Use the real xenprep.iso<commit_after>(*
 * 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.
 *)

(** A central location for settings related to xapi *)

open Xstringext
open Printf

module D = Debug.Make(struct let name="xapi_globs" end)

(* set this to true to enable XSM to out-of-pool SRs with matching UUID *)
let relax_xsm_sr_check = ref true

(* xapi process returns this code on exit when it wants to be restarted *)
let restart_return_code = 123

let pool_secret = ref ""

let localhost_ref : [`host] Ref.t ref = ref Ref.null

(* xapi version *)
let version_major = Version.xapi_version_major
let version_minor = Version.xapi_version_minor
let xapi_user_agent = "xapi/"^(string_of_int version_major)^"."^(string_of_int version_minor)

(* api version *)
(* Normally xencenter_min_verstring and xencenter_max_verstring below should be set to the same value,
 * but there are exceptions: please consult the XenCenter maintainers if in doubt. *)
let api_version_major = 2L
let api_version_minor = 5L
let api_version_string =
  Printf.sprintf "%Ld.%Ld" api_version_major api_version_minor
let api_version_vendor = "XenSource"
let api_version_vendor_implementation = []

(* version of latest tools ISO in filesystem *)
let tools_version_none = (-1, -1, -1, -1)

let tools_version = ref tools_version_none

(* client min/max version range *)
(* xencenter_min should be the lowest version of XenCenter we want the new server to work with. In the
 * (usual) case that we want to force the user to upgrade XenCenter when they upgrade the server,
 * xencenter_min should equal the current version of XenCenter.
 *
 * xencenter_max is not what you would guess after reading the previous paragraph, which would involve
 * predicting the future. Instead, it should always equal the current version of XenCenter. It must not
 * change without issuing a new version of XenCenter. This is used to make sure that even if the user is
 * not required to upgrade, we at least warn them.
 *
 * Please consult the XenCenter maintainers before changing these numbers, because a corresponding change
 * will need to be made in XenCenter *)
let xencenter_min_verstring = "2.5"
let xencenter_max_verstring = "2.5"

(* linux pack vsn key in host.software_version (used for a pool join restriction *)
let linux_pack_vsn_key = "<KEY>"
let packs_dir = ref (Filename.concat "/etc/xensource" "installed-repos")

let ssl_pid = ref 0

let default_cleartext_port = 80
let default_ssl_port = 443

let ips_to_listen_on = "0.0.0.0"

let http_port = default_cleartext_port
let https_port = ref default_ssl_port

let xapi_gc_debug = ref true

let unix_domain_socket = Filename.concat "/var/lib/xcp" "xapi"
let local_storage_unix_domain_socket = Filename.concat "/var/lib/xcp" "storage-local"
let storage_unix_domain_socket = Filename.concat "/var/lib/xcp" "storage"
let local_database = Filename.concat "/var/lib/xcp" "local.db"


(* if a slave in emergency "cannot see master mode" then this flag is set *)
let slave_emergency_mode = ref false

(** Whenever in emergency mode we stash an error here so the user can determine what's wrong
    without trawling through logfiles *)
let emergency_mode_error = ref (Api_errors.Server_error(Api_errors.host_still_booting, []))

let http_realm = "xapi"

let log_config_file = ref (Filename.concat "/etc/xensource" "log.conf")
let db_conf_path = ref (Filename.concat "/etc/xensource" "db.conf")
let remote_db_conf_fragment_path = ref (Filename.concat "/etc/xensource" "remote.db.conf")
let cpu_info_file = ref (Filename.concat "/etc/xensource" "boot_time_cpus")
let initial_host_free_memory_file = "/var/run/nonpersistent/xapi/boot_time_memory"
let using_rrds = ref false

let ready_file = ref ""
let init_complete = ref ""

let hg_changeset = ref "unknown"

(* Keys used in both the software_version (string -> string map) and in the import/export code *)
let _hostname = "hostname"
let _date = "date"
let _product_version = "product_version"
let _product_version_text = "product_version_text"
let _product_version_text_short = "product_version_text_short"
let _platform_name = "platform_name"
let _platform_version = "platform_version"
let _product_brand = "product_brand"
let _build_number = "build_number"
let _git_id = "git_id"
let _api_major = "API_major"
let _api_minor = "API_minor"
let _api_vendor = "API_vendor"
let _api_vendor_implementation = "API_vendor_implementation"
let _xapi_major = "xapi_major"
let _xapi_minor = "xapi_minor"
let _export_vsn = "export_vsn"
let _dbv = "dbv"

(* When comparing two host versions, always treat a host that has platform_version defined as newer
 * than any host that does not have platform_version defined.
 * Substituting this default when a host does not have platform_version defined will be acceptable,
 * as long as a host never has to distinguish between two hosts of different versions which are both
 * older than itself. *)
let default_platform_version = "0.0.0"

(* Used to differentiate between 
   Rio beta2 (0) [no inline checksums, end-of-tar checksum table],
   Rio GA (1) [inline checksums, end-of-tar checksum table]
   and Miami GA (2) [inline checksums, no end-of-tar checksum table] *)
let export_vsn = 2

let software_version () =
	(* In the case of XCP, all product_* fields will be blank. *)
	List.filter (fun (_, value) -> value <> "")
		[_product_version, Version.product_version ();
			_product_version_text,       Version.product_version_text ();
			_product_version_text_short, Version.product_version_text_short ();
			_platform_name, Version.platform_name;
			_platform_version, Version.platform_version;
			 _product_brand,   Version.product_brand ();
			 _build_number,    Version.build_number ();
			 _git_id,           Version.git_id;
			 _hostname,        Version.hostname;
			 _date,            Version.date]

let pygrub_path = "/usr/bin/pygrub"
let eliloader_path = "/usr/bin/eliloader"
let supported_bootloaders = [ "pygrub", pygrub_path;
			      "eliloader", eliloader_path ]

(* Deprecated: *)
let is_guest_installer_network = "is_guest_installer_network"

let is_host_internal_management_network = "is_host_internal_management_network"

(* Used to override the check which blocks VM start or migration if a VIF is on an internal
   network which is pinned to a particular host. *)
let assume_network_is_shared = "assume_network_is_shared"

let auto_scan = "auto-scan" (* if set in SR.other_config, scan the SR in the background *)
let auto_scan_interval = "auto-scan-interval" (* maybe set in Host.other_config *)

let cd_tray_ejector = "cd_tray_ejector"

(* These ports are both served up by vncterm the ports used for the RFB and
   text consoles are p+5900 and p+9500 respectively where p is the port
   specified on the vncterm command line:
     -T, --text            provide telnet access too
     -v, --vnclisten       listen for VNC connection at a given address:port
   The init scripts in dom0 spawn vncterm with -T -v 127.0.0.1:0  *)
let host_console_vncport = 5900L
let host_console_textport = 9500L

let vhd_parent = "vhd-parent" (* set in VDIs backed by VHDs *)

let owner_key = "owner" (* set in VBD other-config to indicate that clients can delete the attached VDI on VM uninstall if they want.. *)
let vbd_backend_key = "backend-kind" (* set in VBD other-config *)

let using_vdi_locking_key = "using-vdi-locking" (* set in Pool other-config to indicate that we should use storage-level (eg VHD) locking *)

let mac_seed = "mac_seed" (* set in a VM to generate MACs by hash chaining *)

let ( ** ) = Int64.mul
let vm_minimum_memory = 16L ** 1024L ** 1024L (* don't start VMs with less than 16 Mb *)

let grant_api_access = "grant_api_access"

(* From Miami GA onward we identify the tools SR with the SR.other_config key: *)
let tools_sr_tag = "xenserver_tools_sr"

(* Rio and Miami beta1 and beta2 used the following name-labels: *)
let rio_tools_sr_name = "XenSource Tools"
let miami_tools_sr_name = "XenServer Tools"

let tools_sr_dir = ref "/opt/xensource/packages/iso"

let xenprep_iso_name_label = "xenprep.iso"
let xenprep_other_config_key = "xenprep_progress"
let xenprep_other_config_iso_inserted = "ISO_inserted"

let default_template_key = "default_template"
let linux_template_key = "linux_template"
let base_template_name_key = "base_template_name"

(* Keys to explain the presence of dom0 block-attached VBDs: *)
let vbd_task_key = "task_id"
{'fraction_non_alphanumeric': 0.0802451936472555, 'fraction_numerical': 0.00941766508776818, 'mean_word_length': 4.662985168822972, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85071', 'n_tokens_mistral': 5841, 'n_tokens_neox': 5538, 'n_words': 2018}