@@ -15,6 +15,7 @@ use ostree_ext::sysroot::SysrootLock;
15
15
16
16
use crate :: cli:: OutputFormat ;
17
17
use crate :: deploy:: ImageState ;
18
+ use crate :: podman;
18
19
use crate :: spec:: {
19
20
Backend , BootEntry , BootOrder , Host , HostSpec , HostStatus , HostType , ImageStatus ,
20
21
} ;
@@ -154,7 +155,7 @@ pub(crate) fn create_imagestatus(
154
155
155
156
/// Given an OSTree deployment, parse out metadata into our spec.
156
157
#[ context( "Reading deployment metadata" ) ]
157
- fn boot_entry_from_deployment (
158
+ async fn boot_entry_from_deployment (
158
159
sysroot : & SysrootLock ,
159
160
deployment : & ostree:: Deployment ,
160
161
) -> Result < BootEntry > {
@@ -171,7 +172,11 @@ fn boot_entry_from_deployment(
171
172
let csum = deployment. csum ( ) ;
172
173
let imgstate = match backend {
173
174
Backend :: Container => {
174
- todo ! ( )
175
+ // TODO: encapsulate this better
176
+ let rootfs = & cap_std_ext:: cap_std:: fs:: Dir :: reopen_dir (
177
+ & crate :: utils:: sysroot_fd_borrowed ( sysroot) ,
178
+ ) ?;
179
+ ImageState :: from ( podman:: podman_inspect ( rootfs, & image. image ) . await ?)
175
180
}
176
181
Backend :: OstreeContainer => {
177
182
ImageState :: from ( * ostree_container:: store:: query_image_commit ( repo, & csum) ?)
@@ -233,18 +238,18 @@ impl BootEntry {
233
238
}
234
239
235
240
/// A variant of [`get_status`] that requires a booted deployment.
236
- pub ( crate ) fn get_status_require_booted (
241
+ pub ( crate ) async fn get_status_require_booted (
237
242
sysroot : & SysrootLock ,
238
243
) -> Result < ( ostree:: Deployment , Deployments , Host ) > {
239
244
let booted_deployment = sysroot. require_booted_deployment ( ) ?;
240
- let ( deployments, host) = get_status ( sysroot, Some ( & booted_deployment) ) ?;
245
+ let ( deployments, host) = get_status ( sysroot, Some ( & booted_deployment) ) . await ?;
241
246
Ok ( ( booted_deployment, deployments, host) )
242
247
}
243
248
244
249
/// Gather the ostree deployment objects, but also extract metadata from them into
245
250
/// a more native Rust structure.
246
251
#[ context( "Computing status" ) ]
247
- pub ( crate ) fn get_status (
252
+ pub ( crate ) async fn get_status (
248
253
sysroot : & SysrootLock ,
249
254
booted_deployment : Option < & ostree:: Deployment > ,
250
255
) -> Result < ( Deployments , Host ) > {
@@ -283,23 +288,36 @@ pub(crate) fn get_status(
283
288
other,
284
289
} ;
285
290
286
- let staged = deployments
287
- . staged
288
- . as_ref ( )
289
- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
290
- . transpose ( )
291
- . context ( "Staged deployment" ) ?;
292
- let booted = booted_deployment
293
- . as_ref ( )
294
- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
295
- . transpose ( )
296
- . context ( "Booted deployment" ) ?;
297
- let rollback = deployments
298
- . rollback
299
- . as_ref ( )
300
- . map ( |d| boot_entry_from_deployment ( sysroot, d) )
301
- . transpose ( )
302
- . context ( "Rollback deployment" ) ?;
291
+ let staged = if let Some ( d) = deployments. staged . as_ref ( ) {
292
+ Some (
293
+ boot_entry_from_deployment ( sysroot, d)
294
+ . await
295
+ . context ( "Staged deployment" ) ?,
296
+ )
297
+ } else {
298
+ None
299
+ } ;
300
+
301
+ let booted = if let Some ( d) = booted_deployment {
302
+ Some (
303
+ boot_entry_from_deployment ( sysroot, d)
304
+ . await
305
+ . context ( "Booted deployment" ) ?,
306
+ )
307
+ } else {
308
+ None
309
+ } ;
310
+
311
+ let rollback = if let Some ( d) = deployments. rollback . as_ref ( ) {
312
+ Some (
313
+ boot_entry_from_deployment ( sysroot, d)
314
+ . await
315
+ . context ( "Rollback deployment" ) ?,
316
+ )
317
+ } else {
318
+ None
319
+ } ;
320
+
303
321
let spec = staged
304
322
. as_ref ( )
305
323
. or ( booted. as_ref ( ) )
@@ -347,7 +365,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
347
365
} else {
348
366
let sysroot = super :: cli:: get_locked_sysroot ( ) . await ?;
349
367
let booted_deployment = sysroot. booted_deployment ( ) ;
350
- let ( _deployments, host) = get_status ( & sysroot, booted_deployment. as_ref ( ) ) ?;
368
+ let ( _deployments, host) = get_status ( & sysroot, booted_deployment. as_ref ( ) ) . await ?;
351
369
host
352
370
} ;
353
371
0 commit comments