0

I'm playing with GCP, specially with VM Instances.

I successfully Start / Stop instances by the Python API. But I cannot get the live operation status.

This is what I do to, for example, stop an instance :

instance_client = compute_v1.InstancesClient()
operation = instance_client.stop( project=PROJECT_NAME, zone=ZONE, instance=vm_name )

The VM is stopping, by the web ui I can see that. But when I want to get operation status programmatically I get something like that :

>>> operation
id: *******
kind: "compute#operation"
name: "operation-****-****-***"
user: "*****@appspot.gserviceaccount.com"
zone: "******"
target_link: "******"
progress: 0
operation_type: "stop"
status: RUNNING
target_id: *****
insert_time: "*****"
self_link: "*****"

It's OK during the first execution seconds but it's never updating. So even if the VM is successfully stopped, the method return the same response.

What I am missing ?

Versions :

google-cloud-compute                          0.7.0
google-api-core                               2.8.2
google-api-python-client                      2.55.0

Note 1 : I cannot execute the docs method because my operation object don't have a result method :

>>> dir(operation)
['Status', '__bool__', '__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'client_operation_id', 'creation_timestamp', 'description', 'end_time', 'error', 'http_error_message', 'http_error_status_code', 'id', 'insert_time', 'kind', 'name', 'operation_group_id', 'operation_type', 'progress', 'region', 'self_link', 'start_time', 'status', 'status_message', 'target_id', 'target_link', 'user', 'warnings', 'zone']

Note 2 : I have the same behaviour with the instance.status method :

>>> vm.status
<Status.RUNNING: 250018339>

The result never change even if the VM successfully stopped.

Tomy137
  • 91
  • 9
  • **operation** is a handle. You must use the handle as a parameter to a function to get the current status. I don't remember the name of the function but it is part of the compute_v1 library. – John Hanley Aug 01 '22 at 09:29
  • Thanks ! I find this page : https://cloud.google.com/compute/docs/samples/compute-instances-operation-check. With the correct operation_client and the operation name, we can wait for the end of the operation by the client.wait() function. Maybe it's the only solution but it's weird that we can't just ask for the current progress... Is this function the one you were thinking of ? – Tomy137 Aug 01 '22 at 10:06
  • The **wait** function means wait. There is another to check operation status. In the **googleapiclient**, which is a different library, the function name is **zoneOperations().get()**. – John Hanley Aug 01 '22 at 18:54

0 Answers0