setup: Update cloud-set-guest-password.in (#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.
This commit is contained in:
dimsijul 2020-06-16 06:44:11 +02:00 committed by GitHub
parent de3ccd2c29
commit 3ac819410a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,25 +26,61 @@
# 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/*"
# Detect main interface name
NETINT=$(ip -o -4 route show to default | awk '{print $5}')
# 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 $NETINT | 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 $NETINT | sed 's/ //g' | awk '{split($0,a,":"); print a[2]}')
if [ -n "$PASSWORD_SERVER_IP" ]; then
logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in nmcli output"
fi
fi
#start sequence
if [ -z "$PASSWORD_SERVER_IP" ] ; then
logger -t "cloud" "Unable to determine the password server, falling back to data-server"
PASSWORD_SERVER_IP=data-server