dimsijul commented on a change in pull request #4070:
URL: https://github.com/apache/cloudstack/pull/4070#discussion_r426643349



##########
File path: setup/bindir/cloud-set-guest-password.in
##########
@@ -26,25 +26,58 @@
 # Modify this line to specify the user (default is root)
 user=root
 
-# Add your DHCP lease folders here
-DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/* /var/lib/dhcp/*"
+# Add network provider variables here (default means that interface for 
network manager is eth0)
+NETPLAN=/etc/netplan
+IFUPDOWN=/etc/network/interfaces
+NETMAN=/etc/sysconfig/network-scripts
+
+# Add dhcp variables
 PASSWORD_SERVER_PORT=8080
 password_received=0
-file_count=0
 error_count=0
+file_count=0
 
-for DHCP_FILE in $DHCP_FOLDERS; do
-       if [ -f $DHCP_FILE ]; then
-               file_count=$((file_count+1))
-               PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | 
tail -1 | awk '{print $NF}' | tr -d '\;')
+# OS is using netplan
+if [ -d "$NETPLAN" ]; then
+        logger -t "cloud" "Operating System is using netplan"
 
-               if [ -n "$PASSWORD_SERVER_IP" ]; then
-                       logger -t "cloud" "Found password server IP 
$PASSWORD_SERVER_IP in $DHCP_FILE"
-                        break
-               fi
-       fi
-done
+        PASSWORD_SERVER_IP=$(netplan ip leases eth0 | grep SERVER_ADDRESS | 
awk '{split($0,a,"="); print a[2]}')
+
+        if [ -n "$PASSWORD_SERVER_IP" ]; then
+                 logger -t "cloud" "Found password server IP 
$PASSWORD_SERVER_IP in netplan config"
+        fi
+fi
+
+# OS is using ifupdown
+if [ -f "$IFUPDOWN" ]; then
+        logger -t "cloud" "Operating System is using ifupdown"
+
+        DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/* /var/lib/dhcp/*"
+
+        for DHCP_FILE in $DHCP_FOLDERS; do
+                if [ -f $DHCP_FILE ]; then
+                        file_count=$((file_count+1))
+                        PASSWORD_SERVER_IP=$(grep dhcp-server-identifier 
$DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
+
+                        if [ -n "$PASSWORD_SERVER_IP" ]; then
+                                logger -t "cloud" "Found password server IP 
$PASSWORD_SERVER_IP in $DHCP_FILE"
+                                break
+                        fi
+                fi
+        done
+fi
+
+# OS is using network interfaces
+if [ -d "$NETMAN" ]; then
+        logger -t "cloud" "Operating System is using network manager"
+
+        PASSWORD_SERVER_IP=$(nmcli -f IP4.GATEWAY device show eth0 | sed 's/ 
//g' | awk '{split($0,a,":"); print a[2]}')

Review comment:
       I have used this command to retrieve the interface name :
   
   NETINT=$(ip -o -4 route show to default | awk '{print $5}')
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to