使用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
参数,该参数应与您可以按实例名称查询的实例的指纹相匹配。