parameters: (metadata, attr_path, required)
return_statement: return response.data
docstring: Fetch an attribute from metadata URL.
docstring_summary: Fetch an attribute from metadata URL.
docstring_tokens: Fetch an attribute from metadata URL .
function: def fetch_metadata(metadata, attr_path, required):
      """Fetch an attribute from metadata URL."""
      url = metadata + _METADATA_PATH + attr_path
      headers = {"Metadata-Flavor": "Google"}
      client = urllib3.PoolManager(ca_certs=certifi.where())
      if required:
        # GKE metadata server may take up to 30s to get access token.
        timeout = 30.0
        retries = True
      else:
        timeout = 0.1
        retries = False
      try:
        response = client.request("GET", url, headers=headers, timeout=timeout, retries=retries)
      except:
        if required:
          raise FetchError(1,
              "Failed fetching metadata attribute: " + url)
        else:
          return None
      status_code = response.status
      if status_code != 200:
        if required:
          message_template = "Failed fetching metadata attribute: {}, status code {}, reason {}"
          raise FetchError(1, message_template.format(url, status_code, response.data))
        else:
          return None
      return response.data
function_tokens: def fetch_metadata ( metadata , attr_path , required ) : url = metadata + _METADATA_PATH + attr_path headers = { "Metadata-Flavor" : "Google" } client = urllib3 . PoolManager ( ca_certs = certifi . where ( ) ) if required : # GKE metadata server may take up to 30s to get access token. timeout = 30.0 retries = True else : timeout = 0.1 retries = False try : response = client . request ( "GET" , url , headers = headers , timeout = timeout , retries = retries ) except : if required : raise FetchError ( 1 , "Failed fetching metadata attribute: " + url ) else : return None status_code = response . status if status_code != 200 : if required : message_template = "Failed fetching metadata attribute: {}, status code {}, reason {}" raise FetchError ( 1 , message_template . format ( url , status_code , response . data ) ) else : return None return response . data