use isoloom_manifest::{Machine, Native};
use super::Running;
use super::operation::Done;
use crate::Result;
use crate::error::Error;
use crate::events::{Emitter, Events};
use crate::executor::Cx;
use crate::options::RunOptions;
use crate::state::Op;
impl Running<'_> {
pub async fn retire(&self, machine: &str, opts: &RunOptions, events: &dyn Events) -> Result<()> {
self.operate(Op::Retire, opts, events, async |connected: &RunOptions, e: &Emitter<'_>| {
let target = self.machine_named(machine)?;
if self.manifest().guest.as_ref().is_some_and(|g| g.machine == target.name) {
return Err(Error::Unsupported {
what: format!("retiring `{machine}`, the VM the run's containers run in"),
});
}
let (_, cx) = self.existing(connected, e).await?;
self.take_out(&cx, target).await?;
Ok(Done {
value: (),
ok: true,
data: serde_json::json!({ "machine": machine }),
state: None,
})
})
.await
}
pub(crate) async fn take_out(&self, cx: &Cx<'_>, target: &Machine) -> Result<()> {
match (&self.manifest().guest, &target.native) {
(Some(guest), Some(Native::Compose { service })) => crate::in_vm::retire(cx, &self.driver, guest, service.as_str()).await,
_ => self.driver.retire(cx, target).await,
}
}
}