如何使用Python更新方法更改Google Cloud实例类型



使用insert方法文档中的Python示例

from pprint import pprint
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)

project = 'my-project' 
zone = 'us-west1-a' 
instance_body = {
# TODO: Add desired entries to the request body.
}
request = service.instances().update(project=project, zone=zone, body=instance_body)
response = request.execute()
# TODO: Change code below to process the `response` dict:
pprint(response)

我将instance_body变量自定义为

instance_body = {
'name': 'my-vm-0001',
'machineType':  'https://www.googleapis.com/compute/v1/projects/%s/zones/%s/machineTypes/e2-highcpu-32' % (project, zone)
}

但是运行update()方法

request = service.instances().update(project=project, zone=zone, body=instance_body)
response = request.execute()

提出CCD_ 4。

有没有办法使用update方法更新实例类型?似乎可以使用gcloud命令更改不稳定性类型:

gcloud compute instances set-machine-type my-vm-0001 --project my-project --zone=us-west1-a--machine-type=e2-highcpu-32

update方法采用与insert方法在instance_body变量中定义的参数相同的参数,并添加一个fingerprint参数,该参数应与您可以按实例名称查询的实例的指纹相匹配。

相关内容

  • 没有找到相关文章

最新更新