1
1
use std:: collections:: VecDeque ;
2
2
3
3
use crate :: deploy:: ImageState ;
4
+ use crate :: podman;
4
5
use crate :: spec:: {
5
6
Backend , BootEntry , BootOrder , Host , HostSpec , HostStatus , HostType , ImageStatus ,
6
7
} ;
@@ -152,7 +153,7 @@ pub(crate) fn create_imagestatus(
152
153
153
154
/// Given an OSTree deployment, parse out metadata into our spec.
154
155
#[ context( "Reading deployment metadata" ) ]
155
- fn boot_entry_from_deployment (
156
+ async fn boot_entry_from_deployment (
156
157
sysroot : & SysrootLock ,
157
158
deployment : & ostree:: Deployment ,
158
159
) -> Result < BootEntry > {
@@ -169,7 +170,11 @@ fn boot_entry_from_deployment(
169
170
let csum = deployment. csum ( ) ;
170
171
let imgstate = match backend {
171
172
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 ?)
173
178
}
174
179
Backend :: OstreeContainer => {
175
180
ImageState :: from ( * ostree_container:: store:: query_image_commit ( repo, & csum) ?)
@@ -231,18 +236,18 @@ impl BootEntry {
231
236
}
232
237
233
238
/// 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 (
235
240
sysroot : & SysrootLock ,
236
241
) -> Result < ( ostree:: Deployment , Deployments , Host ) > {
237
242
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 ?;
239
244
Ok ( ( booted_deployment, deployments, host) )
240
245
}
241
246
242
247
/// Gather the ostree deployment objects, but also extract metadata from them into
243
248
/// a more native Rust structure.
244
249
#[ context( "Computing status" ) ]
245
- pub ( crate ) fn get_status (
250
+ pub ( crate ) async fn get_status (
246
251
sysroot : & SysrootLock ,
247
252
booted_deployment : Option < & ostree:: Deployment > ,
248
253
) -> Result < ( Deployments , Host ) > {
@@ -281,23 +286,36 @@ pub(crate) fn get_status(
281
286
other,
282
287
} ;
283
288
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
+
301
319
let spec = staged
302
320
. as_ref ( )
303
321
. or ( booted. as_ref ( ) )
@@ -346,7 +364,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
346
364
crate :: cli:: require_root ( ) ?;
347
365
let sysroot = super :: cli:: get_locked_sysroot ( ) . await ?;
348
366
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 ?;
350
368
host
351
369
} ;
352
370
0 commit comments