11use std:: collections:: VecDeque ;
22
33use crate :: deploy:: ImageState ;
4+ use crate :: podman;
45use crate :: spec:: {
56 Backend , BootEntry , BootOrder , Host , HostSpec , HostStatus , HostType , ImageStatus ,
67} ;
@@ -152,7 +153,7 @@ pub(crate) fn create_imagestatus(
152153
153154/// Given an OSTree deployment, parse out metadata into our spec.
154155#[ context( "Reading deployment metadata" ) ]
155- fn boot_entry_from_deployment (
156+ async fn boot_entry_from_deployment (
156157 sysroot : & SysrootLock ,
157158 deployment : & ostree:: Deployment ,
158159) -> Result < BootEntry > {
@@ -169,7 +170,11 @@ fn boot_entry_from_deployment(
169170 let csum = deployment. csum ( ) ;
170171 let imgstate = match backend {
171172 Backend :: Container => {
172- todo ! ( )
173+ // TODO: encapsulate this better
174+ let rootfs = & cap_std_ext:: cap_std:: fs:: Dir :: reopen_dir (
175+ & crate :: utils:: sysroot_fd_borrowed ( sysroot) ,
176+ ) ?;
177+ ImageState :: from ( podman:: podman_inspect ( rootfs, & image. image ) . await ?)
173178 }
174179 Backend :: OstreeContainer => {
175180 ImageState :: from ( * ostree_container:: store:: query_image_commit ( repo, & csum) ?)
@@ -231,18 +236,18 @@ impl BootEntry {
231236}
232237
233238/// A variant of [`get_status`] that requires a booted deployment.
234- pub ( crate ) fn get_status_require_booted (
239+ pub ( crate ) async fn get_status_require_booted (
235240 sysroot : & SysrootLock ,
236241) -> Result < ( ostree:: Deployment , Deployments , Host ) > {
237242 let booted_deployment = sysroot. require_booted_deployment ( ) ?;
238- let ( deployments, host) = get_status ( sysroot, Some ( & booted_deployment) ) ?;
243+ let ( deployments, host) = get_status ( sysroot, Some ( & booted_deployment) ) . await ?;
239244 Ok ( ( booted_deployment, deployments, host) )
240245}
241246
242247/// Gather the ostree deployment objects, but also extract metadata from them into
243248/// a more native Rust structure.
244249#[ context( "Computing status" ) ]
245- pub ( crate ) fn get_status (
250+ pub ( crate ) async fn get_status (
246251 sysroot : & SysrootLock ,
247252 booted_deployment : Option < & ostree:: Deployment > ,
248253) -> Result < ( Deployments , Host ) > {
@@ -281,23 +286,36 @@ pub(crate) fn get_status(
281286 other,
282287 } ;
283288
284- let staged = deployments
285- . staged
286- . as_ref ( )
287- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
288- . transpose ( )
289- . context ( "Staged deployment" ) ?;
290- let booted = booted_deployment
291- . as_ref ( )
292- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
293- . transpose ( )
294- . context ( "Booted deployment" ) ?;
295- let rollback = deployments
296- . rollback
297- . as_ref ( )
298- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
299- . transpose ( )
300- . context ( "Rollback deployment" ) ?;
289+ let staged = if let Some ( d) = deployments. staged . as_ref ( ) {
290+ Some (
291+ boot_entry_from_deployment ( sysroot, d)
292+ . await
293+ . context ( "Staged deployment" ) ?,
294+ )
295+ } else {
296+ None
297+ } ;
298+
299+ let booted = if let Some ( d) = booted_deployment {
300+ Some (
301+ boot_entry_from_deployment ( sysroot, d)
302+ . await
303+ . context ( "Booted deployment" ) ?,
304+ )
305+ } else {
306+ None
307+ } ;
308+
309+ let rollback = if let Some ( d) = deployments. rollback . as_ref ( ) {
310+ Some (
311+ boot_entry_from_deployment ( sysroot, d)
312+ . await
313+ . context ( "Rollback deployment" ) ?,
314+ )
315+ } else {
316+ None
317+ } ;
318+
301319 let spec = staged
302320 . as_ref ( )
303321 . or ( booted. as_ref ( ) )
@@ -346,7 +364,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
346364 crate :: cli:: prepare_for_write ( ) . await ?;
347365 let sysroot = super :: cli:: get_locked_sysroot ( ) . await ?;
348366 let booted_deployment = sysroot. booted_deployment ( ) ;
349- let ( _deployments, host) = get_status ( & sysroot, booted_deployment. as_ref ( ) ) ?;
367+ let ( _deployments, host) = get_status ( & sysroot, booted_deployment. as_ref ( ) ) . await ?;
350368 host
351369 } ;
352370
0 commit comments