@@ -16,20 +16,24 @@ use diesel::ExpressionMethods;
16
16
use diesel:: QueryDsl ;
17
17
use diesel:: SelectableHelper ;
18
18
use nexus_db_model:: BpTarget ;
19
+ use nexus_db_model:: SqlU32 ;
19
20
use nexus_db_queries:: authz;
20
21
use nexus_db_queries:: context:: OpContext ;
21
22
use nexus_db_queries:: db:: DataStore ;
22
23
use nexus_db_queries:: db:: datastore:: SQL_BATCH_SIZE ;
23
24
use nexus_db_queries:: db:: pagination:: Paginator ;
24
25
use nexus_types:: deployment:: Blueprint ;
25
26
use nexus_types:: deployment:: BlueprintMetadata ;
27
+ use nexus_types:: deployment:: ReconfiguratorChickenSwitches ;
26
28
use nexus_types:: deployment:: UnstableReconfiguratorState ;
27
29
use omicron_common:: api:: external:: Error ;
28
30
use omicron_common:: api:: external:: LookupType ;
29
31
use omicron_uuid_kinds:: BlueprintUuid ;
30
32
use omicron_uuid_kinds:: GenericUuid ;
31
33
use slog:: Logger ;
32
34
use std:: collections:: BTreeMap ;
35
+ use std:: num:: NonZeroU32 ;
36
+ use tabled:: Tabled ;
33
37
34
38
/// Arguments to the "omdb reconfigurator" subcommand
35
39
#[ derive( Debug , Args ) ]
@@ -53,6 +57,8 @@ enum ReconfiguratorCommands {
53
57
Archive ( ExportArgs ) ,
54
58
/// Show recent history of blueprints
55
59
History ( HistoryArgs ) ,
60
+ /// Show the recent history of chicken switch settings
61
+ ChickenSwitchesHistory ( ChickenSwitchesHistoryArgs ) ,
56
62
}
57
63
58
64
#[ derive( Debug , Args , Clone ) ]
@@ -61,6 +67,13 @@ struct ExportArgs {
61
67
output_file : Utf8PathBuf ,
62
68
}
63
69
70
+ #[ derive( Debug , Args , Clone ) ]
71
+ struct ChickenSwitchesHistoryArgs {
72
+ /// how far back in the history to show (number of targets)
73
+ #[ clap( long, default_value_t = 128 ) ]
74
+ limit : u32 ,
75
+ }
76
+
64
77
#[ derive( Debug , Args , Clone ) ]
65
78
struct HistoryArgs {
66
79
/// how far back in the history to show (number of targets)
@@ -111,6 +124,12 @@ impl ReconfiguratorArgs {
111
124
)
112
125
. await
113
126
}
127
+ ReconfiguratorCommands :: ChickenSwitchesHistory ( args) => {
128
+ cmd_reconfigurator_chicken_switches_history (
129
+ & opctx, & datastore, args,
130
+ )
131
+ . await
132
+ }
114
133
} ,
115
134
)
116
135
. await
@@ -352,6 +371,64 @@ async fn cmd_reconfigurator_history(
352
371
353
372
Ok ( ( ) )
354
373
}
374
+ /// Show recent history of chicken switches
375
+ async fn cmd_reconfigurator_chicken_switches_history (
376
+ opctx : & OpContext ,
377
+ datastore : & DataStore ,
378
+ history_args : & ChickenSwitchesHistoryArgs ,
379
+ ) -> anyhow:: Result < ( ) > {
380
+ let mut history = vec ! [ ] ;
381
+ let limit = history_args. limit ;
382
+ let batch_size = NonZeroU32 :: min ( limit. try_into ( ) . unwrap ( ) , SQL_BATCH_SIZE ) ;
383
+ let mut paginator = Paginator :: < SqlU32 > :: new (
384
+ batch_size,
385
+ dropshot:: PaginationOrder :: Descending ,
386
+ ) ;
387
+ while let Some ( p) = paginator. next ( ) {
388
+ if history. len ( ) >= limit as usize {
389
+ break ;
390
+ }
391
+ let batch = datastore
392
+ . reconfigurator_chicken_switches_list ( opctx, & p. current_pagparams ( ) )
393
+ . await
394
+ . context ( "batch of chicken switches" ) ?;
395
+ paginator = p. found_batch ( & batch, & |b| SqlU32 :: new ( b. version ) ) ;
396
+ history. extend ( batch. into_iter ( ) ) ;
397
+ }
398
+
399
+ #[ derive( Tabled ) ]
400
+ #[ tabled( rename_all = "SCREAMING_SNAKE_CASE" ) ]
401
+ struct SwitchesRow {
402
+ version : String ,
403
+ planner_enabled : String ,
404
+ time_modified : String ,
405
+ }
406
+
407
+ let rows: Vec < _ > = history
408
+ . into_iter ( )
409
+ . map ( |s| {
410
+ let ReconfiguratorChickenSwitches {
411
+ version,
412
+ planner_enabled,
413
+ time_modified,
414
+ } = s;
415
+ SwitchesRow {
416
+ version : version. to_string ( ) ,
417
+ planner_enabled : planner_enabled. to_string ( ) ,
418
+ time_modified : time_modified. to_string ( ) ,
419
+ }
420
+ } )
421
+ . collect ( ) ;
422
+
423
+ let table = tabled:: Table :: new ( rows)
424
+ . with ( tabled:: settings:: Style :: empty ( ) )
425
+ . with ( tabled:: settings:: Padding :: new ( 0 , 1 , 0 , 0 ) )
426
+ . to_string ( ) ;
427
+
428
+ println ! ( "{}" , table) ;
429
+
430
+ Ok ( ( ) )
431
+ }
355
432
356
433
async fn blueprint_load (
357
434
opctx : & OpContext ,
0 commit comments