2.4.3 (latest) 2.4.2 2.3.1 2.2.2 Reference documentation and code samples for the Google Cloud Platform environment queries class Google::Cloud::Env::ComputeMetadata.

A client for the Google metadata service.

## Inherits

- Object

## Methods

### #check_existence

```ruby
def check_existence(open_timeout: nil, request_timeout: nil, retry_count: :default, retry_timeout: :default) -> :no, :unconfirmed, :confirmed
```
Return detailed information about whether we think Metadata is
available. If we have not previously confirmed existence one way or
another, this could block while trying to contact the server through
the given timeouts and retries.
**Parameters**

- **open_timeout** (Numeric) *(defaults to: nil)* --- Timeout for opening http connections. Defaults to [#open_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_open_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#open_timeout (method)").
- **request_timeout** (Numeric) *(defaults to: nil)* --- Timeout for entire http requests. Defaults to [#request_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_request_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#request_timeout (method)").
- **retry_count** (Integer, nil) *(defaults to: :default)* --- Number of times to retry. A value of 1 means 2 attempts (i.e. 1 retry). A value of nil indicates retries are limited only by the timeout. Defaults to [#retry_count](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_count_instance_ "Google::Cloud::Env::ComputeMetadata#retry_count (method)").
- **retry_timeout** (Numeric, nil) *(defaults to: :default)* --- Total timeout for retries. A value of nil indicates no time limit, and retries are limited only by count. Defaults to [#retry_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#retry_timeout (method)").
**Returns**

- (:no) --- if we know the metadata server is not present
- (:unconfirmed) --- if we believe metadata should be present but we haven't gotten a confirmed response from it. This can happen if SMBIOS says we're on GCE but we can't contact the Metadata Server even through retries.
- (:confirmed) --- if we have a confirmed response from metadata.

### #ensure_existence

```ruby
def ensure_existence(timeout: nil) -> :confirmed
```
Assert that the Metadata Server should be present, and wait for a
confirmed connection to ensure it is up. This will generally run
at most [#warmup_time](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_warmup_time_instance_ "Google::Cloud::Env::ComputeMetadata#warmup_time (method)") seconds to wait out the expected maximum
warmup time, but a shorter timeout can be provided.
**Parameter**

- **timeout** (Numeric, nil) *(defaults to: nil)* --- a timeout in seconds, or nil to wait until we have conclusively decided one way or the other.
**Returns**

- (:confirmed) --- if we were able to confirm connection.
**Raises**

- ([MetadataServerNotResponding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-MetadataServerNotResponding.md.txt)) --- if we were unable to confirm connection with the Metadata Server, either because the timeout expired or because the server seems to be down

### #existence_immediate

```ruby
def existence_immediate() -> nil, :no, :unconfirmed, :confirmed
```
The current detailed existence status, without blocking on any
attempt to contact the metadata server.
**Returns**

- (nil) --- if we have no information at all yet
- (:no) --- if we know the metadata server is not present
- (:unconfirmed) --- if we believe metadata should be present but we haven't gotten a confirmed response from it.
- (:confirmed) --- if we have a confirmed response from metadata.

### #expiration_time_of

```ruby
def expiration_time_of(path, query: nil) -> Numeric, nil, false
```
Get the expiration time for the given path. Returns the monotonic
time if the data has been retrieved and has an expiration, nil if the
data has been retrieved but has no expiration, or false if the data
has not yet been retrieved.
**Returns**

- (Numeric, nil, false)

### #host

```ruby
def host() -> String
```
The host URL for the metadata server, including `http://`.
**Returns**

- (String)

### #host=

```ruby
def host=(new_host)
```
The host URL for the metadata server, including `http://`.

### #initialize

```ruby
def initialize(variables: nil, compute_smbios: nil) -> ComputeMetadata
```
Create a compute metadata access object.
**Parameters**

- **variables** ([Google::Cloud::Env::Variables](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-Variables.md.txt)) *(defaults to: nil)* --- Access object for environment variables. If not provided, a default is created.
- **compute_smbios** ([Google::Cloud::Env::ComputeSMBIOS](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeSMBIOS.md.txt)) *(defaults to: nil)* --- Access object for SMBIOS information. If not provided, a default is created.
**Returns**

- ([ComputeMetadata](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt)) --- a new instance of ComputeMetadata

### #lookup

```ruby
def lookup(path, query: nil, open_timeout: nil, request_timeout: nil, retry_count: :default, retry_timeout: :default) -> String, nil
```
Look up a particular key from the metadata server and return the data
as a string. Could return a cached value if the key has been queried
before, otherwise this could block while trying to contact the server
through the given timeouts and retries.


<br />

This returns the HTTP body as a string, only if the call succeeds. If
the key is inaccessible or missing (i.e. the HTTP status was not 200)
or does not have the correct `Metadata-Flavor` header, then nil is
returned. If you need more detailed information, use
[#lookup_response](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_lookup_response_instance_ "Google::Cloud::Env::ComputeMetadata#lookup_response (method)").
**Parameters**

- **path** (String) --- The key path (e.g. `project/project-id`)
- **query** (Hash{String =\> String}) *(defaults to: nil)* --- Any additional query parameters to send with the request.
- **open_timeout** (Numeric) *(defaults to: nil)* --- Timeout for opening http connections. Defaults to [#open_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_open_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#open_timeout (method)").
- **request_timeout** (Numeric) *(defaults to: nil)* --- Timeout for entire http requests. Defaults to [#request_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_request_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#request_timeout (method)").
- **retry_count** (Integer, nil) *(defaults to: :default)* --- Number of times to retry. A value of 1 means 2 attempts (i.e. 1 retry). A value of nil indicates retries are limited only by the timeout. Defaults to [#retry_count](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_count_instance_ "Google::Cloud::Env::ComputeMetadata#retry_count (method)").
- **retry_timeout** (Numeric, nil) *(defaults to: :default)* --- Total timeout for retries. A value of nil indicates no time limit, and retries are limited only by count. Defaults to [#retry_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#retry_timeout (method)").
**Returns**

- (String) --- the data from the metadata server
- (nil) --- if the key is not present
**Raises**

- ([MetadataServerNotResponding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-MetadataServerNotResponding.md.txt)) --- if the Metadata Server is not responding

### #lookup_response

```ruby
def lookup_response(path, query: nil, open_timeout: nil, request_timeout: nil, retry_count: :default, retry_timeout: :default) -> Response
```
Look up a particular key from the metadata server, and return a full
[Response](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata-Response.md.txt "Google::Cloud::Env::ComputeMetadata::Response (class)") object. Could return a cached value if the key has been
queried before, otherwise this could block while trying to contact
the server through the given timeouts and retries.


<br />

This returns a Response object even if the HTTP status is 404, so be
sure to check the status code to determine whether the key actually
exists. Unlike [#lookup](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_lookup_instance_ "Google::Cloud::Env::ComputeMetadata#lookup (method)"), this method does not return nil.
**Parameters**

- **path** (String) --- The key path (e.g. `project/project-id`)
- **query** (Hash{String =\> String}) *(defaults to: nil)* --- Any additional query parameters to send with the request.
- **open_timeout** (Numeric) *(defaults to: nil)* --- Timeout for opening http connections. Defaults to [#open_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_open_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#open_timeout (method)").
- **request_timeout** (Numeric) *(defaults to: nil)* --- Timeout for entire http requests. Defaults to [#request_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_request_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#request_timeout (method)").
- **retry_count** (Integer, nil) *(defaults to: :default)* --- Number of times to retry. A value of 1 means 2 attempts (i.e. 1 retry). A value of nil indicates retries are limited only by the timeout. Defaults to [#retry_count](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_count_instance_ "Google::Cloud::Env::ComputeMetadata#retry_count (method)").
- **retry_timeout** (Numeric, nil) *(defaults to: :default)* --- Total timeout for retries. A value of nil indicates no time limit, and retries are limited only by count. Defaults to [#retry_timeout](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata_retry_timeout_instance_ "Google::Cloud::Env::ComputeMetadata#retry_timeout (method)").
**Returns**

- ([Response](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata-Response.md.txt)) --- the data from the metadata server
**Raises**

- ([MetadataServerNotResponding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-MetadataServerNotResponding.md.txt)) --- if the Metadata Server is not responding

### #open_timeout

```ruby
def open_timeout() -> Numeric
```
The timeout for opening http connections in seconds.
**Returns**

- (Numeric)

### #open_timeout=

```ruby
def open_timeout=(timeout)
```
The timeout for opening http connections in seconds.
**Parameter**

- **timeout** (Numeric)

### #overrides

```ruby
def overrides() -> Overrides, nil
```
The overrides, or nil if overrides are not present.
If present, overrides will answer all metadata queries, and actual
calls to the metadata server will be blocked.
**Returns**

- ([Overrides](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata-Overrides.md.txt), nil)

### #overrides=

```ruby
def overrides=(new_overrides)
```
Set the overrides. You can also set nil to disable overrides.
If present, overrides will answer all metadata queries, and actual
calls to the metadata server will be blocked.

### #request_timeout

```ruby
def request_timeout() -> Numeric
```
The total timeout for an HTTP request in seconds.
**Returns**

- (Numeric)

### #request_timeout=

```ruby
def request_timeout=(timeout)
```
The total timeout for an HTTP request in seconds.
**Parameter**

- **timeout** (Numeric)

### #retry_count

```ruby
def retry_count() -> Integer, nil
```
The default maximum number of times to retry a query for a key.
A value of 1 means 2 attempts (i.e. 1 retry). A value of nil means
there is no limit to the number of retries, although there could be
an overall timeout.


<br />

Defaults to [DEFAULT_RETRY_COUNT](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_COUNT "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_COUNT (constant)").
**Returns**

- (Integer, nil)

### #retry_count=

```ruby
def retry_count=(value) -> Integer, nil
```
The default maximum number of times to retry a query for a key.
A value of 1 means 2 attempts (i.e. 1 retry). A value of nil means
there is no limit to the number of retries, although there could be
an overall timeout.


<br />

Defaults to [DEFAULT_RETRY_COUNT](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_COUNT "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_COUNT (constant)").
**Parameter**

- **value** (Integer, nil)
**Returns**

- (Integer, nil)

### #retry_interval

```ruby
def retry_interval() -> Numeric
```
The time in seconds between retries. This time includes the time
spent by the previous attempt.


<br />

Defaults to [DEFAULT_RETRY_INTERVAL](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_INTERVAL "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_INTERVAL (constant)").
**Returns**

- (Numeric)

### #retry_interval=

```ruby
def retry_interval=(value) -> Numeric
```
The time in seconds between retries. This time includes the time
spent by the previous attempt.


<br />

Defaults to [DEFAULT_RETRY_INTERVAL](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_INTERVAL "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_INTERVAL (constant)").
**Parameter**

- **value** (Numeric)
**Returns**

- (Numeric)

### #retry_timeout

```ruby
def retry_timeout() -> Numeric, nil
```
The default overall timeout across all retries of a lookup, in
seconds. A value of nil means there is no timeout, although there
could be a limit to the number of retries.


<br />

Defaults to [DEFAULT_RETRY_TIMEOUT](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_TIMEOUT "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_TIMEOUT (constant)").
**Returns**

- (Numeric, nil)

### #retry_timeout=

```ruby
def retry_timeout=(value) -> Numeric, nil
```
The default overall timeout across all retries of a lookup, in
seconds. A value of nil means there is no timeout, although there
could be a limit to the number of retries.


<br />

Defaults to [DEFAULT_RETRY_TIMEOUT](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_RETRY_TIMEOUT "Google::Cloud::Env::ComputeMetadata::DEFAULT_RETRY_TIMEOUT (constant)").
**Parameter**

- **value** (Numeric, nil)
**Returns**

- (Numeric, nil)

### #warmup_time

```ruby
def warmup_time() -> Numeric, nil
```
A time in seconds allotted to environment warmup, during which
retries will not be ended. This handles certain environments in which
the Metadata Server might not be fully awake until some time after
application startup. A value of nil disables this warmup period.


<br />

Defaults to [DEFAULT_WARMUP_TIME](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_WARMUP_TIME "Google::Cloud::Env::ComputeMetadata::DEFAULT_WARMUP_TIME (constant)").
**Returns**

- (Numeric, nil)

### #warmup_time=

```ruby
def warmup_time=(value) -> Numeric, nil
```
A time in seconds allotted to environment warmup, during which
retries will not be ended. This handles certain environments in which
the Metadata Server might not be fully awake until some time after
application startup. A value of nil disables this warmup period.


<br />

Defaults to [DEFAULT_WARMUP_TIME](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata.md.txt#Google__Cloud__Env__ComputeMetadata__DEFAULT_WARMUP_TIME "Google::Cloud::Env::ComputeMetadata::DEFAULT_WARMUP_TIME (constant)").
**Parameter**

- **value** (Numeric, nil)
**Returns**

- (Numeric, nil)

### #with_overrides

```ruby
def with_overrides(temp_overrides)
```
Run the given block with the overrides replaced with the given set
(or nil to disable overrides in the block). The original overrides
setting is restored at the end of the block. This is used for
debugging/testing/mocking.
**Parameter**

- **temp_overrides** ([Overrides](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-env/latest/Google-Cloud-Env-ComputeMetadata-Overrides.md.txt), nil)

## Constants

### DEFAULT_HOST

**value:** "http://169.254.169.254"  
The default host for the metadata server

### DEFAULT_OPEN_TIMEOUT

**value:** 0.1  
The default timeout in seconds for opening http connections

### DEFAULT_REQUEST_TIMEOUT

**value:** 0.5  
The default timeout in seconds for request responses

### DEFAULT_RETRY_COUNT

**value:** 2  
The default number of retries

### DEFAULT_RETRY_TIMEOUT

**value:** nil  
The default timeout across retries

### DEFAULT_RETRY_INTERVAL

**value:** 0.5  
The default interval between retries, in seconds

### DEFAULT_WARMUP_TIME

**value:** 60  
The default time in seconds to wait for environment warmup.