@@ -80,6 +80,8 @@ enum DbCommands {
80
80
Services ( ServicesArgs ) ,
81
81
/// Print information about sleds
82
82
Sleds ,
83
+ /// Print information about customer instances
84
+ Instances ,
83
85
}
84
86
85
87
#[ derive( Debug , Args ) ]
@@ -246,6 +248,9 @@ impl DbArgs {
246
248
DbCommands :: Sleds => {
247
249
cmd_db_sleds ( & opctx, & datastore, self . fetch_limit ) . await
248
250
}
251
+ DbCommands :: Instances => {
252
+ cmd_db_instances ( & datastore, self . fetch_limit ) . await
253
+ }
249
254
}
250
255
}
251
256
}
@@ -680,6 +685,53 @@ async fn cmd_db_sleds(
680
685
Ok ( ( ) )
681
686
}
682
687
688
+ #[ derive( Tabled ) ]
689
+ #[ tabled( rename_all = "SCREAMING_SNAKE_CASE" ) ]
690
+ struct CustomerInstanceRow {
691
+ id : Uuid ,
692
+ state : String ,
693
+ propolis_id : Uuid ,
694
+ sled_id : Uuid ,
695
+ }
696
+
697
+ impl From < Instance > for CustomerInstanceRow {
698
+ fn from ( i : Instance ) -> Self {
699
+ CustomerInstanceRow {
700
+ id : i. id ( ) ,
701
+ state : format ! ( "{:?}" , i. runtime_state. state. 0 ) ,
702
+ propolis_id : i. runtime_state . propolis_id ,
703
+ sled_id : i. runtime_state . sled_id ,
704
+ }
705
+ }
706
+ }
707
+
708
+ /// Run `omdb db instances`: list data about customer VMs.
709
+ async fn cmd_db_instances (
710
+ datastore : & DataStore ,
711
+ limit : NonZeroU32 ,
712
+ ) -> Result < ( ) , anyhow:: Error > {
713
+ use db:: schema:: instance:: dsl;
714
+ let instances = dsl:: instance
715
+ . limit ( i64:: from ( u32:: from ( limit) ) )
716
+ . select ( Instance :: as_select ( ) )
717
+ . load_async ( datastore. pool_for_tests ( ) . await ?)
718
+ . await
719
+ . context ( "loading instances" ) ?;
720
+
721
+ let ctx = || "listing instances" . to_string ( ) ;
722
+ check_limit ( & instances, limit, ctx) ;
723
+
724
+ let rows = instances. into_iter ( ) . map ( |i| CustomerInstanceRow :: from ( i) ) ;
725
+ let table = tabled:: Table :: new ( rows)
726
+ . with ( tabled:: settings:: Style :: empty ( ) )
727
+ . with ( tabled:: settings:: Padding :: new ( 0 , 1 , 0 , 0 ) )
728
+ . to_string ( ) ;
729
+
730
+ println ! ( "{}" , table) ;
731
+
732
+ Ok ( ( ) )
733
+ }
734
+
683
735
// DNS
684
736
685
737
/// Run `omdb db dns show`.
0 commit comments