# frozen_string_literal: true # Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Auto-generated by gapic-generator-ruby. DO NOT EDIT! require "google/cloud/errors" require "google/cloud/tpu/v1/cloud_tpu_pb" module Google module Cloud module Tpu module V1 module Tpu ## # Client for the Tpu service. # # Manages TPU nodes and other resources # # TPU API v1 # class Client include Paths # @private attr_reader :tpu_stub ## # Configure the Tpu Client class. # # See {::Google::Cloud::Tpu::V1::Tpu::Client::Configuration} # for a description of the configuration fields. # # @example # # # Modify the configuration for all Tpu clients # ::Google::Cloud::Tpu::V1::Tpu::Client.configure do |config| # config.timeout = 10.0 # end # # @yield [config] Configure the Client client. # @yieldparam config [Client::Configuration] # # @return [Client::Configuration] # def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Tpu", "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.timeout = 60.0 default_config end yield @configure if block_given? @configure end ## # Configure the Tpu 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 {Client.configure}. # # See {::Google::Cloud::Tpu::V1::Tpu::Client::Configuration} # for a description of the configuration fields. # # @yield [config] Configure the Client client. # @yieldparam config [Client::Configuration] # # @return [Client::Configuration] # def configure yield @config if block_given? @config end ## # Create a new Tpu client object. # # @example # # # Create a client using the default configuration # client = ::Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a client using a custom configuration # client = ::Google::Cloud::Tpu::V1::Tpu::Client.new do |config| # config.timeout = 10.0 # end # # @yield [config] Configure the Tpu client. # @yieldparam config [Client::Configuration] # def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/cloud/tpu/v1/cloud_tpu_services_pb" # 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 == Client.configure.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 @operations_client = Operations.new do |config| config.credentials = credentials config.endpoint = @config.endpoint end @tpu_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Tpu::V1::Tpu::Stub, credentials: credentials, endpoint: @config.endpoint, channel_args: @config.channel_args, interceptors: @config.interceptors ) end ## # Get the associated client for long-running operations. # # @return [::Google::Cloud::Tpu::V1::Tpu::Operations] # attr_reader :operations_client # Service calls ## # Lists nodes. # # @overload list_nodes(request, options = nil) # Pass arguments to `list_nodes` via a request object, either of type # {::Google::Cloud::Tpu::V1::ListNodesRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::ListNodesRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload list_nodes(parent: nil, page_size: nil, page_token: nil) # Pass arguments to `list_nodes` 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). # # @param parent [::String] # Required. The parent resource name. # @param page_size [::Integer] # The maximum number of items to return. # @param page_token [::String] # The next_page_token value returned from a previous List request, if any. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::Node>] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::Node>] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::ListNodesRequest.new # # # Call the list_nodes method. # result = client.list_nodes request # # # The returned object is of type Gapic::PagedEnumerable. You can # # iterate over all elements by calling #each, and the enumerable # # will lazily make API calls to fetch subsequent pages. Other # # methods are also available for managing paging directly. # result.each do |response| # # Each element is of type ::Google::Cloud::Tpu::V1::Node. # p response # end # def list_nodes request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::ListNodesRequest # 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 metadata = @config.rpcs.list_nodes.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_nodes.timeout, metadata: metadata, retry_policy: @config.rpcs.list_nodes.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :list_nodes, request, options: options do |response, operation| response = ::Gapic::PagedEnumerable.new @tpu_stub, :list_nodes, request, response, operation, options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Gets the details of a node. # # @overload get_node(request, options = nil) # Pass arguments to `get_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::GetNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::GetNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload get_node(name: nil) # Pass arguments to `get_node` 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). # # @param name [::String] # Required. The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Tpu::V1::Node] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Tpu::V1::Node] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::GetNodeRequest.new # # # Call the get_node method. # result = client.get_node request # # # The returned object is of type Google::Cloud::Tpu::V1::Node. # p result # def get_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::GetNodeRequest # 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 metadata = @config.rpcs.get_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_node.timeout, metadata: metadata, retry_policy: @config.rpcs.get_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :get_node, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Creates a node. # # @overload create_node(request, options = nil) # Pass arguments to `create_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::CreateNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::CreateNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload create_node(parent: nil, node_id: nil, node: nil) # Pass arguments to `create_node` 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). # # @param parent [::String] # Required. The parent resource name. # @param node_id [::String] # The unqualified resource name. # @param node [::Google::Cloud::Tpu::V1::Node, ::Hash] # Required. The node. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::CreateNodeRequest.new # # # Call the create_node method. # result = client.create_node request # # # The returned object is of type Gapic::Operation. You can use this # # object to check the status of an operation, cancel it, or wait # # for results. Here is how to block until completion: # result.wait_until_done! timeout: 60 # if result.response? # p result.response # else # puts "Error!" # end # def create_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::CreateNodeRequest # 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 metadata = @config.rpcs.create_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_node.timeout, metadata: metadata, retry_policy: @config.rpcs.create_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :create_node, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Deletes a node. # # @overload delete_node(request, options = nil) # Pass arguments to `delete_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::DeleteNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::DeleteNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload delete_node(name: nil) # Pass arguments to `delete_node` 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). # # @param name [::String] # Required. The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::DeleteNodeRequest.new # # # Call the delete_node method. # result = client.delete_node request # # # The returned object is of type Gapic::Operation. You can use this # # object to check the status of an operation, cancel it, or wait # # for results. Here is how to block until completion: # result.wait_until_done! timeout: 60 # if result.response? # p result.response # else # puts "Error!" # end # def delete_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::DeleteNodeRequest # 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 metadata = @config.rpcs.delete_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_node.timeout, metadata: metadata, retry_policy: @config.rpcs.delete_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :delete_node, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Reimages a node's OS. # # @overload reimage_node(request, options = nil) # Pass arguments to `reimage_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::ReimageNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::ReimageNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload reimage_node(name: nil, tensorflow_version: nil) # Pass arguments to `reimage_node` 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). # # @param name [::String] # The resource name. # @param tensorflow_version [::String] # The version for reimage to create. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::ReimageNodeRequest.new # # # Call the reimage_node method. # result = client.reimage_node request # # # The returned object is of type Gapic::Operation. You can use this # # object to check the status of an operation, cancel it, or wait # # for results. Here is how to block until completion: # result.wait_until_done! timeout: 60 # if result.response? # p result.response # else # puts "Error!" # end # def reimage_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::ReimageNodeRequest # 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 metadata = @config.rpcs.reimage_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.reimage_node.timeout, metadata: metadata, retry_policy: @config.rpcs.reimage_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :reimage_node, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Stops a node. # # @overload stop_node(request, options = nil) # Pass arguments to `stop_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::StopNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::StopNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload stop_node(name: nil) # Pass arguments to `stop_node` 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). # # @param name [::String] # The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::StopNodeRequest.new # # # Call the stop_node method. # result = client.stop_node request # # # The returned object is of type Gapic::Operation. You can use this # # object to check the status of an operation, cancel it, or wait # # for results. Here is how to block until completion: # result.wait_until_done! timeout: 60 # if result.response? # p result.response # else # puts "Error!" # end # def stop_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::StopNodeRequest # 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 metadata = @config.rpcs.stop_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.stop_node.timeout, metadata: metadata, retry_policy: @config.rpcs.stop_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :stop_node, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Starts a node. # # @overload start_node(request, options = nil) # Pass arguments to `start_node` via a request object, either of type # {::Google::Cloud::Tpu::V1::StartNodeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::StartNodeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload start_node(name: nil) # Pass arguments to `start_node` 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). # # @param name [::String] # The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::StartNodeRequest.new # # # Call the start_node method. # result = client.start_node request # # # The returned object is of type Gapic::Operation. You can use this # # object to check the status of an operation, cancel it, or wait # # for results. Here is how to block until completion: # result.wait_until_done! timeout: 60 # if result.response? # p result.response # else # puts "Error!" # end # def start_node request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::StartNodeRequest # 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 metadata = @config.rpcs.start_node.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.start_node.timeout, metadata: metadata, retry_policy: @config.rpcs.start_node.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :start_node, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # List TensorFlow versions supported by this API. # # @overload list_tensor_flow_versions(request, options = nil) # Pass arguments to `list_tensor_flow_versions` via a request object, either of type # {::Google::Cloud::Tpu::V1::ListTensorFlowVersionsRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::ListTensorFlowVersionsRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload list_tensor_flow_versions(parent: nil, page_size: nil, page_token: nil, filter: nil, order_by: nil) # Pass arguments to `list_tensor_flow_versions` 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). # # @param parent [::String] # Required. The parent resource name. # @param page_size [::Integer] # The maximum number of items to return. # @param page_token [::String] # The next_page_token value returned from a previous List request, if any. # @param filter [::String] # List filter. # @param order_by [::String] # Sort results. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::TensorFlowVersion>] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::TensorFlowVersion>] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::ListTensorFlowVersionsRequest.new # # # Call the list_tensor_flow_versions method. # result = client.list_tensor_flow_versions request # # # The returned object is of type Gapic::PagedEnumerable. You can # # iterate over all elements by calling #each, and the enumerable # # will lazily make API calls to fetch subsequent pages. Other # # methods are also available for managing paging directly. # result.each do |response| # # Each element is of type ::Google::Cloud::Tpu::V1::TensorFlowVersion. # p response # end # def list_tensor_flow_versions request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::ListTensorFlowVersionsRequest # 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 metadata = @config.rpcs.list_tensor_flow_versions.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_tensor_flow_versions.timeout, metadata: metadata, retry_policy: @config.rpcs.list_tensor_flow_versions.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :list_tensor_flow_versions, request, options: options do |response, operation| response = ::Gapic::PagedEnumerable.new @tpu_stub, :list_tensor_flow_versions, request, response, operation, options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Gets TensorFlow Version. # # @overload get_tensor_flow_version(request, options = nil) # Pass arguments to `get_tensor_flow_version` via a request object, either of type # {::Google::Cloud::Tpu::V1::GetTensorFlowVersionRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::GetTensorFlowVersionRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload get_tensor_flow_version(name: nil) # Pass arguments to `get_tensor_flow_version` 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). # # @param name [::String] # Required. The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Tpu::V1::TensorFlowVersion] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Tpu::V1::TensorFlowVersion] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::GetTensorFlowVersionRequest.new # # # Call the get_tensor_flow_version method. # result = client.get_tensor_flow_version request # # # The returned object is of type Google::Cloud::Tpu::V1::TensorFlowVersion. # p result # def get_tensor_flow_version request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::GetTensorFlowVersionRequest # 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 metadata = @config.rpcs.get_tensor_flow_version.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_tensor_flow_version.timeout, metadata: metadata, retry_policy: @config.rpcs.get_tensor_flow_version.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :get_tensor_flow_version, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Lists accelerator types supported by this API. # # @overload list_accelerator_types(request, options = nil) # Pass arguments to `list_accelerator_types` via a request object, either of type # {::Google::Cloud::Tpu::V1::ListAcceleratorTypesRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::ListAcceleratorTypesRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload list_accelerator_types(parent: nil, page_size: nil, page_token: nil, filter: nil, order_by: nil) # Pass arguments to `list_accelerator_types` 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). # # @param parent [::String] # Required. The parent resource name. # @param page_size [::Integer] # The maximum number of items to return. # @param page_token [::String] # The next_page_token value returned from a previous List request, if any. # @param filter [::String] # List filter. # @param order_by [::String] # Sort results. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::AcceleratorType>] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::PagedEnumerable<::Google::Cloud::Tpu::V1::AcceleratorType>] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::ListAcceleratorTypesRequest.new # # # Call the list_accelerator_types method. # result = client.list_accelerator_types request # # # The returned object is of type Gapic::PagedEnumerable. You can # # iterate over all elements by calling #each, and the enumerable # # will lazily make API calls to fetch subsequent pages. Other # # methods are also available for managing paging directly. # result.each do |response| # # Each element is of type ::Google::Cloud::Tpu::V1::AcceleratorType. # p response # end # def list_accelerator_types request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::ListAcceleratorTypesRequest # 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 metadata = @config.rpcs.list_accelerator_types.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_accelerator_types.timeout, metadata: metadata, retry_policy: @config.rpcs.list_accelerator_types.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :list_accelerator_types, request, options: options do |response, operation| response = ::Gapic::PagedEnumerable.new @tpu_stub, :list_accelerator_types, request, response, operation, options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Gets AcceleratorType. # # @overload get_accelerator_type(request, options = nil) # Pass arguments to `get_accelerator_type` via a request object, either of type # {::Google::Cloud::Tpu::V1::GetAcceleratorTypeRequest} or an equivalent Hash. # # @param request [::Google::Cloud::Tpu::V1::GetAcceleratorTypeRequest, ::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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload get_accelerator_type(name: nil) # Pass arguments to `get_accelerator_type` 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). # # @param name [::String] # Required. The resource name. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Tpu::V1::AcceleratorType] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Tpu::V1::AcceleratorType] # # @raise [::Google::Cloud::Error] if the RPC is aborted. # # @example Basic example # require "google/cloud/tpu/v1" # # # Create a client object. The client can be reused for multiple calls. # client = Google::Cloud::Tpu::V1::Tpu::Client.new # # # Create a request. To set request fields, pass in keyword arguments. # request = Google::Cloud::Tpu::V1::GetAcceleratorTypeRequest.new # # # Call the get_accelerator_type method. # result = client.get_accelerator_type request # # # The returned object is of type Google::Cloud::Tpu::V1::AcceleratorType. # p result # def get_accelerator_type request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Tpu::V1::GetAcceleratorTypeRequest # 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 metadata = @config.rpcs.get_accelerator_type.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Tpu::V1::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_accelerator_type.timeout, metadata: metadata, retry_policy: @config.rpcs.get_accelerator_type.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @tpu_stub.call_rpc :get_accelerator_type, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Configuration class for the Tpu API. # # This class represents the configuration for Tpu, # providing control over timeouts, retry behavior, logging, transport # parameters, and other low-level controls. Certain parameters can also be # applied individually to specific RPCs. See # {::Google::Cloud::Tpu::V1::Tpu::Client::Configuration::Rpcs} # for a list of RPCs that can be configured independently. # # Configuration can be applied globally to all clients, or to a single client # on construction. # # @example # # # Modify the global config, setting the timeout for # # list_nodes to 20 seconds, # # and all remaining timeouts to 10 seconds. # ::Google::Cloud::Tpu::V1::Tpu::Client.configure do |config| # config.timeout = 10.0 # config.rpcs.list_nodes.timeout = 20.0 # end # # # Apply the above configuration only to a new client. # client = ::Google::Cloud::Tpu::V1::Tpu::Client.new do |config| # config.timeout = 10.0 # config.rpcs.list_nodes.timeout = 20.0 # end # # @!attribute [rw] endpoint # The hostname or hostname:port of the service endpoint. # Defaults to `"tpu.googleapis.com"`. # @return [::String] # @!attribute [rw] credentials # Credentials to send with calls. You may provide any of the following types: # * (`String`) The path to a service account key file in JSON format # * (`Hash`) A service account key as a Hash # * (`Google::Auth::Credentials`) A googleauth credentials object # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html)) # * (`Signet::OAuth2::Client`) A signet oauth2 client object # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html)) # * (`GRPC::Core::Channel`) a gRPC channel with included credentials # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object # * (`nil`) indicating no credentials # @return [::Object] # @!attribute [rw] scope # The OAuth scopes # @return [::Array<::String>] # @!attribute [rw] lib_name # The library name as recorded in instrumentation and logging # @return [::String] # @!attribute [rw] lib_version # The library version as recorded in instrumentation and logging # @return [::String] # @!attribute [rw] channel_args # Extra parameters passed to the gRPC channel. Note: this is ignored if a # `GRPC::Core::Channel` object is provided as the credential. # @return [::Hash] # @!attribute [rw] interceptors # An array of interceptors that are run before calls are executed. # @return [::Array<::GRPC::ClientInterceptor>] # @!attribute [rw] timeout # The call timeout in seconds. # @return [::Numeric] # @!attribute [rw] metadata # Additional gRPC headers to be sent with the call. # @return [::Hash{::Symbol=>::String}] # @!attribute [rw] retry_policy # The retry policy. The value is a hash with the following keys: # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. # * `:retry_codes` (*type:* `Array`) - The error codes that should # trigger a retry. # @return [::Hash] # @!attribute [rw] quota_project # A separate project against which to charge quota. # @return [::String] # class Configuration extend ::Gapic::Config config_attr :endpoint, "tpu.googleapis.com", ::String config_attr :credentials, nil do |value| allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC allowed.any? { |klass| klass === value } end config_attr :scope, nil, ::String, ::Array, nil config_attr :lib_name, nil, ::String, nil config_attr :lib_version, nil, ::String, nil config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil) config_attr :interceptors, nil, ::Array, nil config_attr :timeout, nil, ::Numeric, nil config_attr :metadata, nil, ::Hash, nil config_attr :retry_policy, nil, ::Hash, ::Proc, nil config_attr :quota_project, nil, ::String, nil # @private def initialize parent_config = nil @parent_config = parent_config unless parent_config.nil? yield self if block_given? end ## # Configurations for individual RPCs # @return [Rpcs] # def rpcs @rpcs ||= begin parent_rpcs = nil parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) Rpcs.new parent_rpcs end end ## # Configuration RPC class for the Tpu API. # # Includes fields providing the configuration for each RPC in this service. # Each configuration object is of type `Gapic::Config::Method` and includes # the following configuration fields: # # * `timeout` (*type:* `Numeric`) - The call timeout in seconds # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields # include the following keys: # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. # * `:retry_codes` (*type:* `Array`) - The error codes that should # trigger a retry. # class Rpcs ## # RPC-specific configuration for `list_nodes` # @return [::Gapic::Config::Method] # attr_reader :list_nodes ## # RPC-specific configuration for `get_node` # @return [::Gapic::Config::Method] # attr_reader :get_node ## # RPC-specific configuration for `create_node` # @return [::Gapic::Config::Method] # attr_reader :create_node ## # RPC-specific configuration for `delete_node` # @return [::Gapic::Config::Method] # attr_reader :delete_node ## # RPC-specific configuration for `reimage_node` # @return [::Gapic::Config::Method] # attr_reader :reimage_node ## # RPC-specific configuration for `stop_node` # @return [::Gapic::Config::Method] # attr_reader :stop_node ## # RPC-specific configuration for `start_node` # @return [::Gapic::Config::Method] # attr_reader :start_node ## # RPC-specific configuration for `list_tensor_flow_versions` # @return [::Gapic::Config::Method] # attr_reader :list_tensor_flow_versions ## # RPC-specific configuration for `get_tensor_flow_version` # @return [::Gapic::Config::Method] # attr_reader :get_tensor_flow_version ## # RPC-specific configuration for `list_accelerator_types` # @return [::Gapic::Config::Method] # attr_reader :list_accelerator_types ## # RPC-specific configuration for `get_accelerator_type` # @return [::Gapic::Config::Method] # attr_reader :get_accelerator_type # @private def initialize parent_rpcs = nil list_nodes_config = parent_rpcs.list_nodes if parent_rpcs.respond_to? :list_nodes @list_nodes = ::Gapic::Config::Method.new list_nodes_config get_node_config = parent_rpcs.get_node if parent_rpcs.respond_to? :get_node @get_node = ::Gapic::Config::Method.new get_node_config create_node_config = parent_rpcs.create_node if parent_rpcs.respond_to? :create_node @create_node = ::Gapic::Config::Method.new create_node_config delete_node_config = parent_rpcs.delete_node if parent_rpcs.respond_to? :delete_node @delete_node = ::Gapic::Config::Method.new delete_node_config reimage_node_config = parent_rpcs.reimage_node if parent_rpcs.respond_to? :reimage_node @reimage_node = ::Gapic::Config::Method.new reimage_node_config stop_node_config = parent_rpcs.stop_node if parent_rpcs.respond_to? :stop_node @stop_node = ::Gapic::Config::Method.new stop_node_config start_node_config = parent_rpcs.start_node if parent_rpcs.respond_to? :start_node @start_node = ::Gapic::Config::Method.new start_node_config list_tensor_flow_versions_config = parent_rpcs.list_tensor_flow_versions if parent_rpcs.respond_to? :list_tensor_flow_versions @list_tensor_flow_versions = ::Gapic::Config::Method.new list_tensor_flow_versions_config get_tensor_flow_version_config = parent_rpcs.get_tensor_flow_version if parent_rpcs.respond_to? :get_tensor_flow_version @get_tensor_flow_version = ::Gapic::Config::Method.new get_tensor_flow_version_config list_accelerator_types_config = parent_rpcs.list_accelerator_types if parent_rpcs.respond_to? :list_accelerator_types @list_accelerator_types = ::Gapic::Config::Method.new list_accelerator_types_config get_accelerator_type_config = parent_rpcs.get_accelerator_type if parent_rpcs.respond_to? :get_accelerator_type @get_accelerator_type = ::Gapic::Config::Method.new get_accelerator_type_config yield self if block_given? end end end end end end end end end