美文网首页
腾讯云 批量切换 “主机安全专业版/基础版”

腾讯云 批量切换 “主机安全专业版/基础版”

作者: 偷油考拉 | 来源:发表于2022-04-22 11:48 被阅读0次

1、启用专业版脚本 enable_pro.py

import json,argparse
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.cwp.v20180228 import cwp_client, models

parser = argparse.ArgumentParser(description='Test Argparse.')
parser.add_argument('-u', type=str,
                    help='CVM uuid , example: 2415d1da-b34e-435e-8b6c-1015e0244497 ')
parser.add_argument('-f', type=argparse.FileType('r'),
                    help='file includes uuids')
args = parser.parse_args()

uuids = []

if args.u:
    uuid = args.u
    uuids.append(uuid)
elif args.f:
    with args.f as f:
        for uuid in f.readlines():
            uuid = uuid.strip('\n')
            uuids.append(uuid)

print(uuids)

SecretId="你的id"
SecretKey="你的key"

try:
    cred = credential.Credential(SecretId, SecretKey)
    httpProfile = HttpProfile()
    httpProfile.endpoint = "cwp.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = cwp_client.CwpClient(cred, "", clientProfile)

    req = models.OpenProVersionRequest()
    params = {
        "MachineType": "cvm",
        "MachineRegion": "0",
        "Quuids": uuids
    }
    req.from_json_string(json.dumps(params))

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

except TencentCloudSDKException as err:
    print(err)

使用方法

  1. -u 参数,指定uuid
python3 enable_pro.py -u 613c8a68-12c3-4f10-b831-509109f291a3
  1. -f 参数,指定一个包含了很多uuid的文件
python3 enable_pro.py -f cvmfile

cvmfile 是uuid的集合,如下范例:
[root@VM-99-12-centos 004-主机安全]# cat cvmfile
2415d1da-b34e-435e-8b6c-1015e0244497
2415d1da-b34e-435e-8b6c-1015e0244498
2415d1da-b34e-435e-8b6c-1015e0244499

2、关闭专业版脚本 disable_pro.py

import json,argparse
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.cwp.v20180228 import cwp_client, models

parser = argparse.ArgumentParser(description='Test Argparse.')
parser.add_argument('-u', type=str,
                    help='CVM uuid , example: 2415d1da-b34e-435e-8b6c-1015e0244497 ')
parser.add_argument('-f', type=argparse.FileType('r'),
                    help='file includes uuids')
args = parser.parse_args()

SecretId="你的id"
SecretKey="你的key"

def disable_pro(uuid):
    print("disable uuid : ",uuid)
    try:
        cred = credential.Credential(SecretId, SecretKey)
        httpProfile = HttpProfile()
        httpProfile.endpoint = "cwp.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = cwp_client.CwpClient(cred, "", clientProfile)

        req = models.CloseProVersionRequest()
        params = {
            "Quuid": uuid
        }
        req.from_json_string(json.dumps(params))

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

    except TencentCloudSDKException as err:
        print(err)

if args.u:
    uuid = args.u
    disable_pro(uuid)
elif args.f:
    with args.f as f:
        for uuid in f.readlines():
            uuid = uuid.strip('\n')
            disable_pro(uuid)

使用方法

  1. -u 参数,指定uuid
python3 disable_pro.py -u 613c8a68-12c3-4f10-b831-509109f291a3
  1. -f 参数,指定一个包含了很多uuid的文件
python3 disable_pro.py -f cvmfile

cvmfile 是uuid的集合,如下范例:
[root@VM-99-12-centos 004-主机安全]# cat cvmfile
2415d1da-b34e-435e-8b6c-1015e0244497
2415d1da-b34e-435e-8b6c-1015e0244498
2415d1da-b34e-435e-8b6c-1015e0244499

相关文章

网友评论

      本文标题:腾讯云 批量切换 “主机安全专业版/基础版”

      本文链接:https://www.haomeiwen.com/subject/qmoraltx.html