1
0

feat: 初始网元脚本支持多组

This commit is contained in:
TsMask
2025-06-07 14:18:50 +08:00
parent b7a3aca364
commit 4c2bab63f2

View File

@@ -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