You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pe...@apache.org on 2025/07/16 00:33:24 UTC

(cloudstack) 01/01: Allow custom NTP servers for CPVM

This is an automated email from the ASF dual-hosted git repository.

pearl11594 pushed a commit to branch setup-cpvm-ntp
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit ee1009ae5624b39ece723151162eb049caad10be
Author: Pearl Dsilva <pe...@gmail.com>
AuthorDate: Tue Jul 15 20:33:07 2025 -0400

    Allow custom NTP servers for CPVM
---
 .../java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java     | 9 ++++++++-
 systemvm/debian/opt/cloud/bin/setup/common.sh                    | 6 +++---
 systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh              | 3 +++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 4331cc494c4..ac2e4cd9d1e 100644
--- a/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -258,6 +258,9 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
 
     protected Set<State> availableVmStateOnAssignProxy = new HashSet<>(Arrays.asList(State.Starting, State.Running, State.Stopping, State.Migrating));
 
+    static final ConfigKey<String> CPVMNTPServerConfig = new ConfigKey<String>(String.class, "cpvm.ntp.server.list", "Advanced", null,
+            "Comma separated list of NTP servers to configure in the Console Proxy VM", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
+
     @Inject
     private KeystoreDao _ksDao;
     @Inject
@@ -1276,6 +1279,10 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
             buf.append(" vmpassword=").append(configurationDao.getValue("system.vm.password"));
         }
 
+        if (CPVMNTPServerConfig.value() != null) {
+            buf.append(" ntpserverlist=").append(CPVMNTPServerConfig.value().replaceAll("\\s+",""));
+        }
+
         for (NicProfile nic : profile.getNics()) {
             int deviceId = nic.getDeviceId();
             if (nic.getIPv4Address() == null) {
@@ -1623,7 +1630,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
 
     @Override
     public ConfigKey<?>[] getConfigKeys() {
-        return new ConfigKey<?>[] { ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled };
+        return new ConfigKey<?>[] { ConsoleProxySslEnabled, NoVncConsoleDefault, NoVncConsoleSourceIpCheckEnabled, CPVMNTPServerConfig };
     }
 
     protected ConsoleProxyStatus parseJsonToConsoleProxyStatus(String json) throws JsonParseException {
diff --git a/systemvm/debian/opt/cloud/bin/setup/common.sh b/systemvm/debian/opt/cloud/bin/setup/common.sh
index 5156d77a6a6..ed38d44384d 100755
--- a/systemvm/debian/opt/cloud/bin/setup/common.sh
+++ b/systemvm/debian/opt/cloud/bin/setup/common.sh
@@ -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"
@@ -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 ntp
     else
         log_it "NTP configuration file not found"
     fi
diff --git a/systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh b/systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh
index 596ad50ab50..cb794bafbe4 100755
--- a/systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh
+++ b/systemvm/debian/opt/cloud/bin/setup/consoleproxy.sh
@@ -40,6 +40,9 @@ setup_console_proxy() {
   disable_rpfilter
   enable_fwding 0
   enable_irqbalance 0
+  if [[ -n "$NTP_SERVER_LIST" ]]; then
+    setup_ntp
+  fi
   rm -f /etc/logrotate.d/cloud
 
 }