Google api 字段'的值无效;磁盘';尝试设置磁盘自动删除选项时

Google api 字段'的值无效;磁盘';尝试设置磁盘自动删除选项时,google-api,google-compute-engine,google-api-python-client,Google Api,Google Compute Engine,Google Api Python Client,在Google Compute Engine上,我有一个名为my inst的运行实例,它的根持久磁盘pd my inst已连接。我想使用pythonapi客户机将磁盘的AutoDelete选项设置为False。我知道我可以在实例创建时或通过使用gcloud compute工具设置此选项,但我的应用程序需要在使用Python API创建实例后设置此选项。我用来发送请求的代码是: request = gce_service.instances().setDiskAutoDelete(autoDele

在Google Compute Engine上,我有一个名为my inst的运行实例,它的根持久磁盘pd my inst已连接。我想使用pythonapi客户机将磁盘的AutoDelete选项设置为False。我知道我可以在实例创建时或通过使用
gcloud compute
工具设置此选项,但我的应用程序需要在使用Python API创建实例后设置此选项。我用来发送请求的代码是:

request = gce_service.instances().setDiskAutoDelete(autoDelete=False,
    deviceName='pd-my-inst', project=PROJECT_ID, instance='my-inst', zone=DEFAULT_ZONE)
response = gce_service.execute(http=http_auth)
我收到的回复与邮件中的内容一样详细,因此发送正确。然后我使用
zoneOperations().get()
方法,直到响应的
['status']
字段为
'DONE'
,类似于中提供的
\u blocking\u call()
函数。我得到的区域操作对象是(为了隐私,某些部分被避开):

我还尝试使用基于Web的API资源管理器为
setDiskAutoDelete()
方法发送请求,但得到了完全相同的错误

我不明白为什么会出现无效的\u字段\u值错误,因为我按照API引用的要求提供了磁盘设备名称。这个领域有什么我遗漏的吗?设备名称是否与实例创建时为其指定的名称不同


谢谢你的帮助!:)

DeviceName字段应包含VM实例所看到的磁盘名称(本例中为persistent-disk-0),这与创建持久磁盘(pd my inst)时为其指定的名称不同。DeviceName位于通过
instances().get()
instances().list()方法获得的json实例对象中:

{
u'status': u'RUNNING',
u'kind': u'compute#instance',
u'machineType': ...
u'name': u'my-inst',
u'zone': u'https://www.googleapis.com/compute/v1/projects/MY-PROJECT-NAME/zones/us-central1-a',
u'tags': {u'fingerprint': u'42WmSpB8rSM='},
u'disks':
    [{
    u'deviceName': u'persistent-disk-0',
    u'kind': u'compute#attachedDisk',
    u'autoDelete': True,
    u'index': 0,
    u'boot': True,
    u'source': u'https://www.googleapis.com/compute/v1/projects/MY-PROJECT-NAME/zones/us-central1-a/disks/pd-my-inst',
    u'type': u'PERSISTENT'
    }],
u'scheduling': {u'automaticRestart': True, u'onHostMaintenance': u'MIGRATE'},
u'canIpForward': False,
...
}
可以使用以下方法检索它:
实例['disks'][DISK\u INDEX]['deviceName']

{
u'status': u'RUNNING',
u'kind': u'compute#instance',
u'machineType': ...
u'name': u'my-inst',
u'zone': u'https://www.googleapis.com/compute/v1/projects/MY-PROJECT-NAME/zones/us-central1-a',
u'tags': {u'fingerprint': u'42WmSpB8rSM='},
u'disks':
    [{
    u'deviceName': u'persistent-disk-0',
    u'kind': u'compute#attachedDisk',
    u'autoDelete': True,
    u'index': 0,
    u'boot': True,
    u'source': u'https://www.googleapis.com/compute/v1/projects/MY-PROJECT-NAME/zones/us-central1-a/disks/pd-my-inst',
    u'type': u'PERSISTENT'
    }],
u'scheduling': {u'automaticRestart': True, u'onHostMaintenance': u'MIGRATE'},
u'canIpForward': False,
...
}