Skip to content

Commit a7a4606

Browse files
committed
CA-422072 Add new fields to host create params
For the new added unit test which check host create params, need to add the new fields to create params. This check is mainly for pool join case. Without the params, the values will be set to default values when the supporter host obj is created. Then the value may be lost after pool-join. However, for the fields in the feature, the values will be set by dbsync. So the values can be set correctly after restart during the pool-join. So there will not be defects. On the other hand, there is also no harm for adding them to create_params. It can pass the new added unit test and set the value correctly when host object is created during pool-join. So add them in this commit. Signed-off-by: Changlei Li <changlei.li@cloud.com>
1 parent e02d597 commit a7a4606

7 files changed

Lines changed: 62 additions & 17 deletions

File tree

ocaml/idl/datamodel_host.ml

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,17 @@ let license_remove =
12091209
to the unlicensed edition"
12101210
~allowed_roles:_R_POOL_OP ()
12111211

1212+
let host_ntp_mode =
1213+
Enum
1214+
( "host_ntp_mode"
1215+
, [
1216+
("DHCP", "Using NTP servers assigned by DHCP to sync time")
1217+
; ("Custom", "Using custom NTP servers configured by user to sync time")
1218+
; ("Factory", "Using built-in NTP servers to sync time")
1219+
; ("Disabled", "NTP is disabled on the host")
1220+
]
1221+
)
1222+
12121223
let create_params =
12131224
[
12141225
{
@@ -1406,6 +1417,41 @@ let create_params =
14061417
; param_release= numbered_release "25.38.0-next"
14071418
; param_default= Some (VBool false)
14081419
}
1420+
; {
1421+
param_type= String
1422+
; param_name= "max_cstate"
1423+
; param_doc=
1424+
"The maximum C-state that the host is allowed to enter, \"\" means \
1425+
unlimited; \"N\" means limit to CN; \"N,M\" means limit to CN with \
1426+
max sub cstate M."
1427+
; param_release= numbered_release "25.38.0-next"
1428+
; param_default= Some (VString "")
1429+
}
1430+
; {
1431+
param_type= host_ntp_mode
1432+
; param_name= "ntp_mode"
1433+
; param_doc=
1434+
"Indicates NTP servers are assigned by DHCP, or configured by user, or \
1435+
the factory servers, or NTP is disabled"
1436+
; param_release= numbered_release "25.38.0-next"
1437+
; param_default= Some (VEnum "Factory")
1438+
}
1439+
; {
1440+
param_type= Set String
1441+
; param_name= "ntp_custom_servers"
1442+
; param_doc=
1443+
"Custom NTP servers configured by users, used in Custom NTP mode"
1444+
; param_release= numbered_release "25.38.0-next"
1445+
; param_default= Some (VSet [])
1446+
}
1447+
; {
1448+
param_type= String
1449+
; param_name= "timezone"
1450+
; param_doc=
1451+
"The time zone identifier as defined in the IANA Time Zone Database"
1452+
; param_release= numbered_release "25.38.0-next"
1453+
; param_default= Some (VString "UTC")
1454+
}
14091455
]
14101456

14111457
let create =
@@ -2584,17 +2630,6 @@ let set_max_cstate =
25842630
]
25852631
~allowed_roles:_R_POOL_OP ()
25862632

2587-
let host_ntp_mode =
2588-
Enum
2589-
( "host_ntp_mode"
2590-
, [
2591-
("DHCP", "Using NTP servers assigned by DHCP to sync time")
2592-
; ("Custom", "Using custom NTP servers configured by user to sync time")
2593-
; ("Factory", "Using built-in NTP servers to sync time")
2594-
; ("Disabled", "NTP is disabled on the host")
2595-
]
2596-
)
2597-
25982633
let set_ntp_mode =
25992634
call ~name:"set_ntp_mode" ~lifecycle:[] ~doc:"Set the NTP mode for the host"
26002635
~params:

ocaml/tests/common/test_common.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ let make_host ~__context ?(uuid = make_uuid ()) ?(name_label = "host")
184184
~last_update_hash ~ssh_enabled ~ssh_enabled_timeout ~ssh_expiry
185185
~console_idle_timeout ~ssh_auto_mode ~secure_boot
186186
~software_version:(Xapi_globs.software_version ())
187-
~https_only
187+
~https_only ~max_cstate:"" ~ntp_mode:`Factory ~ntp_custom_servers:[]
188+
~timezone:"UTC"
188189
in
189190
Db.Host.set_cpu_info ~__context ~self:host ~value:default_cpu_info ;
190191
host

ocaml/tests/test_host.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ let add_host __context name =
2727
~ssh_enabled:true ~ssh_enabled_timeout:0L ~ssh_expiry:Clock.Date.epoch
2828
~console_idle_timeout:0L ~ssh_auto_mode:false ~secure_boot:false
2929
~software_version:(Xapi_globs.software_version ())
30-
~https_only:false
30+
~https_only:false ~max_cstate:"" ~ntp_mode:`Factory
31+
~ntp_custom_servers:[] ~timezone:"UTC"
3132
)
3233

3334
(* Creates an unlicensed pool with the maximum number of hosts *)

ocaml/xapi/dbsync_slave.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ let create_localhost ~__context info =
6666
~console_idle_timeout:Constants.default_console_idle_timeout
6767
~ssh_auto_mode:!Xapi_globs.ssh_auto_mode_default
6868
~secure_boot:false ~software_version:[]
69-
~https_only:!Xapi_globs.https_only
69+
~https_only:!Xapi_globs.https_only ~max_cstate:"" ~ntp_mode:`Factory
70+
~ntp_custom_servers:[] ~timezone:"UTC"
7071
in
7172
()
7273

ocaml/xapi/xapi_host.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10291029
~license_params ~edition ~license_server ~local_cache_sr ~chipset_info
10301030
~ssl_legacy:_ ~last_software_update ~last_update_hash ~ssh_enabled
10311031
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode
1032-
~secure_boot ~software_version ~https_only =
1032+
~secure_boot ~software_version ~https_only ~max_cstate ~ntp_mode
1033+
~ntp_custom_servers ~timezone =
10331034
(* fail-safe. We already test this on the joining host, but it's racy, so multiple concurrent
10341035
pool-join might succeed. Note: we do it in this order to avoid a problem checking restrictions during
10351036
the initial setup of the database *)
@@ -1094,8 +1095,7 @@ let create ~__context ~uuid ~name_label ~name_description:_ ~hostname ~address
10941095
~recommended_guidances:[] ~latest_synced_updates_applied:`unknown
10951096
~pending_guidances_recommended:[] ~pending_guidances_full:[] ~ssh_enabled
10961097
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode
1097-
~max_cstate:"" ~secure_boot ~ntp_mode:`Factory ~ntp_custom_servers:[]
1098-
~timezone:"UTC" ;
1098+
~max_cstate ~secure_boot ~ntp_mode ~ntp_custom_servers ~timezone ;
10991099
(* If the host we're creating is us, make sure its set to live *)
11001100
Db.Host_metrics.set_last_updated ~__context ~self:metrics ~value:(Date.now ()) ;
11011101
Db.Host_metrics.set_live ~__context ~self:metrics ~value:host_is_us ;

ocaml/xapi/xapi_host.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ val create :
139139
-> secure_boot:bool
140140
-> software_version:(string * string) list
141141
-> https_only:bool
142+
-> max_cstate:string
143+
-> ntp_mode:API.host_ntp_mode
144+
-> ntp_custom_servers:string list
145+
-> timezone:string
142146
-> [`host] Ref.t
143147

144148
val destroy : __context:Context.t -> self:API.ref_host -> unit

ocaml/xapi/xapi_pool.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ let rec create_or_get_host_on_master __context rpc session_id (host_ref, host) :
10621062
~secure_boot:host.API.host_secure_boot
10631063
~software_version:host.API.host_software_version
10641064
~https_only:host.API.host_https_only
1065+
~max_cstate:host.API.host_max_cstate ~ntp_mode:host.API.host_ntp_mode
1066+
~ntp_custom_servers:host.API.host_ntp_custom_servers
1067+
~timezone:host.API.host_timezone
10651068
in
10661069
(* Copy other-config into newly created host record: *)
10671070
no_exn

0 commit comments

Comments
 (0)