Skip to content

Allow custom NTP servers for CPVM #11210

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

Merged
merged 2 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions engine/api/src/main/java/com/cloud/vm/VirtualMachineGuru.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.ca.CAManager;
import org.apache.cloudstack.framework.ca.Certificate;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.utils.security.CertUtils;
import org.apache.cloudstack.utils.security.KeyStoreUtils;

Expand All @@ -37,6 +38,9 @@
*/
public interface VirtualMachineGuru {

static final ConfigKey<String> NTPServerConfig = new ConfigKey<String>(String.class, "ntp.server.list", "Advanced", null,
"Comma separated list of NTP servers to configure in System VMs", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);

boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,10 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
buf.append(" vmpassword=").append(configurationDao.getValue("system.vm.password"));
}

if (StringUtils.isNotEmpty(NTPServerConfig.value())) {
buf.append(" ntpserverlist=").append(NTPServerConfig.value().replaceAll("\\s+",""));
}

for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
if (nic.getIPv4Address() == null) {
Expand Down Expand Up @@ -1506,7 +1510,7 @@ public boolean canScan() {
public Long[] getScannablePools() {
List<Long> zoneIds = dataCenterDao.listEnabledNonEdgeZoneIds();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Enabled non-edge zones available for scan: %s", org.apache.commons.lang3.StringUtils.join(zoneIds, ",")));
logger.debug(String.format("Enabled non-edge zones available for scan: %s", StringUtils.join(zoneIds, ",")));
}
return zoneIds.toArray(Long[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar

private final GlobalLock _allocLock = GlobalLock.getInternLock(getAllocLockName());

static final ConfigKey<String> NTPServerConfig = new ConfigKey<String>(String.class, "ntp.server.list", "Advanced", null,
"Comma separated list of NTP servers to configure in Secondary storage VM", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);

static final ConfigKey<Integer> MaxNumberOfSsvmsForMigration = new ConfigKey<Integer>("Advanced", Integer.class, "max.ssvm.count", "5",
"Number of additional SSVMs to handle migration of data objects concurrently", true, ConfigKey.Scope.Global);

Expand Down Expand Up @@ -1178,7 +1175,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
}

if (NTPServerConfig.value() != null) {
if (StringUtils.isNotEmpty(NTPServerConfig.value())) {
buf.append(" ntpserverlist=").append(NTPServerConfig.value().replaceAll("\\s+",""));
}

Expand Down
6 changes: 3 additions & 3 deletions systemvm/debian/opt/cloud/bin/setup/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ getPublicIp() {

setup_ntp() {
log_it "Setting up NTP"
NTP_CONF_FILE="/etc/ntp.conf"
NTP_CONF_FILE="/etc/ntpsec/ntp.conf"
if [ -f $NTP_CONF_FILE ]
then
IFS=',' read -a server_list <<< "$NTP_SERVER_LIST"
Expand All @@ -692,9 +692,9 @@ setup_ntp() {
do
server=$(echo ${server_list[iterator]} | tr -d '\r')
PATTERN="server $server"
sed -i "0,/^#server/s//$PATTERN\n#server/" $NTP_CONF_FILE
sed -i "0,/^# server/s//$PATTERN\n# server/" $NTP_CONF_FILE
done
systemctl enable ntp
systemctl enable --now --no-block ntp
else
log_it "NTP configuration file not found"
fi
Expand Down
4 changes: 4 additions & 0 deletions systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ setup_console_proxy() {
disable_rpfilter
enable_fwding 0
enable_irqbalance 0
if [[ -n "$NTP_SERVER_LIST" ]]; then
setup_ntp
systemctl restart ntp
fi
rm -f /etc/logrotate.d/cloud

}
Expand Down
1 change: 1 addition & 0 deletions systemvm/debian/opt/cloud/bin/setup/secstorage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ HTTP
enable_fwding 0
enable_irqbalance 0
setup_ntp
systemctl restart ntp

rm -f /etc/logrotate.d/cloud
}
Expand Down
Loading