diff options
| author | 牛翔 <[email protected]> | 2019-12-16 15:25:37 +0800 |
|---|---|---|
| committer | 牛翔 <[email protected]> | 2019-12-16 15:25:37 +0800 |
| commit | c4ad95d9baeac05715f70c3fb34e6f4b7310a665 (patch) | |
| tree | 33cbac2f4096a1f6339356807e5d6d5e6444122b | |
| parent | 0815d9a4710c5d5f70e68f8c2a6a0288d65ed6fd (diff) | |
Upload New File
| -rw-r--r-- | init_mcn_network/init_adc_cpu_broad.sh | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/init_mcn_network/init_adc_cpu_broad.sh b/init_mcn_network/init_adc_cpu_broad.sh new file mode 100644 index 0000000..9de450b --- /dev/null +++ b/init_mcn_network/init_adc_cpu_broad.sh @@ -0,0 +1,120 @@ +#!/bin/bash +###################################### +# author: niuxiang +# date: 2019-11-27 +###################################### +# This script is used to configure \ +# the network according to the slot \ +# number of the board card +###################################### + +#左上(cpu02)槽位为:0x80,右上(cpu04)槽位为:0x88, +#左下(cpu01)槽位为:0x90,右下(cpu03)槽位为:0x98; +#check_command='ipmitool raw 0x2e 0x32 0x13 0x5f 0x00' + +work_dir=$(cd $(dirname $0); pwd) +net_conf_dir='/etc/sysconfig/network-scripts/' +service_dir='/opt/tsg/env/' + +# 函数作用: +# 日志记录函数 +write_log(){ + echo "[$(date +'%F %H:%M:%S')]" $@ | tee -a ${work_dir}/logfile.txt +} + +# 函数作用: +# 删除/opt/tsg/env下的配置文件,将tsg-env目录下的相应板卡配置文件拷贝到 +# tsg-env服务相应的目录,并将服务添加开机启动 +copy_tsg_env(){ + if [ ! -d ${service_dir} ];then + mkdir -p ${service_dir} + else + rm -f ${service_dir}/* + fi + rm -f /usr/lib/systemd/system/tsg-env.service + setup_file=${work_dir}/tsg-env/tsg-env-$1_setup + vf_setup_file=${work_dir}/tsg-env/tsg-env-$1_vf-setup + service_file=${work_dir}/tsg-env/tsg-env-$1_tsg-env.service + switch_file=${work_dir}/tsg-env/switch_control_client_non_block + cp -a ${setup_file} ${service_dir}/setup + cp -a ${vf_setup_file} ${service_dir}/vf-setup + cp -a ${switch_file} ${service_dir}/ + cp -a ${service_file} /usr/lib/systemd/system/tsg-env.service + systemctl daemon-reload + systemctl enable tsg-env.service + systemctl restart tsg-env.service + write_log $(echo 'Service conf updated') + write_log $(echo 'Service tsg-env enabled') +} + +# 函数作用: +# 判断ens1/ens8网卡配置文件是否存在,不存在创建配置文件 +# 函数的参数1为根据ethtool命令判断的网卡名称 +check_net_conf(){ + conf_num=$(ls ${net_conf_dir}/ifcfg-ens* | wc -l) + if [ ${conf_num} -gt 1 ];then + name_index=$(date +%H-%M-%S) + mv ${net_conf_dir}/ifcfg-ens*{,.${name_index}} + elif [ ${conf_num} -eq 0 ];then + cp ${work_dir}/ifcfg-ens ${net_conf_dir}/ifcfg-$1 + fi + conf_name=$(ls ${net_conf_dir}/ifcfg-ens* | awk -F'-' '{print $NF}') + if [ $1 == ${conf_name} ];then + write_log $(echo 'NIC name is correct') + else + sed -i "s#^NAME=.*#NAME=$1#g" ${net_conf_dir}/ifcfg-${conf_name} + sed -i "s#^DEVICE=.*#DEVICE=$1#g" ${net_conf_dir}/ifcfg-${conf_name} + mv ${net_conf_dir}/ifcfg-ens* ${net_conf_dir}/ifcfg-$1 + write_log $(echo 'NIC name changed') + fi + +} + +# 函数作用: +# 判断设备网卡是ens1或ens8 +check_ens_num(){ + ethtool ens1 > /dev/null 2>&1 + status=$? + if [ ${status} -eq 0 ];then + net_dev='ens1' + else + net_dev='ens8' + fi + write_log $(echo "pf name is ${net_dev}") +} + +# 函数作用: +# 网卡固化 +# 函数参数1为根据ipmitool判断板卡名称 +config_service(){ + write_log $(echo "this is $1") + copy_tsg_env $1 + check_ens_num + check_net_conf ${net_dev} +} + +if [ $1x != 'run'x ];then + write_log $(echo "./init_adc_cpu_broad.sh run") + exit +fi + +card_info=$(ipmitool raw 0x2e 0x32 0x13 0x5f 0x00 | awk '{print $NF}') +rm -f ${work_dir}/logfile.txt + +case ${card_info} in + 90) + config_service mcn0 + ;; + 80) + config_service mcn1 + ;; + 98) + config_service mcn2 + ;; + 88) + config_service mcn3 + ;; + *) + write_log $(echo 'check error') + ;; +esac |
