Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Sep 21, 2023
1 parent 0891329 commit 6b8efbf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
6 changes: 3 additions & 3 deletions omdb/src/bin/omdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use clap::Subcommand;

mod db;
mod nexus;
mod sled;
mod sled_agent;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
Expand All @@ -38,7 +38,7 @@ async fn main() -> Result<(), anyhow::Error> {
match args.command {
OmdbCommands::Db(db) => db.run_cmd(&log).await,
OmdbCommands::Nexus(nexus) => nexus.run_cmd(&log).await,
OmdbCommands::Sled(sled) => sled.run_cmd(&log).await,
OmdbCommands::SledAgent(sled) => sled.run_cmd(&log).await,
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ enum OmdbCommands {
/// Debug a specific Nexus instance
Nexus(nexus::NexusArgs),
/// Debug a specific Sled
Sled(sled::SledArgs),
SledAgent(sled_agent::SledAgentArgs),
}

fn parse_dropshot_log_level(
Expand Down
29 changes: 15 additions & 14 deletions omdb/src/bin/omdb/sled.rs → omdb/src/bin/omdb/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ use clap::Subcommand;

/// Arguments to the "omdb sled" subcommand
#[derive(Debug, Args)]
pub struct SledArgs {
pub struct SledAgentArgs {
/// URL of the Sled internal API
#[clap(long, env("OMDB_SLED_URL"))]
sled_url: Option<String>,
#[clap(long, env("OMDB_SLED_AGENT_URL"))]
sled_agent_url: Option<String>,

#[command(subcommand)]
command: SledCommands,
command: SledAgentCommands,
}

/// Subcommands for the "omdb sled" subcommand
#[derive(Debug, Subcommand)]
enum SledCommands {
enum SledAgentCommands {
/// print information about zones
#[clap(subcommand)]
Zones(ZoneCommands),
Expand All @@ -34,37 +34,38 @@ enum SledCommands {

#[derive(Debug, Subcommand)]
enum ZoneCommands {
/// Print list of all zones
/// Print list of all running control plane zones
List,
}

#[derive(Debug, Subcommand)]
enum ZpoolCommands {
/// Print list of all zpools
/// Print list of all zpools managed by the sled agent
List,
}

impl SledArgs {
impl SledAgentArgs {
/// Run a `omdb sled` subcommand.
pub async fn run_cmd(
&self,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
// This is a little goofy. The sled URL is required, but can come
// from the environment, in which case it won't be on the command line.
let Some(sled_url) = &self.sled_url else {
let Some(sled_agent_url) = &self.sled_agent_url else {
bail!(
"sled URL must be specified with --sled-url or \
OMDB_SLED_URL"
"sled URL must be specified with --sled-agent-url or \
OMDB_SLED_AGENT_URL"
);
};
let client = sled_agent_client::Client::new(sled_url, log.clone());
let client =
sled_agent_client::Client::new(sled_agent_url, log.clone());

match &self.command {
SledCommands::Zones(ZoneCommands::List) => {
SledAgentCommands::Zones(ZoneCommands::List) => {
cmd_zones_list(&client).await
}
SledCommands::Zpools(ZpoolCommands::List) => {
SledAgentCommands::Zpools(ZpoolCommands::List) => {
cmd_zpools_list(&client).await
}
}
Expand Down
14 changes: 8 additions & 6 deletions omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Omicron debugger (unstable)
Usage: omdb [OPTIONS] <COMMAND>

Commands:
db Query the control plane database (CockroachDB)
nexus Debug a specific Nexus instance
help Print this message or the help of the given subcommand(s)
db Query the control plane database (CockroachDB)
nexus Debug a specific Nexus instance
sled-agent Debug a specific Sled
help Print this message or the help of the given subcommand(s)

Options:
--log-level <LOG_LEVEL> log level filter [env: LOG_LEVEL=] [default: warn]
Expand All @@ -29,9 +30,10 @@ using internal APIs. This is a prototype. The commands and output are unstable
Usage: omdb [OPTIONS] <COMMAND>

Commands:
db Query the control plane database (CockroachDB)
nexus Debug a specific Nexus instance
help Print this message or the help of the given subcommand(s)
db Query the control plane database (CockroachDB)
nexus Debug a specific Nexus instance
sled-agent Debug a specific Sled
help Print this message or the help of the given subcommand(s)

Options:
--log-level <LOG_LEVEL>
Expand Down

0 comments on commit 6b8efbf

Please sign in to comment.