Skip to main content

TalosClient

Struct TalosClient 

Source
pub struct TalosClient { /* private fields */ }

Implementations§

Source§

impl TalosClient

Source

pub async fn new(config: TalosClientConfig) -> Result<Self>

Source

pub async fn from_talosconfig( config: &TalosConfig, context_name: Option<&str>, ) -> Result<Self>

Create a client from a TalosConfig context

This loads credentials from the talosconfig and connects to the first endpoint.

§Example
use talos_api_rs::{TalosClient, config::TalosConfig};

let config = TalosConfig::load_with_env()?;
let client = TalosClient::from_talosconfig(&config, None).await?;
§Arguments
  • config - The loaded TalosConfig
  • context_name - Optional context name to use (defaults to active context)
Source

pub fn with_node(&self, target: NodeTarget) -> Self

Create a new client targeting a specific node

§Example
use talos_api_rs::{TalosClient, TalosClientConfig};
use talos_api_rs::client::NodeTarget;

let client = TalosClient::new(TalosClientConfig::default()).await?;

// Target a specific node for API calls
let targeted = client.with_node(NodeTarget::single("192.168.1.10"));
let hostname = targeted.hostname().await?;
Source

pub fn with_nodes( &self, nodes: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Create a new client targeting multiple nodes

Convenience method for cluster-wide operations.

Source

pub fn node_target(&self) -> &NodeTarget

Get the current node target

Source

pub fn version(&self) -> VersionServiceClient<Channel>

Access the Version API group

Source

pub fn machine(&self) -> MachineServiceClient<Channel>

Access the Machine API group

Source

pub async fn apply_configuration( &self, request: ApplyConfigurationRequest, ) -> Result<ApplyConfigurationResponse>

Apply a configuration to the node.

This is a high-level wrapper around the MachineService::ApplyConfiguration RPC.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, ApplyConfigurationRequest, ApplyMode};

let client = TalosClient::new(TalosClientConfig {
    endpoint: "https://192.168.1.100:50000".to_string(),
    insecure: true,
    ..Default::default()
}).await?;

// Apply configuration in dry-run mode
let request = ApplyConfigurationRequest::builder()
    .config_yaml("machine:\n  type: worker")
    .mode(ApplyMode::NoReboot)
    .dry_run(true)
    .build();

let response = client.apply_configuration(request).await?;
println!("Warnings: {:?}", response.all_warnings());
§Errors

Returns an error if the RPC call fails or the configuration is invalid.

Source

pub async fn apply_configuration_yaml( &self, yaml: &str, mode: ApplyMode, dry_run: bool, ) -> Result<ApplyConfigurationResponse>

Apply a YAML configuration string to the node.

Convenience method for simple configuration application.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, ApplyMode};

let client = TalosClient::new(TalosClientConfig::default()).await?;
let config_yaml = std::fs::read_to_string("machine.yaml")?;
let response = client.apply_configuration_yaml(&config_yaml, ApplyMode::Auto, false).await?;
Source

pub async fn bootstrap( &self, request: BootstrapRequest, ) -> Result<BootstrapResponse>

Bootstrap the etcd cluster on this node.

This initializes a new etcd cluster. This should only be called ONCE on the first control-plane node when creating a new Talos cluster.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, BootstrapRequest};

let client = TalosClient::new(TalosClientConfig::default()).await?;

// Bootstrap a new cluster
let response = client.bootstrap(BootstrapRequest::new()).await?;
println!("Bootstrap complete: {:?}", response.first());
§Recovery

To recover from an etcd snapshot (uploaded via EtcdRecover RPC):

use talos_api_rs::{TalosClient, TalosClientConfig, BootstrapRequest};

let client = TalosClient::new(TalosClientConfig::default()).await?;
let response = client.bootstrap(BootstrapRequest::recovery()).await?;
§Errors

Returns an error if:

  • The node is not a control-plane node
  • etcd is already bootstrapped
  • Network/connection issues
Source

pub async fn bootstrap_cluster(&self) -> Result<BootstrapResponse>

Bootstrap a new etcd cluster (convenience method).

Equivalent to bootstrap(BootstrapRequest::new()).

Source

pub async fn kubeconfig(&self) -> Result<KubeconfigResponse>

Retrieve the kubeconfig from the cluster.

This is a server-streaming RPC that retrieves the kubeconfig file from a control-plane node. The kubeconfig can be used to access the Kubernetes API of the cluster.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig};

let client = TalosClient::new(TalosClientConfig::default()).await?;

// Get kubeconfig
let kubeconfig = client.kubeconfig().await?;
println!("Kubeconfig from node: {:?}", kubeconfig.node);

// Write to file
kubeconfig.write_to_file("kubeconfig.yaml")?;

// Or get as string
let yaml = kubeconfig.as_str()?;
println!("{}", yaml);
§Errors

Returns an error if:

  • The node is not a control-plane node
  • The cluster is not yet bootstrapped
  • Network/connection issues
Source

pub async fn reset(&self, request: ResetRequest) -> Result<ResetResponse>

Reset a Talos node, optionally wiping disks.

§Warning

This is a destructive operation. The node will be reset and may lose all data depending on the wipe mode configured.

§Arguments
  • request - The reset request configuration
§Example
use talos_api_rs::{TalosClient, TalosClientConfig, ResetRequest};

let config = TalosClientConfig::new("https://192.168.1.100:50000".parse()?);
let client = TalosClient::new(config).await?;

// Graceful reset (leaves etcd cluster first)
let response = client.reset(ResetRequest::graceful()).await?;

// Force reset with full disk wipe
let response = client.reset(ResetRequest::force()).await?;

// Custom reset
let response = client.reset(
    ResetRequest::builder()
        .graceful(true)
        .reboot(true)
        .build()
).await?;
Source

pub async fn reset_graceful(&self) -> Result<ResetResponse>

Gracefully reset a Talos node.

This is a convenience method that performs a graceful reset, which:

  • Leaves the etcd cluster gracefully (for control plane nodes)
  • Reboots after reset
  • Does not wipe disks

For more control, use reset with a custom ResetRequest.

Source

pub async fn etcd_member_list( &self, request: EtcdMemberListRequest, ) -> Result<EtcdMemberListResponse>

List etcd cluster members.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, EtcdMemberListRequest};

let config = TalosClientConfig::new("https://192.168.1.100:50000".parse()?);
let client = TalosClient::new(config).await?;

let response = client.etcd_member_list(EtcdMemberListRequest::new()).await?;
for member in response.all_members() {
    println!("{}: {}", member.id, member.hostname);
}
Source

pub async fn etcd_remove_member_by_id( &self, request: EtcdRemoveMemberByIdRequest, ) -> Result<EtcdRemoveMemberByIdResponse>

Remove an etcd member by ID.

Use this to remove members that no longer have an associated Talos node. For nodes that are still running, use etcd_leave_cluster.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, EtcdRemoveMemberByIdRequest};

let config = TalosClientConfig::new("https://192.168.1.100:50000".parse()?);
let client = TalosClient::new(config).await?;

// First, find the member ID
let members = client.etcd_member_list(Default::default()).await?;
if let Some(member) = members.find_by_hostname("old-node") {
    client.etcd_remove_member_by_id(
        EtcdRemoveMemberByIdRequest::new(member.id)
    ).await?;
}
Source

pub async fn etcd_leave_cluster( &self, request: EtcdLeaveClusterRequest, ) -> Result<EtcdLeaveClusterResponse>

Make a node leave the etcd cluster gracefully.

This should be called on the node that is being removed.

Source

pub async fn etcd_forfeit_leadership( &self, request: EtcdForfeitLeadershipRequest, ) -> Result<EtcdForfeitLeadershipResponse>

Forfeit etcd leadership.

Causes the current leader to step down and trigger a new election.

Source

pub async fn etcd_status(&self) -> Result<EtcdStatusResponse>

Get etcd status for the current member.

Source

pub async fn etcd_alarm_list(&self) -> Result<EtcdAlarmListResponse>

List etcd alarms.

Source

pub async fn etcd_alarm_disarm(&self) -> Result<EtcdAlarmDisarmResponse>

Disarm etcd alarms.

Source

pub async fn etcd_defragment(&self) -> Result<EtcdDefragmentResponse>

Defragment etcd storage.

Warning: This is a resource-heavy operation.

Source

pub async fn dmesg(&self, request: DmesgRequest) -> Result<DmesgResponse>

Get kernel message buffer (dmesg).

This is a server-streaming RPC that returns kernel messages.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, DmesgRequest};

let config = TalosClientConfig::new("https://192.168.1.100:50000".parse()?);
let client = TalosClient::new(config).await?;

let dmesg = client.dmesg(DmesgRequest::new()).await?;
println!("{}", dmesg.as_string_lossy());
Source

pub async fn upgrade(&self, request: UpgradeRequest) -> Result<UpgradeResponse>

Upgrade a Talos node to a new version.

§Example
use talos_api_rs::{TalosClient, TalosClientConfig, UpgradeRequest};

let config = TalosClientConfig::new("https://192.168.1.100:50000".parse()?);
let client = TalosClient::new(config).await?;

// Upgrade to a specific version
let response = client.upgrade(
    UpgradeRequest::new("ghcr.io/siderolabs/installer:v1.6.0")
).await?;

// Staged upgrade (downloads but doesn't apply until reboot)
let response = client.upgrade(
    UpgradeRequest::builder("ghcr.io/siderolabs/installer:v1.6.0")
        .stage(true)
        .preserve(true)
        .build()
).await?;
Source

pub async fn service_start( &self, request: ServiceStartRequest, ) -> Result<ServiceStartResponse>

Start a service.

Source

pub async fn service_stop( &self, request: ServiceStopRequest, ) -> Result<ServiceStopResponse>

Stop a service.

Source

pub async fn service_restart( &self, request: ServiceRestartRequest, ) -> Result<ServiceRestartResponse>

Restart a service.

Source

pub async fn logs(&self, request: LogsRequest) -> Result<LogsResponse>

Get service/container logs (server-streaming).

Source

pub async fn load_avg(&self) -> Result<LoadAvgResponse>

Get system load averages.

Source

pub async fn memory(&self) -> Result<MemoryResponse>

Get memory information.

Source

pub async fn cpu_info(&self) -> Result<CpuInfoResponse>

Get CPU information.

Source

pub async fn disk_stats(&self) -> Result<DiskStatsResponse>

Get disk statistics.

Source

pub async fn network_device_stats(&self) -> Result<NetworkDeviceStatsResponse>

Get network device statistics.

Source

pub async fn mounts(&self) -> Result<MountsResponse>

Get mount points.

Source

pub async fn processes(&self) -> Result<ProcessesResponse>

Get process list.

Source

pub async fn list(&self, request: ListRequest) -> Result<ListResponse>

List directory contents (server-streaming).

Source

pub async fn read(&self, request: ReadRequest) -> Result<ReadResponse>

Read a file (server-streaming).

Source

pub async fn copy(&self, request: CopyRequest) -> Result<CopyResponse>

Copy a file or directory as tar archive (server-streaming).

Source

pub async fn disk_usage( &self, request: DiskUsageRequest, ) -> Result<DiskUsageResponse>

Get disk usage (server-streaming).

Source

pub async fn rollback(&self) -> Result<RollbackResponse>

Rollback a Talos node to the previous installed version.

Source

pub async fn generate_client_configuration( &self, request: GenerateClientConfigurationRequest, ) -> Result<GenerateClientConfigurationResponse>

Generate client configuration (talosconfig).

Source

pub async fn packet_capture( &self, request: PacketCaptureRequest, ) -> Result<PacketCaptureResponse>

Capture packets on a network interface (server-streaming).

Source

pub async fn netstat(&self, request: NetstatRequest) -> Result<NetstatResponse>

Get network connection information (netstat).

Source

pub async fn image_list( &self, request: ImageListRequest, ) -> Result<Vec<ImageInfo>>

List container images in the specified containerd namespace.

Returns a list of images from the node’s containerd registry.

§Arguments
  • request - The image list request specifying the namespace to query.
§Example
let config = TalosClientConfig::new("https://192.168.1.100:50000");
let client = TalosClient::new(config).await?;

// List all system images
let images = client.image_list(ImageListRequest::system()).await?;
for image in images {
    println!("{}: {}", image.name, image.size_human());
}

// List Kubernetes images
let cri_images = client.image_list(ImageListRequest::cri()).await?;
Source

pub async fn image_pull( &self, request: ImagePullRequest, ) -> Result<ImagePullResponse>

Pull a container image into the node’s containerd registry.

Downloads and stores the specified image so it’s available locally.

§Arguments
  • request - The image pull request specifying the image reference and namespace.
§Example
let config = TalosClientConfig::new("https://192.168.1.100:50000");
let client = TalosClient::new(config).await?;

// Pull a specific image
let response = client.image_pull(
    ImagePullRequest::new("docker.io/library/nginx:latest")
).await?;
println!("Pulled images: {:?}", response.results);

Trait Implementations§

Source§

impl Clone for TalosClient

Source§

fn clone(&self) -> TalosClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more