Existing documentation
https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert
states that the return type of the call would be a dictionary of multiple status values. In addition, even their python examples shows that the return type is of type dict.
What actually happens
What I've experienced is that the call actually gives me None:
config = {
'name': "test-machine",
'machineType': "zones/us-central1-c/machineTypes/foobar",
'disks': [
{
'boot': True,
'autoDelete': True,
'deviceName': "test-machine",
...
}
}
operation = compute.instances().insert(project=PROJECT_NAME, zone=ZONE, body=config).execute()
wait_for_operation(compute, PROJECT_NAME, ZONE, operation["name"])
The wait_for_operation() function is taken straight off of the python examples:
def wait_for_operation(compute, project, zone, operation):
print('Waiting for operation to finish...')
while True:
result = compute.zoneOperations().get(
project=project,
zone=zone,
operation=operation).execute()
if result['status'] == 'DONE':
print("done.")
if 'error' in result:
raise Exception(result['error'])
return result
time.sleep(1)
and yet, I get this error:
Traceback (most recent call last):
File "gcloud_playground.py", line 113, in <module>
wait_for_operation(compute, PROJECT_NAME, ZONE, operation["name"])
TypeError: 'NoneType' object has no attribute '__getitem__'
What actually happens is that my instance is successfully created, but I would have no idea whether it is successfully created or not.