-
Notifications
You must be signed in to change notification settings - Fork 292
CP-54471 Configure Dom0 NTP via XAPI #6689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/config-ntp-timezone-maxcstate
Are you sure you want to change the base?
CP-54471 Configure Dom0 NTP via XAPI #6689
Conversation
Examles: def set_mode(mode):
session.xenapi.host.set_ntp_mode(host_ref, mode)
def set_custom_servers(servers):
session.xenapi.host.set_ntp_custom_servers(host_ref, servers)
def enable_ntp():
session.xenapi.host.enable_ntp(host_ref)
def disable_ntp():
session.xenapi.host.disable_ntp(host_ref)
def show():
enabled = session.xenapi.host.get_ntp_enabled(host_ref)
mode = session.xenapi.host.get_ntp_mode(host_ref)
custom_servers = session.xenapi.host.get_ntp_custom_servers(host_ref)
status = session.xenapi.host.get_ntp_servers_status(host_ref)
print(f'enabled {enabled}; mode {mode}; custom_servers {custom_servers}; status {status}')
def init():
set_mode('ntp_mode_default')
set_custom_servers([])
disable_ntp()
init()
show()
set_mode('ntp_mode_dhcp')
show()
enable_ntp()
time.sleep(5)
show()
set_mode('ntp_mode_default')
time.sleep(5)
show()
set_custom_servers(['time.google.com', 'time.windows.com', 'time.apple.com'])
set_mode('ntp_mode_custom')
time.sleep(5)
show() output:
xe
|
Did you mean |
ocaml/xapi/xapi_host_ntp.ml
Outdated
|
||
let chrony_conf = "/etc/chrony.conf" | ||
|
||
let chrony_script = "/etc/dhcp/dhclient.d/chrony.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually scripts are added to the list of requited commands in ocaml/idl
so xapi will refuse to run if any of them are missing. Is there any reason this shouldn't be the case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I am not aware of this. Let me check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean xapi_globs.ml
right?
How about Active Directory? IIUC that relies on a working clock synchronization with the AD servers (which may be out of sync with NTP, e.g. we've had situations where they were 30m off). |
- write ntp servers to chrony.conf - interaction with dhclient - handle /run/chrony-dhcp/$interface.sources - handle chrony.sh - restart/enable/disable chronyd Signed-off-by: Changlei Li <[email protected]>
2d3bf3b
to
d52e6d9
Compare
d52e6d9
to
f2c3a5c
Compare
Signed-off-by: Changlei Li <[email protected]>
Signed-off-by: Changlei Li <[email protected]>
Signed-off-by: Changlei Li <[email protected]>
Signed-off-by: Changlei Li <[email protected]>
f2c3a5c
to
97d6734
Compare
It's a good point. But it is beyond the feature scope. Maybe worth exploring in future discussions or tickets |
~ssh_enabled_timeout ~ssh_expiry ~console_idle_timeout ~ssh_auto_mode | ||
~max_cstate:"" ~secure_boot ; | ||
~max_cstate:"" ~secure_boot ~ntp_mode:`ntp_mode_dhcp ~ntp_custom_servers:[] | ||
~ntp_enabled:false ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible the default ntp service status is enabled after XS installation? If so, I would suggest add synchronization for the ntp service status when xapi starts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I need consider more for the dbsync (like ntp_mode, compatibility for old default ntp servers etc.). So, I plan to handle it in a new PR and ticket.
ocaml/xapi/xapi_host.ml
Outdated
let open Xapi_host_ntp in | ||
let ensure_custom_servers_exist servers = | ||
if servers = [] then | ||
Helpers.internal_error "ntp_custom_servers is empty, please set first" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about raise an api_errors
? internal_error
seems like an error caused by some XS internal issue. But actually this error is caused by a wrong customer configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
xe error:
# xe host-param-set uuid=20370b70-d4df-4d43-b3a0-d0ad0227f022 ntp-mode=ntp_mode_custom
The NTP configuration is invalid.
reason: Can't set ntp_mode_custom when ntp_custom_servers is empty
# xe host-param-set uuid=20370b70-d4df-4d43-b3a0-d0ad0227f022 ntp-custom-servers=""
The NTP configuration is invalid.
reason: Can't set ntp_custom_servers empty when ntp_mode is custom
python sdk exception:
['INVALID_NTP_CONFIG', "Can't set ntp_mode_custom when ntp_custom_servers is empty"]
['INVALID_NTP_CONFIG', "Can't set ntp_custom_servers empty when ntp_mode is custom"]
Db.Host.set_ntp_mode ~__context ~self ~value | ||
) | ||
|
||
let set_ntp_custom_servers ~__context ~self ~value = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check the IP/domain format here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me consider it. But it seems hard to construct a valid domain format rule to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will not check to format as it's hard to determine the valid domain format. And they will be written to server xxxxx iburst
to chrony conf. ntp service will handle them. If incorrect, the ntp service will be abnormal due to the user's wrong configuration.
Signed-off-by: Changlei Li <[email protected]>
New filed:
host.ntp_mode
,host.ntp_custom_servers
New API:
host.set_ntp_mode
,host.set_ntp_custom_servers
,host.get_ntp_mode
,host.get_ntp_custom_servers
,host.get_ntp_servers_status
.ntp_mode_dhcp: In this mode, ntp uses the dhcp assigned ntp servers as sources. In Dom0, dhclient triggers
chrony.sh
to update the ntp servers when network event happens. It writes ntp servers to/run/chrony-dhcp/$interface.sources
and the dir/run/chrony-dhcp
is included inchrony.conf
. The dhclient also stores dhcp lease in/var/lib/xcp/dhclient-$interface.leases
, see https://github.com/xapi-project/xen-api/blob/v25.31.0/ocaml/networkd/lib/network_utils.ml#L925. When switch ntp mode to dhcp, XAPI checks the lease file and finds ntp server then fills chrony-dhcp file. The exec permission ofchrony.sh
is added. When swith ntp mode from dhcp to others, XAPI removes the chrony-dhcp files and the exec permission ofchrony.sh
. The operation is same with xsconsole https://github.com/xapi-project/xsconsole/blob/v11.1.1/XSConsoleData.py#L593. In this feature, xsconsole will change to use XenAPI to manage ntp later to avoid conflict.ntp_mode_custom: In this mode, ntp uses
host.ntp_custom_servers
as sources. This is implemented by changingchrony.conf
and restart chronyd.host.ntp_custom_servers
is set by the user.ntp_mode_default: In this mode, ntp uses default-ntp-servers in XAPI config file.
The dbsync, more APIs about NTP will be in following PRs.