#!/bin/bash # 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" ) # 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 # 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 output_file="output.sql" # Empty the contents of the file (if the file already exists) > "$output_file" # ======================= generate sql # ne_info # generate_ne_info 1 OMC 001 127.0.0.1 33030 1,2 generate_ne_info() { local row_id=$1 local ne_type=$2 local ne_id=$3 local ip=$4 local port=$5 local ne_host=$6 local ne_name="${ne_type}_${ne_id}" local ne_rmuid="4400HX${ne_type}${ne_id}" echo "INSERT INTO ne_info VALUES (${row_id}, '${ne_type}', '${ne_id}', '${ne_rmuid}', '${ne_name}', '${ip}', ${port}, 'PNF', '-', '-', '-', '-', '${ne_host}', 1, '', '', 0, 'script', $(date +%s%3N));" } # ne_host # generate_ne_host 1 OMC 001 127.0.0.1 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 ssh_type="2" local ssh_password="" if [ -n "$DEFAULT_SSH_PORT" ]; 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));" ((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));" ((start_id++)) # 特殊网元类型处理 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));" ;; "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));" ;; esac } # generate_ne_host_ids OMC 1 generate_ne_host_ids() { local ne_type=$1 local start_id=$2 local ids="${start_id},$((start_id+1))" case "$ne_type" in "UDM") ids="${ids},$((start_id+2))" ;; "UPF") ids="${ids},$((start_id+2))" ;; esac echo "$ids" } # ne_version # generate_ne_version 1 OMC 001 generate_ne_version() { local row_id=$1 local ne_type=$2 local ne_id=$3 echo "INSERT INTO ne_version VALUES (${row_id}, '${ne_type}', '${ne_id}', '-', '-', '-', '', '', '', '', '', '', '0', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" } # ne_license # generate_ne_license 1 OMC 001 generate_ne_license() { local row_id=$1 local ne_type=$2 local ne_id=$3 echo "INSERT INTO ne_license VALUES (${row_id}, '${ne_type}', '${ne_id}', '', '', 0, '', '', '1', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));" } # ======================= # Execute output sql to file execute_output() { local row_id=1 local host_id=1 # empty the table echo "DELETE FROM ne_host;" >> "$output_file" echo "DELETE FROM ne_info;" >> "$output_file" echo "DELETE FROM ne_version;" >> "$output_file" 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}" 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" echo "" >> "$output_file" ((row_id++)) case "$ne_type" in "UDM"|"UPF") host_id=$((host_id+3)) ;; *) host_id=$((host_id+2)) ;; esac done } execute_output # Execute import sql to omc execute_import() { local OMCBinFile=/usr/local/bin/omc local OMCEtcDir=/usr/local/etc/omc local confFile=$OMCEtcDir/omc.yaml source $OMCEtcDir/omc.conf $OMCBinFile -c $confFile --sqlPath $output_file --sqlSource $MODE } execute_import # Remove the output file rm -rf $output_file