class_docstr: ClusterResolver for Google Compute Engine.
  
  This is an implementation of cluster resolvers for the Google Compute Engine
  instance group platform. By specifying a project, zone, and instance group,
  this will retrieve the IP address of all the instances within the instance
  group and return a ClusterResolver object suitable for use for distributed
  TensorFlow.
  
  Note: this cluster resolver cannot retrieve `task_type`, `task_id` or
  `rpc_layer`. To use it with some distribution strategies like
  `tf.distribute.experimental.MultiWorkerMirroredStrategy`, you will need to
  specify `task_type` and `task_id` in the constructor.
  
  Usage example with tf.distribute.Strategy:
  
    ```Python
    # On worker 0
    cluster_resolver = GCEClusterResolver("my-project", "us-west1",
                                          "my-instance-group",
                                          task_type="worker", task_id=0)
    strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy(
        cluster_resolver=cluster_resolver)
  
    # On worker 1
    cluster_resolver = GCEClusterResolver("my-project", "us-west1",
                                          "my-instance-group",
                                          task_type="worker", task_id=1)
    strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy(
        cluster_resolver=cluster_resolver)
    ```
docstr: Returns a ClusterSpec object based on the latest instance group info.
  
  This returns a ClusterSpec object for use based on information from the
  specified instance group. We will retrieve the information from the GCE APIs
  every time this method is called.
  
  Returns:
    A ClusterSpec containing host information retrieved from GCE.
docstr_tok: ["Returns","a","ClusterSpec","object","based","on","the","latest","instance","group","info",".","This","returns","a","ClusterSpec","object","for","use","based","on","information","from","the","specified","instance","group",".","We","will","retrieve","the","information","from","the","GCE","APIs","every","time","this","method","is","called",".","Returns",":","A","ClusterSpec","containing","host","information","retrieved","from","GCE","."]
code: def cluster_spec(self):
      """Returns a ClusterSpec object based on the latest instance group info.
  
      This returns a ClusterSpec object for use based on information from the
      specified instance group. We will retrieve the information from the GCE APIs
      every time this method is called.
  
      Returns:
        A ClusterSpec containing host information retrieved from GCE.
      """
      request_body = {"instanceState": "RUNNING"}
      request = self._service.instanceGroups().listInstances(
          project=self._project,
          zone=self._zone,
          instanceGroups=self._instance_group,
          body=request_body,
          orderBy="name",
      )
  
      worker_list = []
  
      while request is not None:
          response = request.execute()
  
          items = response["items"]
          for instance in items:
              instance_name = instance["instance"].split("/")[-1]
  
              instance_request = self._service.instances().get(
                  project=self._project,
                  zone=self._zone,
                  instance=instance_name,
              )
  
              if instance_request is not None:
                  instance_details = instance_request.execute()
                  ip_address = instance_details["networkInterfaces"][0][
                      "networkIP"
                  ]
                  instance_url = "%s:%s" % (ip_address, self._port)
                  worker_list.append(instance_url)
  
          request = self._service.instanceGroups().listInstances_next(
              previous_request=request, previous_response=response
          )
  
      worker_list.sort()
      return ClusterSpec({self._task_type: worker_list})
  
file_path: tensorflow/tensorflow/python/distribute/cluster_resolver/gce_cluster_resolver.py
imports: from tensorflow.python.distribute.cluster_resolver.cluster_resolver import ClusterResolver
  from tensorflow.python.training.server_lib import ClusterSpec
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 2 for calling the GCEClusterResolver obj's underlying member method code with example usage: obj.cluster_spec() and returns: ClusterSpec