日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

業(yè)務(wù)爸爸:小毛驢幫我實(shí)現(xiàn)一個(gè)功能,我在做業(yè)務(wù)版本更新的時(shí)候需要把該主機(jī)在clb上權(quán)限改為0,要求用shell腳本實(shí)現(xiàn)。

小毛驢:安排!

#!/bin/sh
#
#調(diào)用騰訊云的clb api,修改指定 clb, 指定 localtion id下指定 targets 主機(jī)的權(quán)限。
# author 小毛驢
#

clb_modify_target_api_url=${ApiUrl}

function installJq() {
    if [ -f /etc/redhat-release ];then
        _OSFLAG=`cat /etc/redhat-release | awk '{print tolower($1)}'`
        if [[ ${_OSFLAG}x == 'centos'x  ]]  || [[  ${_OSFLAG}x == 'tencent'x ]] ; then
             yum  -y  -q  install jq
        fi
    elif [ -f /etc/lsb-release ];then
        _OSFLAG=`cat /etc/lsb-release | grep "DISTRIB_ID" | awk -F"=" '{print tolower($2)}'` 
        if [ ${_OSFLAG}x == "ubuntu"x ];then
            sudo apt-get -y   -q install jq
        fi
    else
        echo  "This is no CentOS and Ubuntu , 腳本目前不支持此系統(tǒng) !"
        exit 1
    fi
}

which jq > /dev/null
if [ $? -gt 0 ]; then
    installJq
fi

function modify_clb_targets() {
    local region=$1
    local load_balancer_id=$2
    local listener_id=$3
    local location_id=$4
    local eni_ip=$5
    local port=$6
    local weight=$7
    generate_get_clb_post_data() {
cat <<EOF
{
    "region": "${region}",
    "load_balancer_id": "${load_balancer_id}",
    "listener_id": "${listener_id}",
    "location_id": "${location_id}",
    "targets": [{
        "eni_ip": "${eni_ip}",
        "port": ${port},
        "weight": ${weight}
    }]
}
EOF
}

    respond=$(curl -s -X POST 
        ${clb_modify_target_api_url} 
        -H 'cache-control: no-cache' 
        -H 'content-type: Application/json' 
        -d "$(generate_get_clb_post_data)")
    echo ${respond}
    http_code=$(echo ${respond} | jq '.code')
    if [[ ${http_code} != 200 ]]; then
        echo "$(echo ${respond} | jq '.message')"
        exit  2
    fi
    echo ${respond} | jq '.message'
}

#如果 Port 是 -1 表示該LocationId下EniIp這地址只有一個(gè)端口
if [ ${Port} == -1 ];then
    modify_clb_targets ${Region} ${LoadBalancerId} ${ListenerId} ${LocationId} ${EniIp} -1 ${Weight}
else
    modify_clb_targets ${Region} ${LoadBalancerId} ${ListenerId} ${LocationId} ${EniIp} ${Port} ${Weight}
fi

知識(shí)點(diǎn)

  1. clb_modify_target_api_url 這個(gè)接口是基于騰訊云封裝后的接口(golang實(shí)現(xiàn),后面會(huì)把該代碼分享), 接收json數(shù)據(jù)能修改對(duì)應(yīng)clb下localtionId的主機(jī)權(quán)限。
  2. 用jq處理返回的json數(shù)據(jù)。

分享到:
標(biāo)簽:shell
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定