Skip to content

Commit 3ac8194

Browse files
authored
setup: Update cloud-set-guest-password.in (apache#4070)
Update cloud-set-guest-password.in Adaptation of the original script to be able to work with netplan, network manager and ifupdown. Changes have been tested in Cloudstack V 4.13 with the following operating systems and network providers : Ubuntu 16.04 with ifupdown (/etc/network/interfaces) Ubuntu 18.04 with netplan Ubuntu 20.04 with netplan Debian 10 with ifupdown (/etc/network/interfaces) Debian 9 with ifupdown (/etc/network/interfaces) CentOS 8 with network manager (/etc/sysconfig/network-scripts/ifcfg-eth0) CentOS 7 with network manager (/etc/sysconfig/network-scripts/ifcfg-eth0) Create a new vm from template with password feature enabled and log in the vm with provided password. Stop the vm, change the password with the feature, start the vm and log in the vm with provided password.
1 parent de3ccd2 commit 3ac8194

1 file changed

Lines changed: 49 additions & 13 deletions

File tree

setup/bindir/cloud-set-guest-password.in

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,61 @@
2626
# Modify this line to specify the user (default is root)
2727
user=root
2828

29-
# Add your DHCP lease folders here
30-
DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/* /var/lib/dhcp/*"
29+
# Detect main interface name
30+
NETINT=$(ip -o -4 route show to default | awk '{print $5}')
31+
32+
# Add network provider variables here (default means that interface for network manager is eth0)
33+
NETPLAN=/etc/netplan
34+
IFUPDOWN=/etc/network/interfaces
35+
NETMAN=/etc/sysconfig/network-scripts
36+
37+
# Add dhcp variables
3138
PASSWORD_SERVER_PORT=8080
3239
password_received=0
33-
file_count=0
3440
error_count=0
41+
file_count=0
3542

36-
for DHCP_FILE in $DHCP_FOLDERS; do
37-
if [ -f $DHCP_FILE ]; then
38-
file_count=$((file_count+1))
39-
PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
43+
# OS is using netplan
44+
if [ -d "$NETPLAN" ]; then
45+
logger -t "cloud" "Operating System is using netplan"
4046

41-
if [ -n "$PASSWORD_SERVER_IP" ]; then
42-
logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in $DHCP_FILE"
43-
break
44-
fi
45-
fi
46-
done
47+
PASSWORD_SERVER_IP=$(netplan ip leases $NETINT | grep SERVER_ADDRESS | awk '{split($0,a,"="); print a[2]}')
48+
49+
if [ -n "$PASSWORD_SERVER_IP" ]; then
50+
logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in netplan config"
51+
fi
52+
fi
53+
54+
# OS is using ifupdown
55+
if [ -f "$IFUPDOWN" ]; then
56+
logger -t "cloud" "Operating System is using ifupdown"
57+
58+
DHCP_FOLDERS="/var/lib/dhclient/* /var/lib/dhcp3/* /var/lib/dhcp/*"
59+
60+
for DHCP_FILE in $DHCP_FOLDERS; do
61+
if [ -f $DHCP_FILE ]; then
62+
file_count=$((file_count+1))
63+
PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;')
64+
65+
if [ -n "$PASSWORD_SERVER_IP" ]; then
66+
logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in $DHCP_FILE"
67+
break
68+
fi
69+
fi
70+
done
71+
fi
72+
73+
# OS is using network interfaces
74+
if [ -d "$NETMAN" ]; then
75+
logger -t "cloud" "Operating System is using network manager"
76+
77+
PASSWORD_SERVER_IP=$(nmcli -f IP4.GATEWAY device show $NETINT | sed 's/ //g' | awk '{split($0,a,":"); print a[2]}')
78+
if [ -n "$PASSWORD_SERVER_IP" ]; then
79+
logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in nmcli output"
80+
fi
81+
fi
4782

83+
#start sequence
4884
if [ -z "$PASSWORD_SERVER_IP" ] ; then
4985
logger -t "cloud" "Unable to determine the password server, falling back to data-server"
5086
PASSWORD_SERVER_IP=data-server

0 commit comments

Comments
 (0)