parameters: (relative_url, use_metadata_ip=False)
return_statement: return response
docstring: Request the given url from the GCE metadata service.
docstring_summary: Request the given url from the GCE metadata service.
docstring_tokens: Request the given url from the GCE metadata service .
function: def _GceMetadataRequest(relative_url, use_metadata_ip=False):
      """Request the given url from the GCE metadata service."""
      if use_metadata_ip:
          base_url = 'http://169.254.169.254/'
      else:
          base_url = 'http://metadata.google.internal/'
      url = base_url + 'computeMetadata/v1/' + relative_url
      # Extra header requirement can be found here:
      # https://developers.google.com/compute/docs/metadata
      headers = {'Metadata-Flavor': 'Google'}
      request = urllib.request.Request(url, headers=headers)
      opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
      try:
          response = opener.open(request)
      except urllib.error.URLError as e:
          raise exceptions.CommunicationError(
              'Could not reach metadata service: %s' % e.reason)
      return response
function_tokens: def _GceMetadataRequest ( relative_url , use_metadata_ip = False ) : if use_metadata_ip : base_url = 'http://169.254.169.254/' else : base_url = 'http://metadata.google.internal/' url = base_url + 'computeMetadata/v1/' + relative_url # Extra header requirement can be found here: # https://developers.google.com/compute/docs/metadata headers = { 'Metadata-Flavor' : 'Google' } request = urllib . request . Request ( url , headers = headers ) opener = urllib . request . build_opener ( urllib . request . ProxyHandler ( { } ) ) try : response = opener . open ( request ) except urllib . error . URLError as e : raise exceptions . CommunicationError ( 'Could not reach metadata service: %s' % e . reason ) return response