Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A client for a remote bsdkrund’s GraphQL API.

Queries and mutations go over HTTP; subscriptions (used internally by Client::exec, Client::shell and Client::follow_logs) share one lazily opened graphql-transport-ws socket per client, torn down once the last subscription ends. Cloning is cheap and shares that socket.

Implementations§

Source§

impl Client

Source

pub fn new(url: impl Into<String>, token: impl Into<String>) -> Result<Client>

Build a client from a daemon URL and its bearer token.

A URL configured without a token is refused rather than silently making an unauthenticated request — the daemon has no anonymous tier.

Source

pub fn from_env() -> Result<Client>

Build a client from BSDKRUN_URL / BSDKRUN_TOKEN.

Errors if BSDKRUN_URL is unset (nothing to connect to), or if it is set but BSDKRUN_TOKEN is not — a host configured without a token is a configuration error, never a silent fall-back to an unauthenticated request.

Source

pub fn url(&self) -> &str

The normalized GraphQL endpoint URL.

Source

pub fn request(&self, query: &str, variables: Value) -> Result<Value>

Run a raw query or mutation and return its data.

Source

pub fn subscribe( &self, query: &str, variables: Value, on_next: impl FnMut(Value) + Send + 'static, ) -> Result<Subscription>

Start a raw subscription; each next payload’s data goes to on_next. Returns a Subscription handle to end it with.

Source

pub fn subscribe_with( &self, query: &str, variables: Value, on_next: impl FnMut(Value) + Send + 'static, on_error: impl FnMut(Error) + Send + 'static, on_complete: impl FnMut() + Send + 'static, ) -> Result<Subscription>

Client::subscribe with error/completion callbacks.

Source

pub fn list(&self, all: bool) -> Result<Vec<SandboxInfo>>

List machines. all includes exited ones.

Source

pub fn get(&self, id: &str) -> Result<Option<SandboxInfo>>

Fetch one machine by id (a unique prefix) or name, or None.

Source

pub fn stop(&self, id: &str) -> Result<CommandResult>

Source

pub fn start(&self, id: &str) -> Result<CommandResult>

Source

pub fn remove<S: AsRef<str>>( &self, ids: &[S], force: bool, ) -> Result<CommandResult>

Source

pub fn update( &self, id: &str, cpus: Option<u32>, mem: Option<u32>, ) -> Result<CommandResult>

Change a machine’s recorded vCPU / memory; applies on its next start.

Source

pub fn commit( &self, id: &str, name: &str, description: &str, ) -> Result<CommandResult>

Snapshot a machine into a named flavor, like docker commit.

Source

pub fn logs(&self, id: &str, boot: bool) -> Result<String>

One-shot read of a machine’s console log (bsdkrun’s boot log with boot).

Source

pub fn follow_logs(&self, id: &str) -> FollowLogsBuilder

Stream a machine’s console log live.

let sub = client
    .follow_logs("abc123")
    .on_data(|bytes| print!("{}", String::from_utf8_lossy(&bytes)))
    .start()?;
Source

pub fn run_linux(&self) -> RunLinuxBuilder

Boot a Linux machine on the daemon — runLinux.

Source

pub fn run_bsd(&self, os: BsdOs) -> RunBsdBuilder

Boot FreeBSD or NetBSD on the daemon — runBsd.

Source

pub fn run_nanos(&self) -> RunNanosBuilder

Boot a Nanos unikernel on the daemon — runNanos.

Source

pub fn run_unikraft(&self) -> RunUnikraftBuilder

Boot a Unikraft unikernel on the daemon — runUnikraft.

Source

pub fn run_solo5(&self) -> RunSolo5Builder

Boot a Solo5 (MirageOS) unikernel on the daemon — runSolo5. Runs under the solo5-hvt tender rather than libkrun; the unikernel declares its own devices in its MFT1 manifest, so only block backings and its own args are passed.

Source

pub fn run_osv(&self) -> RunOsvBuilder

Boot an OSv unikernel on the daemon — runOsv.

Source

pub fn run_flavor(&self, name: impl Into<String>) -> RunFlavorBuilder

Boot a named flavor on the daemon — runFlavor.

Source

pub fn exec<I, S>(&self, id: &str, command: I) -> Result<RemoteExecResult>
where I: IntoIterator<Item = S>, S: Into<String>,

Run a command to completion via the machine’s shell agent.

Source

pub fn exec_with_env<I, S, E, T>( &self, id: &str, command: I, env: E, ) -> Result<RemoteExecResult>
where I: IntoIterator<Item = S>, S: Into<String>, E: IntoIterator<Item = T>, T: Into<String>,

Client::exec with per-command "K=V" environment entries.

Sequenced exactly as daemon/README.md describes: openShell (with command set, so the session runs it instead of a login shell), THEN subscribe to shellOutput (output is buffered from the moment the session opened, so nothing is lost even though the subscribe necessarily happens after the mutation), collecting bytes until an event carries a non-null exit code, THEN closeShell — called unconditionally, including on error, since it is idempotent and a session must never be left dangling.

Source

pub fn shell(&self, id: &str) -> ShellBuilder

Open a live interactive session — output/exit arrive via callbacks.

let session = client.shell("abc123").rows(50).cols(120).open()?;
session.on_output(|bytes| print!("{}", String::from_utf8_lossy(bytes)));
session.on_exit(|code| println!("exited {code}"));
session.write("ls -la\n")?;

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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