4

腾讯云CLB实例克隆

 2 years ago
source link: https://blog.51cto.com/vaedit/5364447
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

腾讯云CLB实例克隆

原创

Vaedit 2022-06-07 20:07:03 ©著作权

文章标签 json python bash CLB 文章分类 云平台 云计算 阅读数158

在工作中业务上线时,会存在多个VIP需要上规则,存在同时几千甚至上万的规则,那么上规则和维护规则变得极为麻烦,并且项目上线时为了预防万一,会多备几组VIP容余备用。比如一个项目上线,至少得电信,联通,移动,香港,CAP等5个VIP,同时考虑到流量评估和异常情况,需要多备几组VIP,那么有没有什么方式只需上一组vip,然后直接克隆实例呢?

  1. 需要创建账户SecretKey和SecretID
  2. 账户需要分配有CLB相应的权限
  3. 腾讯云提工单账号加白才可以使用CLB克隆接口

脚本如下:

#pip3 install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
# coding: utf-8
# author: Vaeditshen

import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.clb.v20180317 import clb_client, models
import argparse
parser = argparse.ArgumentParser(description="clone clb tools")
parser.add_argument('-i', '--secredid', default='xxx', help='子账户ID')
parser.add_argument('-k', '--secredkey', default='xx', help='子账户KEY')
parser.add_argument('-r', '--region', default='ap-nanjing', help='地域')
parser.add_argument('-l', '--lbid', default='xx', help='CLB ID')
args = parser.parse_args()

try:
    cred = credential.Credential(args.secredid, args.secredkey)
    httpProfile = HttpProfile()
    httpProfile.endpoint = "clb.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = clb_client.ClbClient(cred, args.region, clientProfile)

    req = models.CloneLoadBalancerRequest()
    params = {
        "LoadBalancerId": args.lbid
    }
    req.from_json_string(json.dumps(params))

    resp = client.CloneLoadBalancer(req)
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)

使用方式:

Desktop python3 clone_clb2.py -h
usage: clone_clb2.py [-h] [-i SECREDID] [-k SECREDKEY] [-r REGION] [-l LBID]

clone clb tools

optional arguments:
  -h, --help            show this help message and exit
  -i SECREDID, --secredid SECREDID
                        子账户ID
  -k SECREDKEY, --secredkey SECREDKEY
                        子账户KEY
  -r REGION, --region REGION
                        地域
  -l LBID, --lbid LBID  CLB ID
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK