Skip to content

Commit ca5bbee

Browse files
static ip support for edge node (#223)
1 parent aa1c92a commit ca5bbee

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

standalone-node/installation_scripts/config-file

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ user_name=""
4444
# Default value is kubernetes.
4545
host_type="kubernetes"
4646

47+
#------------------- Static IP Configuration ------------------------------------------------------
48+
# This section assigns a Static IP address to the Edge Node if no DHCP server is available.
49+
#
50+
# Ensure that the IP address, subnet mask, gateway, and DNS name server values
51+
# are correctly configured according to your organization’s network settings.
52+
#
53+
## NOTE:
54+
# This configuration is optional.
55+
# If a valid IP is obtained from a DHCP server, the static IP configuration
56+
# will be skipped, even if the static details are provided below
57+
# Example:
58+
# static_ip="192.168.1.24"
59+
# subnet_mak="24" i.e 192.168.1.24/24
60+
# dns_name_server="8.8.8.8,4.4.4.4" ## According to your organization's netwrok
61+
62+
static_ip=""
63+
subnet_mask=""
64+
defualt_gate_way=""
65+
dns_name_server=""
4766

4867
# ------------------ LVM partition size ------------------------
4968
# Set the LVM partition size in GB. This will be used for creating

standalone-node/provisioning_scripts/install-os.sh

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
750808
system_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
774834
system_finalizer() {
775-
835+
776836
dump_logs_to_usb || return 1
777837
}
778838

0 commit comments

Comments
 (0)