class_docstr: Cluster Resolver for Google Cloud TPUs.
  
  This is an implementation of cluster resolvers for the Google Cloud TPU
  service.
  
  TPUClusterResolver supports the following distinct environments:
  Google Compute Engine
  Google Kubernetes Engine
  Google internal
  
  It can be passed into `tf.distribute.TPUStrategy` to support TF2 training on
  Cloud TPUs.
docstr: Returns a ClusterSpec object based on the latest TPU information.
  
  We retrieve the information from the GCE APIs every time this method is
  called.
  
  Returns:
    A ClusterSpec containing host information returned from Cloud TPUs,
    or None.
  
  Raises:
    RuntimeError: If the provided TPU is not healthy.
docstr_tok: ["Returns","a","ClusterSpec","object","based","on","the","latest","TPU","information",".","We","retrieve","the","information","from","the","GCE","APIs","every","time","this","method","is","called",".","Returns",":","A","ClusterSpec","containing","host","information","returned","from","Cloud","TPUs",",","or","None",".","Raises",":","RuntimeError",":","If","the","provided","TPU","is","not","healthy","."]
code: def cluster_spec(self):
      """Returns a ClusterSpec object based on the latest TPU information.
  
      We retrieve the information from the GCE APIs every time this method is
      called.
  
      Returns:
        A ClusterSpec containing host information returned from Cloud TPUs,
        or None.
  
      Raises:
        RuntimeError: If the provided TPU is not healthy.
      """
      ############################################################################
      # There are 6 potential cases this code must handle:
      #  0. [Local case.] When a TPU is connected directly to the VM.
      #  1. [Normal case.] We should resolve the TPU name to a set of tasks, and
      #      a. Create a ClusterSpec that includes the coordinator job
      #      b. Create a ClusterSpec without the coordinator job.
      #  2. [GKE / No API Access.] We should not resolve the TPU name to a set of
      #     tasks and
      #      a. Create a ClusterSpec with the coordinator
      #      b. Create a ClusterSpec without the coordinator
      ############################################################################
  
      if self._tpu != "local":
          network_endpoints = self._cloud_tpu_client.network_endpoints()
          worker_list = [
              "%s:%s" % (endpoint["ipAddress"], endpoint["port"])
              for endpoint in network_endpoints
          ]
          cluster_spec = {self.task_type: worker_list}
          if self._coordinator_address:
              # {1, 2}.a
              cluster_spec[self._coordinator_name] = [
                  self._coordinator_address
              ]
          return server_lib.ClusterSpec(cluster_spec)
      else:
          return server_lib.ClusterSpec({})
  
imports: import collections
  import re
  from tensorflow.core.protobuf.tpu import topology_pb2
  from tensorflow.python.distribute.cluster_resolver import cluster_resolver
  from tensorflow.python.eager import remote
  from tensorflow.python.framework import config
  from tensorflow.python.framework import errors
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.tpu import tpu_strategy_util
  from tensorflow.python.tpu import tpu_system_metadata
  from tensorflow.python.training import server_lib
  from tensorflow.python.util import compat
label_desc: Use image node_id 12 for calling the TPUClusterResolver obj's underlying member method code with example usage: obj.cluster_spec() and returns: server_lib, server_lib