Skip to main content

Session

Struct Session 

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

The control API of one running MicroVM.

Implementations§

Source§

impl Session

Source

pub fn agent_token(&self) -> &str

The bearer this session authenticates with.

Public because a caller who launched with a minted token needs to read it back to reattach later (the Python oracle’s Session.agent_token property, and what the CLI’s run envelope publishes for microvm exec --agent-token). The value is still kept out of Debug — readable on purpose is different from printed by accident.

Source

pub async fn connect( endpoint: impl Into<String>, agent_token: impl Into<String>, minter: Arc<dyn TokenMinter>, ) -> Result<Session, Error>

A session against endpoint, minting proxy tokens through minter.

Does not talk to the VM. Constructing a session is free and re-doable, and a constructor that probed would make “do I have a session” mean “is the VM up”, which are different questions with different answers during a launch.

Source

pub fn direct( endpoint: impl Into<String>, agent_token: impl Into<String>, ) -> Result<Session, Error>

A session with no proxy auth, for a daemon reached directly.

The conformance path and every local-binary test go through here. See Transport::proxy on why this is a supported shape rather than a test-only escape hatch.

Source

pub fn builder( endpoint: impl Into<String>, agent_token: impl Into<String>, ) -> SessionBuilder

A builder, for the cases that need a port, a timeout, or a custom backend.

Source

pub fn endpoint(&self) -> &str

The endpoint this session addresses.

Source

pub fn port(&self) -> u16

The port the proxy token is scoped to.

Source

pub fn proxy_auth(&self) -> Option<&Arc<ProxyAuth>>

The proxy auth, for a caller that needs the mint count or an invalidation.

Source

pub async fn connect_headers( &self, port: u16, ) -> Result<Vec<(String, String)>, Error>

Both proxy headers for port, minted through this session’s token cache.

The {url, headers} half of a port-endpoint resolution: pair these with Self::endpoint and a caller can open its own connection with no knowledge of how the token is minted or when it refreshes.

Empty for a direct session, which is the correct answer rather than a missing one: a daemon reached directly takes no proxy headers, so an empty set is exactly what its requests carry today (see Transport::proxy).

The auth value is a bearer credential and this returns it. Nothing in this crate logs or stores the result.

Source

pub async fn connect_subprotocols( &self, port: u16, ) -> Result<Option<[String; 3]>, Error>

The three WebSocket subprotocols for port, minted through this session’s token cache.

None for a direct session, and that is deliberately not an empty list: the subprotocol form exists only because a request through the endpoint proxy cannot set headers, so there is nothing for a directly-reached daemon to offer, and a caller handed ["lambda-microvms"] with no token would open a handshake that is refused for a reason naming neither.

See ProxyAuth::subprotocols for the wire format and for the platform’s stripping behaviour. The middle value carries the credential.

Source

pub fn rebind(&mut self, endpoint: String)

Points the session at a new endpoint and drops the cached proxy token (STATE-8).

The measured behaviour is that the endpoint URL does not change across suspend/resume, so this is usually a no-op on the URL — but the token drop is not: a token minted against the pre-suspend instance may no longer validate, and that rejection reads exactly like a dead daemon.

Takes &mut self because it changes where the session points, which is not something a shared reference should be able to do mid-request. The invalidation itself is &self on ProxyAuth, so a resume path holding only the auth can still drop the token.

Source

pub async fn health(&self) -> Result<Health, Error>

Unauthenticated liveness. bootstrapped is the useful field.

Reachable through the endpoint at all implies bootstrapped in practice — the platform forwards no external traffic until the run hook returns 200 — but a caller inside the VM, or one talking to the daemon directly, can observe the pre-bootstrap state.

Source

pub async fn wait_until_ready(&self, timeout: Duration) -> Result<Health, Error>

Polls health until the daemon reports bootstrapped.

Connection errors are expected here rather than exceptional: a VM that has just reached RUNNING commonly refuses a connection or two before the proxy path is wired up, and a mint failure is retryable by construction. A fatal error ends the wait immediately — retrying a 401 until the deadline is one of the two mistakes the retryable split exists to prevent.

Source

pub async fn run(&self, req: StartRequest) -> Result<ExecHandle, Error>

Starts a command and returns its handle. Does not wait.

The exec_id on the request is the idempotency key. The daemon returns success for a known id without spawning a second child, so a caller whose retry must be safe across its own restart supplies a stable one.

Source

pub fn exec(&self, exec_id: impl Into<String>) -> ExecHandle

A handle for an exec started earlier, possibly by another process.

Source

pub async fn run_sync( &self, req: StartRequest, timeout: Duration, ) -> Result<ExecResult, Error>

Start, wait, ack. The one-shot shape, for when output is all you want.

Source

pub async fn kill(&self, exec_id: &str) -> Result<bool, Error>

Signals an exec’s whole process group. Returns whether anything was signalled.

Source

pub async fn upload_file( &self, path: &str, data: &[u8], mode: Option<&str>, ) -> Result<(), Error>

Writes one file, creating parents. mode is octal as a string.

Source

pub async fn download_file(&self, path: &str) -> Result<Vec<u8>, Error>

Reads one file.

Source

pub async fn file_exists(&self, path: &str) -> Result<bool, Error>

Whether a path exists, distinguishing absence from every other refusal.

Source

pub async fn upload_tar( &self, remote: &str, archive: &[u8], ) -> Result<(), Error>

Extracts pre-built tar bytes under remote.

Source

pub async fn download_tar(&self, remote: &str) -> Result<Vec<u8>, Error>

The raw tar bytes of a remote tree.

Trait Implementations§

Source§

impl Debug for Session

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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