From 4c2bab63f20ac49153a0cdf53dbcaa4c758a364f Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Sat, 7 Jun 2025 14:18:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E5=A7=8B=E7=BD=91=E5=85=83?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=94=AF=E6=8C=81=E5=A4=9A=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- linux/usr/local/etc/omc/script/init_ne.sh | 122 ++++++++++++++-------- 1 file changed, 78 insertions(+), 44 deletions(-) diff --git a/linux/usr/local/etc/omc/script/init_ne.sh b/linux/usr/local/etc/omc/script/init_ne.sh index c631b23..0262724 100644 --- a/linux/usr/local/etc/omc/script/init_ne.sh +++ b/linux/usr/local/etc/omc/script/init_ne.sh @@ -1,32 +1,49 @@ #!/bin/bash +declare -A NE_LIST +# Default network element number ne_id = 001 # Defining a list of network elements -# ne_type,ne_ip,ne_port -NE_LIST=( - "OMC,172.16.5.100,33030" - "IMS,172.16.5.110,33030" - "AMF,172.16.5.120,33030" - "AUSF,172.16.5.130,33030" - "UDM,172.16.5.140,33030" - "SMF,172.16.5.150,33030" - "PCF,172.16.5.160,33030" - "UPF,172.16.5.190,33030" -) +# Format: "ne_type, ne_ip, ne_port" +# ----------------------------------------- +# ne_id 001 Network Elements +# ----------------------------------------- +NE_LIST["001"]="\ +OMC,172.16.5.100,33030 +IMS,172.16.5.110,33030 +AMF,172.16.5.120,33030 +AUSF,172.16.5.130,33030 +UDM,172.16.5.140,33030 +SMF,172.16.5.150,33030 +PCF,172.16.5.160,33030 +UPF,172.16.5.190,33030 +" + +# ----------------------------------------- +# ne_id 002 Network Elements +# ----------------------------------------- +# NE_LIST["002"]="\ +# IMS,172.16.15.110,33030 +# AMF,172.16.15.120,33030 +# AUSF,172.16.15.130,33030 +# UDM,172.16.15.140,33030 +# SMF,172.16.15.150,33030 +# PCF,172.16.15.160,33030 +# UPF,172.16.15.190,33030 +# " # Default SSH info DEFAULT_SSH_USER="manager" -# If you already have a password-free authorization, please set the password to "" -# DEFAULT_SSH_PWD="" -# password=admin123 -DEFAULT_SSH_PWD="bSQ21KY7cjn58JNkZ0UZM64EbSIPMQwfCTmzk3MTBvQ=" DEFAULT_SSH_PORT=22 +# If you already have a password-free authorization, please set the password to "" +#DEFAULT_SSH_PWD="" +DEFAULT_SSH_PWD="bSQ21KY7cjn58JNkZ0UZM64EbSIPMQwfCTmzk3MTBvQ=" # admin123 +# 5gc+omc use local 127.0.0.1 +DEFAULT_SSH_LOCAL=false # Default ne_host info DEFAULT_TELNET_PORT=4100 DEFAULT_TELNET_PORT2=5002 DEFAULT_REDIS_PORT=6379 -# Default network element number ne_id -DEFAULT_NE_ID="001" # Path to the output file @@ -57,31 +74,36 @@ generate_ne_host() { local row_id=$1 local ne_type=$2 local ne_id=$3 - local ip=$4 local ne_name="${ne_type}_${ne_id}" local start_id=$row_id + + local ip=$4 + if [ "$DEFAULT_SSH_LOCAL" == true ]; then + ip="127.0.0.1" + fi + local ssh_type="2" local ssh_password="" - if [ -n "$DEFAULT_SSH_PORT" ]; then + if [ -n "$DEFAULT_SSH_PWD" ]; then ssh_type="0" ssh_password="$DEFAULT_SSH_PWD" fi - # SSH连接 - echo "INSERT INTO ne_host VALUES (${start_id}, 'ssh', '1', '${ne_name}_${DEFAULT_SSH_PORT}', '${ip}', ${DEFAULT_SSH_PORT}, '${DEFAULT_SSH_USER}', '${ssh_type}', '${ssh_password}', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" + # SSH + echo "INSERT INTO ne_host VALUES (${start_id}, 'ssh', '1', '${ne_name}_${DEFAULT_SSH_PORT}_${start_id}', '${ip}', ${DEFAULT_SSH_PORT}, '${DEFAULT_SSH_USER}', '${ssh_type}', '${ssh_password}', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" ((start_id++)) - # Telnet连接 - echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT}', '${ip}', ${DEFAULT_TELNET_PORT}, 'admin', '0', 'okzArqkFYlnVVdQYkNiqmiW+CGQrxg1AFmroR1bw1Kg=', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" + # Telnet + echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT}_${start_id}', '${ip}', ${DEFAULT_TELNET_PORT}, 'admin', '0', 'okzArqkFYlnVVdQYkNiqmiW+CGQrxg1AFmroR1bw1Kg=', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" ((start_id++)) - # 特殊网元类型处理 + # Special network element type handling case "$ne_type" in "UDM") - echo "INSERT INTO ne_host VALUES (${start_id}, 'redis', '1', '${ne_name}_${DEFAULT_REDIS_PORT}', '${ip}', ${DEFAULT_REDIS_PORT}, 'udmdb', '0', 'jW965gWZK0mw6EtYfihMV9QqHjqa03vJ8VlVii9non8=', '', '', '0', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" + echo "INSERT INTO ne_host VALUES (${start_id}, 'redis', '1', '${ne_name}_${DEFAULT_REDIS_PORT}_${start_id}', '${ip}', ${DEFAULT_REDIS_PORT}, 'udmdb', '0', 'jW965gWZK0mw6EtYfihMV9QqHjqa03vJ8VlVii9non8=', '', '', '0', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" ;; "UPF") - echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT2}', '${ip}', ${DEFAULT_TELNET_PORT2}, 'admin', '0', '', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" + echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT2}_${start_id}', '${ip}', ${DEFAULT_TELNET_PORT2}, 'admin', '0', '', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" ;; esac } @@ -138,27 +160,39 @@ execute_output() { echo "DELETE FROM ne_license;" >> "$output_file" echo "" >> "$output_file" - for v in "${NE_LIST[@]}"; do - IFS=',' read -r ne_type ne_ip ne_port <<< "$v" - echo "===> ${ne_type} ${ne_ip} ${ne_port}" + # ----------------------------------------- + # Example of accessing and parsing the elements + # ----------------------------------------- + for ne_id in "${!NE_LIST[@]}"; do + echo "NEID: $ne_id:" - generate_ne_host "$host_id" "$ne_type" "$DEFAULT_NE_ID" "$ne_ip" >> "$output_file" - local host_ids=$(generate_ne_host_ids $ne_type $host_id) - generate_ne_info "$row_id" "$ne_type" "$DEFAULT_NE_ID" "$ne_ip" "$ne_port" "$host_ids" >> "$output_file" - generate_ne_version "$row_id" "$ne_type" "$DEFAULT_NE_ID" >> "$output_file" - generate_ne_license "$row_id" "$ne_type" "$DEFAULT_NE_ID" >> "$output_file" + # Splitting the values by newline to get each device entry + IFS=$'\n' read -r -d '' -a devices <<< "${NE_LIST[$ne_id]}" - echo "" >> "$output_file" + # Iterating over each device entry + for device in "${devices[@]}"; do + # Split device entry into name, IP, and port + IFS=',' read -r ne_type ne_ip ne_port <<< "$device" + echo "===> ${ne_type} ${ne_ip} ${ne_port}" - ((row_id++)) - case "$ne_type" in - "UDM"|"UPF") - host_id=$((host_id+3)) - ;; - *) - host_id=$((host_id+2)) - ;; - esac + generate_ne_host "$host_id" "$ne_type" "$ne_id" "$ne_ip" >> "$output_file" + local host_ids=$(generate_ne_host_ids $ne_type $host_id) + generate_ne_info "$row_id" "$ne_type" "$ne_id" "$ne_ip" "$ne_port" "$host_ids" >> "$output_file" + generate_ne_version "$row_id" "$ne_type" "$ne_id" >> "$output_file" + generate_ne_license "$row_id" "$ne_type" "$ne_id" >> "$output_file" + + echo "" >> "$output_file" + + ((row_id++)) + case "$ne_type" in + "UDM"|"UPF") + host_id=$((host_id+3)) + ;; + *) + host_id=$((host_id+2)) + ;; + esac + done done } execute_output