製品情報
パブリックイメージの更新情報
OSの公式サポート終了計画
製品に関するお知らせ
QcloudCVMFullAccessと QcloudAPIFullAccess のプリセットポリシーを付与します。python --version
yum install python3
sudo apt install python3
python --version
test.py ファイルを作成し、次のコードを入力します。import jsonfrom tencentcloud.common import credentialfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfilefrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKExceptionfrom tencentcloud.cvm.v20170312 import cvm_client, models# デフォルトでは、環境変数 TENCENTCLOUD_SECRET_ID および TENCENTCLOUD_SECRET_KEY を読み取り、secretId および SecretKey を取得します。# 認証情報の管理方法の詳細については、https://github.com/TencentCloud/tencentcloud-sdk-python#%E5%87%AD%E8%AF%81%E7%AE%A1%E7%90%86をご覧くださいcred = credential.EnvironmentVariableCredential().get_credential()httpProfile = HttpProfile()httpProfile.endpoint = "cvm.tencentcloudapi.com"clientProfile = ClientProfile()clientProfile.httpProfile = httpProfile# この例では南京が使用されています。 実際の状況に応じてリージョンを変更します。 たとえば、上海の場合、リージョンを「ap-shanghai」に変更します。aria = 'ap-nanjing'client = cvm_client.CvmClient(cred,aria, clientProfile)def img_share(img_id,img_name,accountids):try:req1 = models.ModifyImageSharePermissionRequest()params1 = {"ImageId": img_id,"AccountIds": accountids,"Permission": "SHARE"}req1.from_json_string(json.dumps(params1))resp1 = client.ModifyImageSharePermission(req1)response1 = json.loads(resp1.to_json_string())print(img_name,'共有成功!',response1)except TencentCloudSDKException as err:print(img_name,'共有失敗!',err)try:req = models.DescribeImagesRequest()params = {"Filters": [{"Name": "image-type","Values": ["PRIVATE_IMAGE"]}],"Limit": 100}req.from_json_string(json.dumps(params))resp = client.DescribeImages(req)response = json.loads(resp.to_json_string())img_num = response["TotalCount"]print('イメージリストを取得中....')share_config = input('1.すべてのイメージを共有します\\n\\n2.. 共有するイメージを決定します\\n\\n1 または 2 を入力して Enter キーを押します。 デフォルト値: 2:') or '2'accountids = input('イメージを共有するユーザーの UIN を入力し、複数のUINをカンマで区切ってください:').split(",")for i in range(img_num):basic = response['ImageSet'][i]img_id = basic['ImageId']img_name = basic['ImageName']if share_config == '1':img_share(img_id,img_name,accountids)elif share_config == '2':print('イメージID:',img_id,'イメージ名:',img_name)share_choice = input('このイメージを共有するかどうか y/n:') or 'y'if share_choice == 'y':img_share(img_id,img_name,accountids)elif share_choice == 'n':continueelse:print('正しいオプションを入力してください!!')else:print('正しいオプションを入力してください!!')except TencentCloudSDKException as err:print(err)
フィードバック