Skip to content

Commit 890386e

Browse files
authored
Allow custom NTP servers for CPVM (#11210)
1 parent a51a04e commit 890386e

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

engine/api/src/main/java/com/cloud/vm/VirtualMachineGuru.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.utils.exception.CloudRuntimeException;
2525
import org.apache.cloudstack.ca.CAManager;
2626
import org.apache.cloudstack.framework.ca.Certificate;
27+
import org.apache.cloudstack.framework.config.ConfigKey;
2728
import org.apache.cloudstack.utils.security.CertUtils;
2829
import org.apache.cloudstack.utils.security.KeyStoreUtils;
2930

@@ -37,6 +38,9 @@
3738
*/
3839
public interface VirtualMachineGuru {
3940

41+
static final ConfigKey<String> NTPServerConfig = new ConfigKey<String>(String.class, "ntp.server.list", "Advanced", null,
42+
"Comma separated list of NTP servers to configure in System VMs", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
43+
4044
boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context);
4145

4246
/**

server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,10 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
12761276
buf.append(" vmpassword=").append(configurationDao.getValue("system.vm.password"));
12771277
}
12781278

1279+
if (StringUtils.isNotEmpty(NTPServerConfig.value())) {
1280+
buf.append(" ntpserverlist=").append(NTPServerConfig.value().replaceAll("\\s+",""));
1281+
}
1282+
12791283
for (NicProfile nic : profile.getNics()) {
12801284
int deviceId = nic.getDeviceId();
12811285
if (nic.getIPv4Address() == null) {
@@ -1506,7 +1510,7 @@ public boolean canScan() {
15061510
public Long[] getScannablePools() {
15071511
List<Long> zoneIds = dataCenterDao.listEnabledNonEdgeZoneIds();
15081512
if (logger.isDebugEnabled()) {
1509-
logger.debug(String.format("Enabled non-edge zones available for scan: %s", org.apache.commons.lang3.StringUtils.join(zoneIds, ",")));
1513+
logger.debug(String.format("Enabled non-edge zones available for scan: %s", StringUtils.join(zoneIds, ",")));
15101514
}
15111515
return zoneIds.toArray(Long[]::new);
15121516
}

services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
268268

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

271-
static final ConfigKey<String> NTPServerConfig = new ConfigKey<String>(String.class, "ntp.server.list", "Advanced", null,
272-
"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);
273-
274271
static final ConfigKey<Integer> MaxNumberOfSsvmsForMigration = new ConfigKey<Integer>("Advanced", Integer.class, "max.ssvm.count", "5",
275272
"Number of additional SSVMs to handle migration of data objects concurrently", true, ConfigKey.Scope.Global);
276273

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

1181-
if (NTPServerConfig.value() != null) {
1178+
if (StringUtils.isNotEmpty(NTPServerConfig.value())) {
11821179
buf.append(" ntpserverlist=").append(NTPServerConfig.value().replaceAll("\\s+",""));
11831180
}
11841181

systemvm/debian/opt/cloud/bin/setup/common.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ getPublicIp() {
683683

684684
setup_ntp() {
685685
log_it "Setting up NTP"
686-
NTP_CONF_FILE="/etc/ntp.conf"
686+
NTP_CONF_FILE="/etc/ntpsec/ntp.conf"
687687
if [ -f $NTP_CONF_FILE ]
688688
then
689689
IFS=',' read -a server_list <<< "$NTP_SERVER_LIST"
@@ -692,9 +692,9 @@ setup_ntp() {
692692
do
693693
server=$(echo ${server_list[iterator]} | tr -d '\r')
694694
PATTERN="server $server"
695-
sed -i "0,/^#server/s//$PATTERN\n#server/" $NTP_CONF_FILE
695+
sed -i "0,/^# server/s//$PATTERN\n# server/" $NTP_CONF_FILE
696696
done
697-
systemctl enable ntp
697+
systemctl enable --now --no-block ntp
698698
else
699699
log_it "NTP configuration file not found"
700700
fi

systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ setup_console_proxy() {
4040
disable_rpfilter
4141
enable_fwding 0
4242
enable_irqbalance 0
43+
if [[ -n "$NTP_SERVER_LIST" ]]; then
44+
setup_ntp
45+
systemctl restart ntp
46+
fi
4347
rm -f /etc/logrotate.d/cloud
4448

4549
}

systemvm/debian/opt/cloud/bin/setup/secstorage.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ HTTP
8282
enable_fwding 0
8383
enable_irqbalance 0
8484
setup_ntp
85+
systemctl restart ntp
8586

8687
rm -f /etc/logrotate.d/cloud
8788
}

0 commit comments

Comments
 (0)