Class: Google::Cloud::Compute::V1::Advice::Rest::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/compute/v1/advice/rest/client.rb

Overview

REST client for the Advice service.

The Advice API.

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new Advice REST client object.

Examples:


# Create a client using the default configuration
client = ::Google::Cloud::Compute::V1::Advice::Rest::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Compute::V1::Advice::Rest::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config) —

    Configure the Advice client.

Yield Parameters:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 130

def initialize
  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  # Use self-signed JWT if the endpoint is unchanged from default,
  # but only if the default endpoint does not have a region prefix.
  enable_self_signed_jwt = @config.endpoint.nil? ||
                           (@config.endpoint == Configuration::DEFAULT_ENDPOINT &&
                           !@config.endpoint.split(".").first.include?("-"))
  credentials ||= Credentials.default scope: @config.scope,
                                      enable_self_signed_jwt: enable_self_signed_jwt
  if credentials.is_a?(::String) || credentials.is_a?(::Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end

  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @advice_stub = ::Google::Cloud::Compute::V1::Advice::Rest::ServiceStub.new(
    endpoint: @config.endpoint,
    endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
    universe_domain: @config.universe_domain,
    credentials: credentials,
    logger: @config.logger
  )

  @advice_stub.logger(stub: true)&.info do |entry|
    entry.set_system_name
    entry.set_service
    entry.message = "Created client for #{entry.service}"
    entry.set_credentials_fields credentials
    entry.set "customEndpoint", @config.endpoint if @config.endpoint
    entry.set "defaultTimeout", @config.timeout if @config.timeout
    entry.set "quotaProject", @quota_project_id if @quota_project_id
  end
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the Advice Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all Advice clients
::Google::Cloud::Compute::V1::Advice::Rest::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config) —

    Configure the Client client.

Yield Parameters:

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 62

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "Compute", "V1"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end
    default_config = Client::Configuration.new parent_config

    default_config.rpcs.calendar_mode.timeout = 600.0

    default_config.rpcs.capacity.timeout = 600.0

    default_config.rpcs.capacity_history.timeout = 600.0

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#calendar_mode(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CalendarModeAdviceResponse #calendar_mode(calendar_mode_advice_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CalendarModeAdviceResponse

Advise how, where and when to create the requested amount of instances with specified accelerators, within the specified time and location limits. The method recommends creating future reservations for the requested resources.

Examples:

Basic example

require "google/cloud/compute/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Compute::V1::Advice::Rest::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Compute::V1::CalendarModeAdviceRpcRequest.new

# Call the calendar_mode method.
result = client.calendar_mode request

# The returned object is of type Google::Cloud::Compute::V1::CalendarModeAdviceResponse.
p result

Overloads:

  • #calendar_mode(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CalendarModeAdviceResponse

    Pass arguments to calendar_mode via a request object, either of type CalendarModeAdviceRpcRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Compute::V1::CalendarModeAdviceRpcRequest, ::Hash) —

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil) —

      Overrides the default settings for this call, e.g, timeout, retries etc. Optional.

  • #calendar_mode(calendar_mode_advice_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CalendarModeAdviceResponse

    Pass arguments to calendar_mode via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • calendar_mode_advice_request_resource (::Google::Cloud::Compute::V1::CalendarModeAdviceRequest, ::Hash) (defaults to: nil) —

      The body resource for this request

    • project (::String) (defaults to: nil) —

      Project ID for this request.

    • region (::String) (defaults to: nil) —

      Name of the region for this request.

Yields:

  • (result, operation) —

    Access the result along with the TransportOperation object

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error) —

    if the REST call is aborted.



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 233

def calendar_mode request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Compute::V1::CalendarModeAdviceRpcRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.calendar_mode..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Compute::V1::VERSION,
    transports_version_send: [:rest]

  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  options.apply_defaults timeout:      @config.rpcs.calendar_mode.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.calendar_mode.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @advice_stub.calendar_mode request, options do |result, operation|
    yield result, operation if block_given?
  end
rescue ::Gapic::Rest::Error => e
  raise ::Google::Cloud::Error.from_error(e)
end

#capacity(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CapacityAdviceResponse #capacity(capacity_advice_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CapacityAdviceResponse

Advice on making real-time decisions (such as choosing zone or machine types) during deployment to maximize your chances of obtaining capacity.

Examples:

Basic example

require "google/cloud/compute/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Compute::V1::Advice::Rest::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Compute::V1::CapacityAdviceRpcRequest.new

# Call the capacity method.
result = client.capacity request

# The returned object is of type Google::Cloud::Compute::V1::CapacityAdviceResponse.
p result

Overloads:

  • #capacity(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CapacityAdviceResponse

    Pass arguments to capacity via a request object, either of type CapacityAdviceRpcRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Compute::V1::CapacityAdviceRpcRequest, ::Hash) —

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil) —

      Overrides the default settings for this call, e.g, timeout, retries etc. Optional.

  • #capacity(capacity_advice_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CapacityAdviceResponse

    Pass arguments to capacity via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • capacity_advice_request_resource (::Google::Cloud::Compute::V1::CapacityAdviceRequest, ::Hash) (defaults to: nil) —

      The body resource for this request

    • project (::String) (defaults to: nil) —

      Project ID for this request.

    • region (::String) (defaults to: nil) —

      Name of the region for this request.

Yields:

  • (result, operation) —

    Access the result along with the TransportOperation object

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error) —

    if the REST call is aborted.



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 317

def capacity request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Compute::V1::CapacityAdviceRpcRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.capacity..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Compute::V1::VERSION,
    transports_version_send: [:rest]

  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  options.apply_defaults timeout:      @config.rpcs.capacity.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.capacity.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @advice_stub.capacity request, options do |result, operation|
    yield result, operation if block_given?
  end
rescue ::Gapic::Rest::Error => e
  raise ::Google::Cloud::Error.from_error(e)
end

#capacity_history(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CapacityHistoryResponse #capacity_history(capacity_history_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CapacityHistoryResponse

Gets the capacity history.

Examples:

Basic example

require "google/cloud/compute/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Compute::V1::Advice::Rest::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Compute::V1::CapacityHistoryAdviceRequest.new

# Call the capacity_history method.
result = client.capacity_history request

# The returned object is of type Google::Cloud::Compute::V1::CapacityHistoryResponse.
p result

Overloads:

  • #capacity_history(request, options = nil) ⇒ ::Google::Cloud::Compute::V1::CapacityHistoryResponse

    Pass arguments to capacity_history via a request object, either of type CapacityHistoryAdviceRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::Compute::V1::CapacityHistoryAdviceRequest, ::Hash) —

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil) —

      Overrides the default settings for this call, e.g, timeout, retries etc. Optional.

  • #capacity_history(capacity_history_request_resource: nil, project: nil, region: nil) ⇒ ::Google::Cloud::Compute::V1::CapacityHistoryResponse

    Pass arguments to capacity_history via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • capacity_history_request_resource (::Google::Cloud::Compute::V1::CapacityHistoryRequest, ::Hash) (defaults to: nil) —

      The body resource for this request

    • project (::String) (defaults to: nil) —

      Project ID for this request.

    • region (::String) (defaults to: nil) —

      Name of the region for this request.

Yields:

  • (result, operation) —

    Access the result along with the TransportOperation object

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error) —

    if the REST call is aborted.



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 399

def capacity_history request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Compute::V1::CapacityHistoryAdviceRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.capacity_history..to_h

  # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::Compute::V1::VERSION,
    transports_version_send: [:rest]

  [:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  options.apply_defaults timeout:      @config.rpcs.capacity_history.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.capacity_history.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @advice_stub.capacity_history request, options do |result, operation|
    yield result, operation if block_given?
  end
rescue ::Gapic::Rest::Error => e
  raise ::Google::Cloud::Error.from_error(e)
end

#configure {|config| ... } ⇒ Client::Configuration

Configure the Advice Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config) —

    Configure the Client client.

Yield Parameters:

Returns:



100
101
102
103
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 100

def configure
  yield @config if block_given?
  @config
end

#logger ⇒ Logger

The logger used for request/response debug logging.

Returns:

  • (Logger)


177
178
179
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 177

def logger
  @advice_stub.logger
end

#universe_domain ⇒ String

The effective universe domain

Returns:

  • (String)


110
111
112
# File 'lib/google/cloud/compute/v1/advice/rest/client.rb', line 110

def universe_domain
  @advice_stub.universe_domain
end