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
impl Client
Sourcepub fn new(url: impl Into<String>, token: impl Into<String>) -> Result<Client>
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.
Sourcepub fn from_env() -> Result<Client>
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.
Sourcepub fn request(&self, query: &str, variables: Value) -> Result<Value>
pub fn request(&self, query: &str, variables: Value) -> Result<Value>
Run a raw query or mutation and return its data.
Sourcepub fn subscribe(
&self,
query: &str,
variables: Value,
on_next: impl FnMut(Value) + Send + 'static,
) -> Result<Subscription>
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.
Sourcepub 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>
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.
Sourcepub fn list(&self, all: bool) -> Result<Vec<SandboxInfo>>
pub fn list(&self, all: bool) -> Result<Vec<SandboxInfo>>
List machines. all includes exited ones.
Sourcepub fn get(&self, id: &str) -> Result<Option<SandboxInfo>>
pub fn get(&self, id: &str) -> Result<Option<SandboxInfo>>
Fetch one machine by id (a unique prefix) or name, or None.
pub fn stop(&self, id: &str) -> Result<CommandResult>
pub fn start(&self, id: &str) -> Result<CommandResult>
pub fn remove<S: AsRef<str>>( &self, ids: &[S], force: bool, ) -> Result<CommandResult>
Sourcepub fn update(
&self,
id: &str,
cpus: Option<u32>,
mem: Option<u32>,
) -> Result<CommandResult>
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.
Sourcepub fn commit(
&self,
id: &str,
name: &str,
description: &str,
) -> Result<CommandResult>
pub fn commit( &self, id: &str, name: &str, description: &str, ) -> Result<CommandResult>
Snapshot a machine into a named flavor, like docker commit.
Sourcepub fn logs(&self, id: &str, boot: bool) -> Result<String>
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).
Sourcepub fn follow_logs(&self, id: &str) -> FollowLogsBuilder
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()?;Sourcepub fn run_linux(&self) -> RunLinuxBuilder
pub fn run_linux(&self) -> RunLinuxBuilder
Boot a Linux machine on the daemon — runLinux.
Sourcepub fn run_bsd(&self, os: BsdOs) -> RunBsdBuilder
pub fn run_bsd(&self, os: BsdOs) -> RunBsdBuilder
Boot FreeBSD or NetBSD on the daemon — runBsd.
Sourcepub fn run_nanos(&self) -> RunNanosBuilder
pub fn run_nanos(&self) -> RunNanosBuilder
Boot a Nanos unikernel on the daemon — runNanos.
Sourcepub fn run_unikraft(&self) -> RunUnikraftBuilder
pub fn run_unikraft(&self) -> RunUnikraftBuilder
Boot a Unikraft unikernel on the daemon — runUnikraft.
Sourcepub fn run_solo5(&self) -> RunSolo5Builder
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.
Sourcepub fn run_osv(&self) -> RunOsvBuilder
pub fn run_osv(&self) -> RunOsvBuilder
Boot an OSv unikernel on the daemon — runOsv.
Sourcepub fn run_flavor(&self, name: impl Into<String>) -> RunFlavorBuilder
pub fn run_flavor(&self, name: impl Into<String>) -> RunFlavorBuilder
Boot a named flavor on the daemon — runFlavor.
Sourcepub fn exec<I, S>(&self, id: &str, command: I) -> Result<RemoteExecResult>
pub fn exec<I, S>(&self, id: &str, command: I) -> Result<RemoteExecResult>
Run a command to completion via the machine’s shell agent.
Sourcepub fn exec_with_env<I, S, E, T>(
&self,
id: &str,
command: I,
env: E,
) -> Result<RemoteExecResult>
pub fn exec_with_env<I, S, E, T>( &self, id: &str, command: I, env: E, ) -> Result<RemoteExecResult>
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.
Sourcepub fn shell(&self, id: &str) -> ShellBuilder
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")?;