Cloud TPU API v1 - Package cloud.google.com/go/tpu/apiv1 (v1.8.4) Stay organized with collections Save and categorize content based on your preferences.
Package tpu is an auto-generated package for theCloud TPU API.
TPU API provides customers with access to Google TPU technology.
General documentation
For information that is relevant for all client libraries please referencehttps://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on thispage includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/tpu/apiv1@latestctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed.The methods of Client are safe for concurrent use by multiple goroutines.The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req:=&tpupb.CreateNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#CreateNodeRequest.}op,err:=c.CreateNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp
Use of Context
The ctx passed to NewClient is used for authentication requests andfor creating the underlying connection, but is not used for subsequent calls.Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
funcDefaultAuthScopes()[]stringDefaultAuthScopes reports the default set of authentication scopes to use with this package.
AcceleratorTypeIterator
typeAcceleratorTypeIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*tpupb.AcceleratorType,nextPageTokenstring,errerror)// contains filtered or unexported fields}AcceleratorTypeIterator manages a stream of *tpupb.AcceleratorType.
func (*AcceleratorTypeIterator) All
func(it*AcceleratorTypeIterator)All()iter.Seq2[*tpupb.AcceleratorType,error]All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.
func (*AcceleratorTypeIterator) Next
func(it*AcceleratorTypeIterator)Next()(*tpupb.AcceleratorType,error)Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.
func (*AcceleratorTypeIterator) PageInfo
func(it*AcceleratorTypeIterator)PageInfo()*iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
CallOptions
typeCallOptionsstruct{ListNodes[]gax.CallOptionGetNode[]gax.CallOptionCreateNode[]gax.CallOptionDeleteNode[]gax.CallOptionReimageNode[]gax.CallOptionStopNode[]gax.CallOptionStartNode[]gax.CallOptionListTensorFlowVersions[]gax.CallOptionGetTensorFlowVersion[]gax.CallOptionListAcceleratorTypes[]gax.CallOptionGetAcceleratorType[]gax.CallOptionGetLocation[]gax.CallOptionListLocations[]gax.CallOptionCancelOperation[]gax.CallOptionDeleteOperation[]gax.CallOptionGetOperation[]gax.CallOptionListOperations[]gax.CallOption}CallOptions contains the retry settings for each method of Client.
Client
typeClientstruct{// The call options for this service.CallOptions*CallOptions// LROClient is used internally to handle long-running operations.// It is exposed so that its CallOptions can be modified if required.// Users should not Close this client.LROClient*lroauto.OperationsClient// contains filtered or unexported fields}Client is a client for interacting with Cloud TPU API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
Manages TPU nodes and other resources
TPU API v1
func NewClient
NewClient creates a new tpu client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.
Manages TPU nodes and other resources
TPU API v1
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}func (*Client) CancelOperation
func(c*Client)CancelOperation(ctxcontext.Context,req*longrunningpb.CancelOperationRequest,opts...gax.CallOption)errorCancelOperation is a utility method from google.longrunning.Operations.
Example
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"tpu"cloud.google.com/go/tpu/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.CancelOperationRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.}err=c.CancelOperation(ctx,req)iferr!=nil{// TODO: Handle error.}}func (*Client) Close
Close closes the connection to the API service. The user should invoke this whenthe client is no longer required.
func (*Client) Connection (deprecated)
func(c*Client)Connection()*grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.
func (*Client) CreateNode
func(c*Client)CreateNode(ctxcontext.Context,req*tpupb.CreateNodeRequest,opts...gax.CallOption)(*CreateNodeOperation,error)CreateNode creates a node.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.CreateNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#CreateNodeRequest.}op,err:=c.CreateNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) CreateNodeOperation
func(c*Client)CreateNodeOperation(namestring)*CreateNodeOperationCreateNodeOperation returns a new CreateNodeOperation from a given name.The name must be that of a previously created CreateNodeOperation, possibly from a different process.
func (*Client) DeleteNode
func(c*Client)DeleteNode(ctxcontext.Context,req*tpupb.DeleteNodeRequest,opts...gax.CallOption)(*DeleteNodeOperation,error)DeleteNode deletes a node.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.DeleteNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#DeleteNodeRequest.}op,err:=c.DeleteNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) DeleteNodeOperation
func(c*Client)DeleteNodeOperation(namestring)*DeleteNodeOperationDeleteNodeOperation returns a new DeleteNodeOperation from a given name.The name must be that of a previously created DeleteNodeOperation, possibly from a different process.
func (*Client) DeleteOperation
func(c*Client)DeleteOperation(ctxcontext.Context,req*longrunningpb.DeleteOperationRequest,opts...gax.CallOption)errorDeleteOperation is a utility method from google.longrunning.Operations.
Example
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"tpu"cloud.google.com/go/tpu/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.DeleteOperationRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.}err=c.DeleteOperation(ctx,req)iferr!=nil{// TODO: Handle error.}}func (*Client) GetAcceleratorType
func(c*Client)GetAcceleratorType(ctxcontext.Context,req*tpupb.GetAcceleratorTypeRequest,opts...gax.CallOption)(*tpupb.AcceleratorType,error)GetAcceleratorType gets AcceleratorType.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.GetAcceleratorTypeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#GetAcceleratorTypeRequest.}resp,err:=c.GetAcceleratorType(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) GetLocation
func(c*Client)GetLocation(ctxcontext.Context,req*locationpb.GetLocationRequest,opts...gax.CallOption)(*locationpb.Location,error)GetLocation gets information about a location.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"locationpb"google.golang.org/genproto/googleapis/cloud/location")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&locationpb.GetLocationRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#GetLocationRequest.}resp,err:=c.GetLocation(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) GetNode
func(c*Client)GetNode(ctxcontext.Context,req*tpupb.GetNodeRequest,opts...gax.CallOption)(*tpupb.Node,error)GetNode gets the details of a node.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.GetNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#GetNodeRequest.}resp,err:=c.GetNode(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) GetOperation
func(c*Client)GetOperation(ctxcontext.Context,req*longrunningpb.GetOperationRequest,opts...gax.CallOption)(*longrunningpb.Operation,error)GetOperation is a utility method from google.longrunning.Operations.
Example
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"tpu"cloud.google.com/go/tpu/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.GetOperationRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.}resp,err:=c.GetOperation(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) GetTensorFlowVersion
func(c*Client)GetTensorFlowVersion(ctxcontext.Context,req*tpupb.GetTensorFlowVersionRequest,opts...gax.CallOption)(*tpupb.TensorFlowVersion,error)GetTensorFlowVersion gets TensorFlow Version.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.GetTensorFlowVersionRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#GetTensorFlowVersionRequest.}resp,err:=c.GetTensorFlowVersion(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) ListAcceleratorTypes
func(c*Client)ListAcceleratorTypes(ctxcontext.Context,req*tpupb.ListAcceleratorTypesRequest,opts...gax.CallOption)*AcceleratorTypeIteratorListAcceleratorTypes lists accelerator types supported by this API.
Examples
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb""google.golang.org/api/iterator")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListAcceleratorTypesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListAcceleratorTypesRequest.}it:=c.ListAcceleratorTypes(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*tpupb.ListAcceleratorTypesResponse)}}all
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListAcceleratorTypesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListAcceleratorTypesRequest.}forresp,err:=rangec.ListAcceleratorTypes(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}func (*Client) ListLocations
func(c*Client)ListLocations(ctxcontext.Context,req*locationpb.ListLocationsRequest,opts...gax.CallOption)*LocationIteratorListLocations lists information about the supported locations for this service.
Examples
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1""google.golang.org/api/iterator"locationpb"google.golang.org/genproto/googleapis/cloud/location")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&locationpb.ListLocationsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.}it:=c.ListLocations(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*locationpb.ListLocationsResponse)}}all
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"locationpb"google.golang.org/genproto/googleapis/cloud/location")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&locationpb.ListLocationsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/location#ListLocationsRequest.}forresp,err:=rangec.ListLocations(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}func (*Client) ListNodes
func(c*Client)ListNodes(ctxcontext.Context,req*tpupb.ListNodesRequest,opts...gax.CallOption)*NodeIteratorListNodes lists nodes.
Examples
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb""google.golang.org/api/iterator")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListNodesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListNodesRequest.}it:=c.ListNodes(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*tpupb.ListNodesResponse)}}all
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListNodesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListNodesRequest.}forresp,err:=rangec.ListNodes(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}func (*Client) ListOperations
func(c*Client)ListOperations(ctxcontext.Context,req*longrunningpb.ListOperationsRequest,opts...gax.CallOption)*OperationIteratorListOperations is a utility method from google.longrunning.Operations.
Examples
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"tpu"cloud.google.com/go/tpu/apiv1""google.golang.org/api/iterator")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.ListOperationsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.}it:=c.ListOperations(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*longrunningpb.ListOperationsResponse)}}all
packagemainimport("context"longrunningpb"cloud.google.com/go/longrunning/autogen/longrunningpb"tpu"cloud.google.com/go/tpu/apiv1")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&longrunningpb.ListOperationsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.}forresp,err:=rangec.ListOperations(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}func (*Client) ListTensorFlowVersions
func(c*Client)ListTensorFlowVersions(ctxcontext.Context,req*tpupb.ListTensorFlowVersionsRequest,opts...gax.CallOption)*TensorFlowVersionIteratorListTensorFlowVersions list TensorFlow versions supported by this API.
Examples
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb""google.golang.org/api/iterator")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListTensorFlowVersionsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListTensorFlowVersionsRequest.}it:=c.ListTensorFlowVersions(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*tpupb.ListTensorFlowVersionsResponse)}}all
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ListTensorFlowVersionsRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ListTensorFlowVersionsRequest.}forresp,err:=rangec.ListTensorFlowVersions(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}func (*Client) ReimageNode
func(c*Client)ReimageNode(ctxcontext.Context,req*tpupb.ReimageNodeRequest,opts...gax.CallOption)(*ReimageNodeOperation,error)ReimageNode reimages a node’s OS.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.ReimageNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#ReimageNodeRequest.}op,err:=c.ReimageNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) ReimageNodeOperation
func(c*Client)ReimageNodeOperation(namestring)*ReimageNodeOperationReimageNodeOperation returns a new ReimageNodeOperation from a given name.The name must be that of a previously created ReimageNodeOperation, possibly from a different process.
func (*Client) StartNode
func(c*Client)StartNode(ctxcontext.Context,req*tpupb.StartNodeRequest,opts...gax.CallOption)(*StartNodeOperation,error)StartNode starts a node.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.StartNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#StartNodeRequest.}op,err:=c.StartNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) StartNodeOperation
func(c*Client)StartNodeOperation(namestring)*StartNodeOperationStartNodeOperation returns a new StartNodeOperation from a given name.The name must be that of a previously created StartNodeOperation, possibly from a different process.
func (*Client) StopNode
func(c*Client)StopNode(ctxcontext.Context,req*tpupb.StopNodeRequest,opts...gax.CallOption)(*StopNodeOperation,error)StopNode stops a node, this operation is only available with single TPU nodes.
Example
packagemainimport("context"tpu"cloud.google.com/go/tpu/apiv1"tpupb"cloud.google.com/go/tpu/apiv1/tpupb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in:// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=tpu.NewClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&tpupb.StopNodeRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#StopNodeRequest.}op,err:=c.StopNode(ctx,req)iferr!=nil{// TODO: Handle error.}resp,err:=op.Wait(ctx)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}func (*Client) StopNodeOperation
func(c*Client)StopNodeOperation(namestring)*StopNodeOperationStopNodeOperation returns a new StopNodeOperation from a given name.The name must be that of a previously created StopNodeOperation, possibly from a different process.
CreateNodeOperation
typeCreateNodeOperationstruct{// contains filtered or unexported fields}CreateNodeOperation manages a long-running operation from CreateNode.
func (*CreateNodeOperation) Done
func(op*CreateNodeOperation)Done()boolDone reports whether the long-running operation has completed.
func (*CreateNodeOperation) Metadata
func(op*CreateNodeOperation)Metadata()(*tpupb.OperationMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*CreateNodeOperation) Name
func(op*CreateNodeOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*CreateNodeOperation) Poll
func(op*CreateNodeOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*CreateNodeOperation) Wait
func(op*CreateNodeOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
DeleteNodeOperation
typeDeleteNodeOperationstruct{// contains filtered or unexported fields}DeleteNodeOperation manages a long-running operation from DeleteNode.
func (*DeleteNodeOperation) Done
func(op*DeleteNodeOperation)Done()boolDone reports whether the long-running operation has completed.
func (*DeleteNodeOperation) Metadata
func(op*DeleteNodeOperation)Metadata()(*tpupb.OperationMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*DeleteNodeOperation) Name
func(op*DeleteNodeOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*DeleteNodeOperation) Poll
func(op*DeleteNodeOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*DeleteNodeOperation) Wait
func(op*DeleteNodeOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
LocationIterator
typeLocationIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*locationpb.Location,nextPageTokenstring,errerror)// contains filtered or unexported fields}LocationIterator manages a stream of *locationpb.Location.
func (*LocationIterator) All
func(it*LocationIterator)All()iter.Seq2[*locationpb.Location,error]All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.
func (*LocationIterator) Next
func(it*LocationIterator)Next()(*locationpb.Location,error)Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.
func (*LocationIterator) PageInfo
func(it*LocationIterator)PageInfo()*iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
NodeIterator
typeNodeIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*tpupb.Node,nextPageTokenstring,errerror)// contains filtered or unexported fields}NodeIterator manages a stream of *tpupb.Node.
func (*NodeIterator) All
func(it*NodeIterator)All()iter.Seq2[*tpupb.Node,error]All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.
func (*NodeIterator) Next
func(it*NodeIterator)Next()(*tpupb.Node,error)Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.
func (*NodeIterator) PageInfo
func(it*NodeIterator)PageInfo()*iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
OperationIterator
typeOperationIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*longrunningpb.Operation,nextPageTokenstring,errerror)// contains filtered or unexported fields}OperationIterator manages a stream of *longrunningpb.Operation.
func (*OperationIterator) All
func(it*OperationIterator)All()iter.Seq2[*longrunningpb.Operation,error]All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.
func (*OperationIterator) Next
func(it*OperationIterator)Next()(*longrunningpb.Operation,error)Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.
func (*OperationIterator) PageInfo
func(it*OperationIterator)PageInfo()*iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
ReimageNodeOperation
typeReimageNodeOperationstruct{// contains filtered or unexported fields}ReimageNodeOperation manages a long-running operation from ReimageNode.
func (*ReimageNodeOperation) Done
func(op*ReimageNodeOperation)Done()boolDone reports whether the long-running operation has completed.
func (*ReimageNodeOperation) Metadata
func(op*ReimageNodeOperation)Metadata()(*tpupb.OperationMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*ReimageNodeOperation) Name
func(op*ReimageNodeOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*ReimageNodeOperation) Poll
func(op*ReimageNodeOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*ReimageNodeOperation) Wait
func(op*ReimageNodeOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
StartNodeOperation
typeStartNodeOperationstruct{// contains filtered or unexported fields}StartNodeOperation manages a long-running operation from StartNode.
func (*StartNodeOperation) Done
func(op*StartNodeOperation)Done()boolDone reports whether the long-running operation has completed.
func (*StartNodeOperation) Metadata
func(op*StartNodeOperation)Metadata()(*tpupb.OperationMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*StartNodeOperation) Name
func(op*StartNodeOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*StartNodeOperation) Poll
func(op*StartNodeOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*StartNodeOperation) Wait
func(op*StartNodeOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
StopNodeOperation
typeStopNodeOperationstruct{// contains filtered or unexported fields}StopNodeOperation manages a long-running operation from StopNode.
func (*StopNodeOperation) Done
func(op*StopNodeOperation)Done()boolDone reports whether the long-running operation has completed.
func (*StopNodeOperation) Metadata
func(op*StopNodeOperation)Metadata()(*tpupb.OperationMetadata,error)Metadata returns metadata associated with the long-running operation.Metadata itself does not contact the server, but Poll does.To get the latest metadata, call this method after a successful call to Poll.If the metadata is not available, the returned metadata and error are both nil.
func (*StopNodeOperation) Name
func(op*StopNodeOperation)Name()stringName returns the name of the long-running operation.The name is assigned by the server and is unique within the service from which the operation is created.
func (*StopNodeOperation) Poll
func(op*StopNodeOperation)Poll(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds andthe operation has completed with failure, the error is returned and op.Done will return true.If Poll succeeds and the operation has completed successfully,op.Done will return true, and the response of the operation is returned.If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*StopNodeOperation) Wait
func(op*StopNodeOperation)Wait(ctxcontext.Context,opts...gax.CallOption)(*tpupb.Node,error)Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
TensorFlowVersionIterator
typeTensorFlowVersionIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*tpupb.TensorFlowVersion,nextPageTokenstring,errerror)// contains filtered or unexported fields}TensorFlowVersionIterator manages a stream of *tpupb.TensorFlowVersion.
func (*TensorFlowVersionIterator) All
func(it*TensorFlowVersionIterator)All()iter.Seq2[*tpupb.TensorFlowVersion,error]All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.
func (*TensorFlowVersionIterator) Next
func(it*TensorFlowVersionIterator)Next()(*tpupb.TensorFlowVersion,error)Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.
func (*TensorFlowVersionIterator) PageInfo
func(it*TensorFlowVersionIterator)PageInfo()*iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.