[go: up one dir, main page]

google-cloud-tpu-v2 0.3.0

Google Cloud Client Libraries for Rust - Cloud TPU API
Documentation
// Copyright 2025 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.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

use crate::Result;

/// Implements a client for the Cloud TPU API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_tpu_v2::client::Tpu;
/// let client = Tpu::builder().build().await?;
/// // use `client` to make requests to the Cloud TPU API.
/// # gax::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Manages TPU nodes and other resources
///
/// TPU API v2
///
/// # Configuration
///
/// To configure `Tpu` use the `with_*` methods in the type returned
/// by [builder()][Tpu::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://tpu.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::tpu::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::tpu::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `Tpu` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `Tpu` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct Tpu {
    inner: std::sync::Arc<dyn super::stub::dynamic::Tpu>,
}

impl Tpu {
    /// Returns a builder for [Tpu].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_tpu_v2::client::Tpu;
    /// let client = Tpu::builder().build().await?;
    /// # gax::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::tpu::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::tpu::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::Tpu + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> Result<std::sync::Arc<dyn super::stub::dynamic::Tpu>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(conf: gaxi::options::ClientConfig) -> Result<impl super::stub::Tpu> {
        super::transport::Tpu::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> Result<impl super::stub::Tpu> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::Tpu::new)
    }

    /// Lists nodes.
    pub fn list_nodes(&self) -> super::builder::tpu::ListNodes {
        super::builder::tpu::ListNodes::new(self.inner.clone())
    }

    /// Gets the details of a node.
    pub fn get_node(&self) -> super::builder::tpu::GetNode {
        super::builder::tpu::GetNode::new(self.inner.clone())
    }

    /// Creates a node.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_node(&self) -> super::builder::tpu::CreateNode {
        super::builder::tpu::CreateNode::new(self.inner.clone())
    }

    /// Deletes a node.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_node(&self) -> super::builder::tpu::DeleteNode {
        super::builder::tpu::DeleteNode::new(self.inner.clone())
    }

    /// Stops a node. This operation is only available with single TPU nodes.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn stop_node(&self) -> super::builder::tpu::StopNode {
        super::builder::tpu::StopNode::new(self.inner.clone())
    }

    /// Starts a node.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn start_node(&self) -> super::builder::tpu::StartNode {
        super::builder::tpu::StartNode::new(self.inner.clone())
    }

    /// Updates the configurations of a node.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn update_node(&self) -> super::builder::tpu::UpdateNode {
        super::builder::tpu::UpdateNode::new(self.inner.clone())
    }

    /// Lists queued resources.
    pub fn list_queued_resources(&self) -> super::builder::tpu::ListQueuedResources {
        super::builder::tpu::ListQueuedResources::new(self.inner.clone())
    }

    /// Gets details of a queued resource.
    pub fn get_queued_resource(&self) -> super::builder::tpu::GetQueuedResource {
        super::builder::tpu::GetQueuedResource::new(self.inner.clone())
    }

    /// Creates a QueuedResource TPU instance.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn create_queued_resource(&self) -> super::builder::tpu::CreateQueuedResource {
        super::builder::tpu::CreateQueuedResource::new(self.inner.clone())
    }

    /// Deletes a QueuedResource TPU instance.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_queued_resource(&self) -> super::builder::tpu::DeleteQueuedResource {
        super::builder::tpu::DeleteQueuedResource::new(self.inner.clone())
    }

    /// Resets a QueuedResource TPU instance
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn reset_queued_resource(&self) -> super::builder::tpu::ResetQueuedResource {
        super::builder::tpu::ResetQueuedResource::new(self.inner.clone())
    }

    /// Generates the Cloud TPU service identity for the project.
    pub fn generate_service_identity(&self) -> super::builder::tpu::GenerateServiceIdentity {
        super::builder::tpu::GenerateServiceIdentity::new(self.inner.clone())
    }

    /// Lists accelerator types supported by this API.
    pub fn list_accelerator_types(&self) -> super::builder::tpu::ListAcceleratorTypes {
        super::builder::tpu::ListAcceleratorTypes::new(self.inner.clone())
    }

    /// Gets AcceleratorType.
    pub fn get_accelerator_type(&self) -> super::builder::tpu::GetAcceleratorType {
        super::builder::tpu::GetAcceleratorType::new(self.inner.clone())
    }

    /// Lists runtime versions supported by this API.
    pub fn list_runtime_versions(&self) -> super::builder::tpu::ListRuntimeVersions {
        super::builder::tpu::ListRuntimeVersions::new(self.inner.clone())
    }

    /// Gets a runtime version.
    pub fn get_runtime_version(&self) -> super::builder::tpu::GetRuntimeVersion {
        super::builder::tpu::GetRuntimeVersion::new(self.inner.clone())
    }

    /// Retrieves the guest attributes for the node.
    pub fn get_guest_attributes(&self) -> super::builder::tpu::GetGuestAttributes {
        super::builder::tpu::GetGuestAttributes::new(self.inner.clone())
    }

    /// Lists information about the supported locations for this service.
    pub fn list_locations(&self) -> super::builder::tpu::ListLocations {
        super::builder::tpu::ListLocations::new(self.inner.clone())
    }

    /// Gets information about a location.
    pub fn get_location(&self) -> super::builder::tpu::GetLocation {
        super::builder::tpu::GetLocation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::tpu::ListOperations {
        super::builder::tpu::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::tpu::GetOperation {
        super::builder::tpu::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn delete_operation(&self) -> super::builder::tpu::DeleteOperation {
        super::builder::tpu::DeleteOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::tpu::CancelOperation {
        super::builder::tpu::CancelOperation::new(self.inner.clone())
    }
}