google.cloud.forseti.common.util.metadata_server module

Metadata server utilities.

The metadata server is only accessible on GCE.

_issue_http_request(method, path, headers)[source]

Perform a request on a specified httplib connection object.

Parameters:
  • method (str) – The http request method.
  • path (str) – The path on the server.
  • headers (dict) – A key-value pairs of headers.
Returns:

The HTTP response object.

Return type:

httplib.HTTPResponse

Raises:

MetadataServerHttpError – When we can’t reach the requested host.

_obtain_http_client(hostname='metadata.google.internal')[source]

Get an HTTP client to the GCP metadata server.

Parameters:hostname (str) – A qualified hostname.
Returns:A simple HTTP client to the GCP metadata server.
Return type:HttpClient
can_reach_metadata_server()[source]

Determine if we can reach the metadata server.

Returns:True if metadata server can be reached, False otherwise.
Return type:bool
get_project_id()[source]

Get the project id from the metadata server.

Returns:The of the project id, on error, returns None.
Return type:str
get_value_for_attribute(attribute)[source]

For a given key return the value.

Parameters:attribute (str) – Some metadata key.
Returns:The value of the requested key, if key isn’t present then None.
Return type:str