5
5
//! omdb commands that query or update specific Sleds
6
6
7
7
use crate :: Omdb ;
8
+ use crate :: check_allow_destructive:: DestructiveOperationToken ;
8
9
use crate :: helpers:: CONNECTION_OPTIONS_HEADING ;
9
10
use anyhow:: Context ;
10
11
use anyhow:: bail;
11
12
use clap:: Args ;
12
13
use clap:: Subcommand ;
14
+ use sled_agent_client:: types:: ChickenSwitchDestroyOrphanedDatasets ;
13
15
14
16
/// Arguments to the "omdb sled-agent" subcommand
15
17
#[ derive( Debug , Args ) ]
@@ -37,6 +39,11 @@ enum SledAgentCommands {
37
39
/// print information about the local bootstore node
38
40
#[ clap( subcommand) ]
39
41
Bootstore ( BootstoreCommands ) ,
42
+
43
+ /// control "chicken switches" (potentially-destructive sled-agent behavior
44
+ /// that can be toggled on or off via `omdb`)
45
+ #[ clap( subcommand) ]
46
+ ChickenSwitch ( ChickenSwitchCommands ) ,
40
47
}
41
48
42
49
#[ derive( Debug , Subcommand ) ]
@@ -46,32 +53,38 @@ enum ZoneCommands {
46
53
}
47
54
48
55
#[ derive( Debug , Subcommand ) ]
49
- enum ZpoolCommands {
50
- /// Print list of all zpools managed by the sled agent
51
- List ,
56
+ enum BootstoreCommands {
57
+ /// Show the internal state of the local bootstore node
58
+ Status ,
52
59
}
53
60
54
61
#[ derive( Debug , Subcommand ) ]
55
- enum DatasetCommands {
56
- /// Print list of all datasets the sled agent is configured to manage
57
- ///
58
- /// Note that the set of actual datasets on the sled may be distinct,
59
- /// use the `omdb db inventory collections show` command to see the latest
60
- /// set of datasets collected from sleds.
61
- List ,
62
+ enum ChickenSwitchCommands {
63
+ /// interact with the "destroy orphaned datasets" chicken switch
64
+ DestroyOrphans ( DestroyOrphansArgs ) ,
65
+ }
66
+
67
+ #[ derive( Debug , Args ) ]
68
+ struct DestroyOrphansArgs {
69
+ #[ command( subcommand) ]
70
+ command : DestroyOrphansCommands ,
62
71
}
63
72
64
73
#[ derive( Debug , Subcommand ) ]
65
- enum BootstoreCommands {
66
- /// Show the internal state of the local bootstore node
67
- Status ,
74
+ enum DestroyOrphansCommands {
75
+ /// Get the current chicken switch setting
76
+ Get ,
77
+ /// Enable the current chicken switch setting
78
+ Enable ,
79
+ /// Disable the current chicken switch setting
80
+ Disable ,
68
81
}
69
82
70
83
impl SledAgentArgs {
71
84
/// Run a `omdb sled-agent` subcommand.
72
85
pub ( crate ) async fn run_cmd (
73
86
& self ,
74
- _omdb : & Omdb ,
87
+ omdb : & Omdb ,
75
88
log : & slog:: Logger ,
76
89
) -> Result < ( ) , anyhow:: Error > {
77
90
// This is a little goofy. The sled URL is required, but can come
@@ -92,6 +105,29 @@ impl SledAgentArgs {
92
105
SledAgentCommands :: Bootstore ( BootstoreCommands :: Status ) => {
93
106
cmd_bootstore_status ( & client) . await
94
107
}
108
+ SledAgentCommands :: ChickenSwitch (
109
+ ChickenSwitchCommands :: DestroyOrphans ( DestroyOrphansArgs {
110
+ command : DestroyOrphansCommands :: Get ,
111
+ } ) ,
112
+ ) => cmd_chicken_switch_destroy_orphans_get ( & client) . await ,
113
+ SledAgentCommands :: ChickenSwitch (
114
+ ChickenSwitchCommands :: DestroyOrphans ( DestroyOrphansArgs {
115
+ command : DestroyOrphansCommands :: Enable ,
116
+ } ) ,
117
+ ) => {
118
+ let token = omdb. check_allow_destructive ( ) ?;
119
+ cmd_chicken_switch_destroy_orphans_set ( & client, true , token)
120
+ . await
121
+ }
122
+ SledAgentCommands :: ChickenSwitch (
123
+ ChickenSwitchCommands :: DestroyOrphans ( DestroyOrphansArgs {
124
+ command : DestroyOrphansCommands :: Disable ,
125
+ } ) ,
126
+ ) => {
127
+ let token = omdb. check_allow_destructive ( ) ?;
128
+ cmd_chicken_switch_destroy_orphans_set ( & client, false , token)
129
+ . await
130
+ }
95
131
}
96
132
}
97
133
}
@@ -157,3 +193,33 @@ async fn cmd_bootstore_status(
157
193
158
194
Ok ( ( ) )
159
195
}
196
+
197
+ /// Runs `omdb sled-agent chicken-switch destroy-orphans get`
198
+ async fn cmd_chicken_switch_destroy_orphans_get (
199
+ client : & sled_agent_client:: Client ,
200
+ ) -> Result < ( ) , anyhow:: Error > {
201
+ let ChickenSwitchDestroyOrphanedDatasets { destroy_orphans } = client
202
+ . chicken_switch_destroy_orphaned_datasets_get ( )
203
+ . await
204
+ . context ( "get chicken switch value" ) ?
205
+ . into_inner ( ) ;
206
+ let status = if destroy_orphans { "enabled" } else { "disabled" } ;
207
+ println ! ( "destroy orphaned datasets {status}" ) ;
208
+ Ok ( ( ) )
209
+ }
210
+
211
+ /// Runs `omdb sled-agent chicken-switch destroy-orphans {enable,disable}`
212
+ async fn cmd_chicken_switch_destroy_orphans_set (
213
+ client : & sled_agent_client:: Client ,
214
+ destroy_orphans : bool ,
215
+ _token : DestructiveOperationToken ,
216
+ ) -> Result < ( ) , anyhow:: Error > {
217
+ let options = ChickenSwitchDestroyOrphanedDatasets { destroy_orphans } ;
218
+ client
219
+ . chicken_switch_destroy_orphaned_datasets_put ( & options)
220
+ . await
221
+ . context ( "put chicken switch value" ) ?;
222
+ let status = if destroy_orphans { "enabled" } else { "disabled" } ;
223
+ println ! ( "destroy orphaned datasets {status}" ) ;
224
+ Ok ( ( ) )
225
+ }
0 commit comments