@@ -746,6 +746,64 @@ copy_os_update_script() {
746746 umount /mnt
747747}
748748
749+ # Static IP configuration for no dhcp support edge nodes.
750+ set_static_ip () {
751+
752+ CONFIG_FILE=" /etc/scripts/config-file"
753+
754+ # get the static ip details from config file
755+ ip=$( grep ' ^static_ip=' " $CONFIG_FILE " | cut -d ' =' -f2)
756+ net_mask=$( grep ' ^subnet_mask=' " $CONFIG_FILE " | cut -d ' =' -f2)
757+ gate_way=$( grep ' ^defualt_gate_way=' " $CONFIG_FILE " | cut -d ' =' -f2)
758+ dns_server=$( grep ' ^dns_name_server=' " $CONFIG_FILE " | cut -d ' =' -f2)
759+
760+ # Select the interfce to assign the static ip,ignore loop back interface.
761+ IFACE=$( ip -o link show | awk -F' : ' ' !/lo/ {print $2; exit}' )
762+
763+ # Write the configuration to /etc/netplan/51-cloud-init.yaml
764+
765+ check_mnt_mount_exist
766+ mount " $os_disk$os_rootfs_part " /mnt
767+
768+ STATIC_IP_FILE=" /mnt/etc/netplan/51-cloud-init.yaml"
769+ # Create YAML content
770+ cat > " $STATIC_IP_FILE " << EOF
771+ network:
772+ version: 2
773+ ethernets:
774+ $IFACE :
775+ dhcp4: false
776+ addresses: [$ip /$net_mask ]
777+ gateway4: $gate_way
778+ nameservers:
779+ addresses: [ ${dns_server} ]
780+ EOF
781+ chmod 600 $STATIC_IP_FILE
782+ umount /mnt
783+ }
784+
785+ static_ip_configuration () {
786+
787+ echo -e " ${BLUE} Static IP Configuration!!${NC} "
788+
789+ # Check if a valiad IP address already assigned to Edge node
790+ # If yes , ignore static ip configuration
791+ pub_inerface_name=$( route | grep ' ^default' | grep -o ' [^ ]*$' )
792+
793+ # If pub_inerface_name name empty means no ip assigned from dhcp server.
794+ if [ -z " $pub_inerface_name " ]; then
795+ set_static_ip
796+ else
797+ # Check if pub interface configured with loop back ip or vm ip
798+ ip_addr=$( ip -4 addr show " $pub_inerface_name " | awk ' /inet / {print $2}' | cut -d/ -f1 | grep -Ev ' ^(127\.|10\.0\.)' | head -1)
799+ # If the ip_addr empty means no valid IP assigned to interface from dhcp server. ignore for vm setup
800+ if [ -z " $ip_addr " ] && [ " $deploy_mode " != " ven" ]; then
801+ set_static_ip
802+ fi
803+ fi
804+ return 0
805+ }
806+
749807# Check provision pre-conditions
750808system_readiness_check () {
751809
@@ -767,12 +825,14 @@ platform_config_manager() {
767825
768826 update_mac_under_dhcp_systemd || return 1
769827
828+ static_ip_configuration || return 1
829+
770830 boot_order_chage_to_disk || return 1
771831}
772832
773833# Post installation tasks
774834system_finalizer () {
775-
835+
776836 dump_logs_to_usb || return 1
777837}
778838
0 commit comments