feat: Implement API to set NTP servers#87
Conversation
Signed-off-by: Felicity Xu <hanyux@nvidia.com>
|
For Dells, you have to issue the following redfish call. Out of experience, setting them in |
|
For HPEs, you have to use |
Signed-off-by: Felicity Xu <hanyux@nvidia.com>
| .client | ||
| .patch_with_if_match("UpdateService", body) | ||
| .await | ||
| fn set_ntp_servers<'a>( |
There was a problem hiding this comment.
AMI servers require PATCH's to be sent with an If-Match header. Instead of delegating it to the standard implementation, do the following:
if servers.is_empty() {
return Ok(());
}
let url = format!("Managers/{}/NetworkProtocol", self.s.manager_id());
let body = HashMap::from([(
"NTP",
serde_json::json!({
"NTPServers": servers,
"ProtocolEnabled": true,
}),
)]);
self.s.client.patch_with_if_match(&url, body).await
| } | ||
|
|
||
| let mut attrs = HashMap::new(); | ||
| attrs.insert("NTPConfigGroup.1.NTPEnable", "Enabled"); |
There was a problem hiding this comment.
Unused slots keep stale values when fewer than 3 servers are passed into set_ntp_servers. We should explicitly blank them out so the set is authoritative. Something like:
let mut attrs = HashMap::from([("NTPConfigGroup.1.NTPEnable", "Enabled")]);
const NTP_KEYS: [&str; 3] = [
"NTPConfigGroup.1.NTP1",
"NTPConfigGroup.1.NTP2",
"NTPConfigGroup.1.NTP3",
];
for (i, key) in NTP_KEYS.into_iter().enumerate() {
// blank unused slots so the set is authoritative
attrs.insert(key, servers.get(i).map_or("", String::as_str));
}
| return Ok(()); | ||
| } | ||
|
|
||
| // iLO supports at most 2 static NTP servers; extra entries are ignored. |
There was a problem hiding this comment.
You can do something like this instead:
let static_ntp_servers: Vec<String> = servers.iter().take(2).cloned().collect();
Also we should log when a user passes in more than 2 servers:
if servers.len() > 2 {
tracing::warn!("iLO supports at most 2 static NTP servers; ignoring {} extra", servers.len() - 2);
}
| return Ok(()); | ||
| } | ||
|
|
||
| let url = format!("Managers/{}/NetworkProtocol", self.manager_id(),); |
There was a problem hiding this comment.
nit: extra comma next to self.manager_id()
|
Also, |
Added a new Redfish API method
set_ntp_serversthat configures a list of NTP servers of the BMC.See issue #548.