Skip to content

Commit 02ee3af

Browse files
authored
CP-54476 Merge ntp disable/enable to ntp mode (#6765)
As the doc PR #6745 shows, the enable/disable ntp APIs and host.ntp_enabled field can be merged into host.ntp_mode. Now, the ntp modes are DHCP, Custom, Factory and Disabled. This PR also updates the datamodel lifecycle and bumps up the schema.
2 parents 442efae + 1b698f0 commit 02ee3af

File tree

15 files changed

+112
-159
lines changed

15 files changed

+112
-159
lines changed

doc/content/design/host-ntp-time.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ cache for the getter APIs.
3838

3939
New fields:
4040
`host.ntp_mode`, enum host_ntp_mode(DHCP, Custom, Factory, Disabled)
41-
`host.ntp_custom_servers`, string set
42-
`host.ntp_enabled`, bool
41+
`host.ntp_custom_servers`, string set
4342

4443
New APIs: `host.set_ntp_mode`, `host.set_ntp_custom_servers`, `host.get_ntp_mode`,
4544
`host.get_ntp_custom_servers`, `host.get_ntp_servers_status`
@@ -201,7 +200,6 @@ host.timezone
201200
host.set_timezone
202201
host.list_timezones
203202
host.get_timezone
204-
host.get_ntp_enabled
205203
host.get_ntp_synchronized
206204
host.set_ntp_mode
207205
host.get_ntp_mode

ocaml/idl/datamodel_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open Datamodel_roles
1010
to leave a gap for potential hotfixes needing to increment the schema version.*)
1111
let schema_major_vsn = 5
1212

13-
let schema_minor_vsn = 791
13+
let schema_minor_vsn = 792
1414

1515
(* Historical schema versions just in case this is useful later *)
1616
let rio_schema_major_vsn = 5

ocaml/idl/datamodel_host.ml

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,11 +2579,10 @@ let host_ntp_mode =
25792579
Enum
25802580
( "host_ntp_mode"
25812581
, [
2582-
("ntp_mode_dhcp", "Using NTP servers assigned by DHCP to sync time")
2583-
; ( "ntp_mode_custom"
2584-
, "Using custom NTP servers configured by user to sync time"
2585-
)
2586-
; ("ntp_mode_default", "Using default NTP servers to sync time")
2582+
("DHCP", "Using NTP servers assigned by DHCP to sync time")
2583+
; ("Custom", "Using custom NTP servers configured by user to sync time")
2584+
; ("Factory", "Using built-in NTP servers to sync time")
2585+
; ("Disabled", "NTP is disabled on the host")
25872586
]
25882587
)
25892588

@@ -2606,16 +2605,6 @@ let set_ntp_custom_servers =
26062605
]
26072606
~allowed_roles:_R_POOL_OP ()
26082607

2609-
let disable_ntp =
2610-
call ~name:"disable_ntp" ~lifecycle:[] ~doc:"Disable NTP on the host"
2611-
~params:[(Ref _host, "self", "The host")]
2612-
~allowed_roles:_R_POOL_OP ()
2613-
2614-
let enable_ntp =
2615-
call ~name:"enable_ntp" ~lifecycle:[] ~doc:"Enable NTP on the host"
2616-
~params:[(Ref _host, "self", "The host")]
2617-
~allowed_roles:_R_POOL_OP ()
2618-
26192608
let get_ntp_servers_status =
26202609
call ~name:"get_ntp_servers_status" ~lifecycle:[]
26212610
~doc:"Get the NTP servers status on the host"
@@ -2822,8 +2811,6 @@ let t =
28222811
; set_max_cstate
28232812
; set_ntp_mode
28242813
; set_ntp_custom_servers
2825-
; disable_ntp
2826-
; enable_ntp
28272814
; get_ntp_servers_status
28282815
; set_timezone
28292816
; list_timezones
@@ -3297,15 +3284,12 @@ let t =
32973284
~default_value:(Some (VBool false)) "secure_boot"
32983285
"Whether the host has booted in secure boot mode"
32993286
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:host_ntp_mode
3300-
~default_value:(Some (VEnum "ntp_mode_dhcp")) "ntp_mode"
3287+
~default_value:(Some (VEnum "Factory")) "ntp_mode"
33013288
"Indicates NTP servers are assigned by DHCP, or configured by \
3302-
user, or the default servers"
3289+
user, or the factory servers, or NTP is disabled"
33033290
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:(Set String)
33043291
~default_value:(Some (VSet [])) "ntp_custom_servers"
3305-
"The set of NTP servers configured for the host"
3306-
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:Bool
3307-
~default_value:(Some (VBool false)) "ntp_enabled"
3308-
"Reflects whether NTP is enabled on the host"
3292+
"Custom NTP servers configured by users, used in Custom NTP mode"
33093293
; field ~qualifier:DynamicRO ~lifecycle:[] ~ty:String
33103294
~default_value:(Some (VString "UTC")) "timezone"
33113295
"The time zone identifier as defined in the IANA Time Zone Database"

ocaml/idl/datamodel_lifecycle.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ let prototyped_of_field = function
9797
Some "22.26.0"
9898
| "SM", "host_pending_features" ->
9999
Some "24.37.0"
100+
| "host", "timezone" ->
101+
Some "25.37.0-next"
102+
| "host", "ntp_custom_servers" ->
103+
Some "25.37.0-next"
104+
| "host", "ntp_mode" ->
105+
Some "25.37.0-next"
100106
| "host", "secure_boot" ->
101107
Some "25.31.0"
108+
| "host", "max_cstate" ->
109+
Some "25.37.0-next"
102110
| "host", "ssh_auto_mode" ->
103111
Some "25.27.0"
104112
| "host", "console_idle_timeout" ->
@@ -225,6 +233,22 @@ let prototyped_of_message = function
225233
Some "22.26.0"
226234
| "VTPM", "create" ->
227235
Some "22.26.0"
236+
| "host", "set_servertime" ->
237+
Some "25.37.0-next"
238+
| "host", "get_ntp_synchronized" ->
239+
Some "25.37.0-next"
240+
| "host", "list_timezones" ->
241+
Some "25.37.0-next"
242+
| "host", "set_timezone" ->
243+
Some "25.37.0-next"
244+
| "host", "get_ntp_servers_status" ->
245+
Some "25.37.0-next"
246+
| "host", "set_ntp_custom_servers" ->
247+
Some "25.37.0-next"
248+
| "host", "set_ntp_mode" ->
249+
Some "25.37.0-next"
250+
| "host", "set_max_cstate" ->
251+
Some "25.37.0-next"
228252
| "host", "update_firewalld_service_status" ->
229253
Some "25.34.0"
230254
| "host", "get_tracked_user_agents" ->

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
33
(* BEWARE: if this changes, check that schema has been bumped accordingly in
44
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)
55

6-
let last_known_schema_hash = "c72edb27945bceb074de3fa54381ddd4"
6+
let last_known_schema_hash = "d8cb04ccddfd91ca3f0f9074dcf7c219"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/tests/common/test_common.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ let make_host2 ~__context ?(ref = Ref.make ()) ?(uuid = make_uuid ())
224224
~pending_guidances_recommended:[] ~pending_guidances_full:[]
225225
~last_update_hash:"" ~ssh_enabled:true ~ssh_enabled_timeout:0L
226226
~ssh_expiry:Date.epoch ~console_idle_timeout:0L ~ssh_auto_mode:false
227-
~max_cstate:"" ~secure_boot:false ~ntp_mode:`ntp_mode_dhcp
228-
~ntp_custom_servers:[] ~ntp_enabled:false ~timezone:"UTC" ;
227+
~max_cstate:"" ~secure_boot:false ~ntp_mode:`Factory ~ntp_custom_servers:[]
228+
~timezone:"UTC" ;
229229
ref
230230

231231
let make_pif ~__context ~network ~host ?(device = "eth0")

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,24 +1098,6 @@ let rec cmdtable_data : (string * cmd_spec) list =
10981098
; flags= [Neverforward]
10991099
}
11001100
)
1101-
; ( "host-enable-ntp"
1102-
, {
1103-
reqd= []
1104-
; optn= []
1105-
; help= "Enable ntp service on the host."
1106-
; implementation= No_fd Cli_operations.host_enable_ntp
1107-
; flags= [Host_selectors]
1108-
}
1109-
)
1110-
; ( "host-disable-ntp"
1111-
, {
1112-
reqd= []
1113-
; optn= []
1114-
; help= "Disable ntp service on the host."
1115-
; implementation= No_fd Cli_operations.host_disable_ntp
1116-
; flags= [Host_selectors]
1117-
}
1118-
)
11191101
; ( "patch-upload"
11201102
, {
11211103
reqd= ["file-name"]

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7820,26 +7820,6 @@ let host_disable_ssh _printer rpc session_id params =
78207820
params []
78217821
)
78227822

7823-
let host_enable_ntp _printer rpc session_id params =
7824-
ignore
7825-
(do_host_op rpc session_id
7826-
(fun _ host ->
7827-
let host = host.getref () in
7828-
Client.Host.enable_ntp ~rpc ~session_id ~self:host
7829-
)
7830-
params []
7831-
)
7832-
7833-
let host_disable_ntp _printer rpc session_id params =
7834-
ignore
7835-
(do_host_op rpc session_id
7836-
(fun _ host ->
7837-
let host = host.getref () in
7838-
Client.Host.disable_ntp ~rpc ~session_id ~self:host
7839-
)
7840-
params []
7841-
)
7842-
78437823
module SDN_controller = struct
78447824
let introduce printer rpc session_id params =
78457825
let port =

ocaml/xapi-cli-server/records.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,9 +3423,6 @@ let host_record rpc session_id host =
34233423
)
34243424
)
34253425
()
3426-
; make_field ~name:"ntp_enabled"
3427-
~get:(fun () -> string_of_bool (x ()).API.host_ntp_enabled)
3428-
()
34293426
; make_field ~name:"timezone"
34303427
~get:(fun () -> (x ()).API.host_timezone)
34313428
~set:(fun value ->

ocaml/xapi/message_forwarding.ml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,18 +4152,6 @@ functor
41524152
let remote_fn = Client.Host.set_ntp_custom_servers ~self ~value in
41534153
do_op_on ~local_fn ~__context ~host:self ~remote_fn
41544154

4155-
let enable_ntp ~__context ~self =
4156-
info "Host.enable_ntp: host='%s'" (host_uuid ~__context self) ;
4157-
let local_fn = Local.Host.enable_ntp ~self in
4158-
let remote_fn = Client.Host.enable_ntp ~self in
4159-
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4160-
4161-
let disable_ntp ~__context ~self =
4162-
info "Host.disable_ntp: host='%s'" (host_uuid ~__context self) ;
4163-
let local_fn = Local.Host.disable_ntp ~self in
4164-
let remote_fn = Client.Host.disable_ntp ~self in
4165-
do_op_on ~local_fn ~__context ~host:self ~remote_fn
4166-
41674155
let get_ntp_servers_status ~__context ~self =
41684156
info "Host.get_ntp_servers_status: host = '%s'"
41694157
(host_uuid ~__context self) ;
@@ -4195,7 +4183,7 @@ functor
41954183
info "Host.set_servertime : host = '%s'; value = '%s'"
41964184
(host_uuid ~__context self)
41974185
(Clock.Date.to_rfc3339 value) ;
4198-
if Db.Host.get_ntp_enabled ~__context ~self then
4186+
if Db.Host.get_ntp_mode ~__context ~self <> `Disabled then
41994187
raise
42004188
(Api_errors.Server_error
42014189
(Api_errors.not_allowed_when_ntp_is_enabled, [Ref.string_of self])

0 commit comments

Comments
 (0)