Skip to content

Commit 4735c27

Browse files
committed
add omdb command to read/write new chicken switch
1 parent f39206d commit 4735c27

File tree

2 files changed

+85
-17
lines changed

2 files changed

+85
-17
lines changed

dev-tools/omdb/src/bin/omdb/sled_agent.rs

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
//! omdb commands that query or update specific Sleds
66
77
use crate::Omdb;
8+
use crate::check_allow_destructive::DestructiveOperationToken;
89
use crate::helpers::CONNECTION_OPTIONS_HEADING;
910
use anyhow::Context;
1011
use anyhow::bail;
1112
use clap::Args;
1213
use clap::Subcommand;
14+
use sled_agent_client::types::ChickenSwitchDestroyOrphanedDatasets;
1315

1416
/// Arguments to the "omdb sled-agent" subcommand
1517
#[derive(Debug, Args)]
@@ -37,6 +39,11 @@ enum SledAgentCommands {
3739
/// print information about the local bootstore node
3840
#[clap(subcommand)]
3941
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),
4047
}
4148

4249
#[derive(Debug, Subcommand)]
@@ -46,32 +53,38 @@ enum ZoneCommands {
4653
}
4754

4855
#[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,
5259
}
5360

5461
#[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,
6271
}
6372

6473
#[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,
6881
}
6982

7083
impl SledAgentArgs {
7184
/// Run a `omdb sled-agent` subcommand.
7285
pub(crate) async fn run_cmd(
7386
&self,
74-
_omdb: &Omdb,
87+
omdb: &Omdb,
7588
log: &slog::Logger,
7689
) -> Result<(), anyhow::Error> {
7790
// This is a little goofy. The sled URL is required, but can come
@@ -92,6 +105,29 @@ impl SledAgentArgs {
92105
SledAgentCommands::Bootstore(BootstoreCommands::Status) => {
93106
cmd_bootstore_status(&client).await
94107
}
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+
}
95131
}
96132
}
97133
}
@@ -157,3 +193,33 @@ async fn cmd_bootstore_status(
157193

158194
Ok(())
159195
}
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+
}

dev-tools/omdb/tests/usage_errors.out

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,11 @@ Debug a specific Sled
909909
Usage: omdb sled-agent [OPTIONS] <COMMAND>
910910

911911
Commands:
912-
zones print information about zones
913-
bootstore print information about the local bootstore node
914-
help Print this message or the help of the given subcommand(s)
912+
zones print information about zones
913+
bootstore print information about the local bootstore node
914+
chicken-switch control "chicken switches" (potentially-destructive sled-agent behavior that can
915+
be toggled on or off via `omdb`)
916+
help Print this message or the help of the given subcommand(s)
915917

916918
Options:
917919
--log-level <LOG_LEVEL> log level filter [env: LOG_LEVEL=] [default: warn]

0 commit comments

Comments
 (0)