-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[omdb] Add a couple simple Sled Agent queries #4126
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,109 @@ | ||||||
// This Source Code Form is subject to the terms of the Mozilla Public | ||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||||||
|
||||||
//! omdb commands that query or update specific Sleds | ||||||
|
||||||
use anyhow::bail; | ||||||
use anyhow::Context; | ||||||
use clap::Args; | ||||||
use clap::Subcommand; | ||||||
|
||||||
/// Arguments to the "omdb sled" subcommand | ||||||
#[derive(Debug, Args)] | ||||||
pub struct SledArgs { | ||||||
/// URL of the Sled internal API | ||||||
#[clap(long, env("OMDB_SLED_URL"))] | ||||||
sled_url: Option<String>, | ||||||
|
||||||
#[command(subcommand)] | ||||||
command: SledCommands, | ||||||
} | ||||||
|
||||||
/// Subcommands for the "omdb sled" subcommand | ||||||
#[derive(Debug, Subcommand)] | ||||||
enum SledCommands { | ||||||
/// print information about zones | ||||||
#[clap(subcommand)] | ||||||
Zones(ZoneCommands), | ||||||
|
||||||
/// print information about zpools | ||||||
#[clap(subcommand)] | ||||||
Zpools(ZpoolCommands), | ||||||
} | ||||||
|
||||||
#[derive(Debug, Subcommand)] | ||||||
enum ZoneCommands { | ||||||
/// Print list of all zones | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(just trying to be precise about what it's printing so that someone doesn't interpret this as the same as edit: I just checked and it looks like this is only the running zones that are the subset of zones the sled agent is configured to run, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated, specifying that these are "running control plane zones". I think we could also expose the set of zones the sled was told to run, but this will require modifying the sled agent API. |
||||||
List, | ||||||
} | ||||||
|
||||||
#[derive(Debug, Subcommand)] | ||||||
enum ZpoolCommands { | ||||||
/// Print list of all zpools | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||
List, | ||||||
} | ||||||
|
||||||
impl SledArgs { | ||||||
/// 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 { | ||||||
bail!( | ||||||
"sled URL must be specified with --sled-url or \ | ||||||
OMDB_SLED_URL" | ||||||
); | ||||||
}; | ||||||
let client = sled_agent_client::Client::new(sled_url, log.clone()); | ||||||
|
||||||
match &self.command { | ||||||
SledCommands::Zones(ZoneCommands::List) => { | ||||||
cmd_zones_list(&client).await | ||||||
} | ||||||
SledCommands::Zpools(ZpoolCommands::List) => { | ||||||
cmd_zpools_list(&client).await | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// Runs `omdb sled zones list` | ||||||
async fn cmd_zones_list( | ||||||
client: &sled_agent_client::Client, | ||||||
) -> Result<(), anyhow::Error> { | ||||||
let response = client.zones_list().await.context("listing zones")?; | ||||||
let zones = response.into_inner(); | ||||||
let zones: Vec<_> = zones.into_iter().collect(); | ||||||
|
||||||
println!("zones:"); | ||||||
if zones.is_empty() { | ||||||
println!(" <none>"); | ||||||
} | ||||||
for zone in &zones { | ||||||
println!(" {:?}", zone); | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} | ||||||
|
||||||
/// Runs `omdb sled zpools list` | ||||||
async fn cmd_zpools_list( | ||||||
client: &sled_agent_client::Client, | ||||||
) -> Result<(), anyhow::Error> { | ||||||
let response = client.zpools_get().await.context("listing zpools")?; | ||||||
let zpools = response.into_inner(); | ||||||
|
||||||
println!("zpools:"); | ||||||
if zpools.is_empty() { | ||||||
println!(" <none>"); | ||||||
} | ||||||
for zpool in &zpools { | ||||||
println!(" {:?}", zpool); | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only wonder if this should be
sled-agent
(there are other things on the sled). If you do I'd carry that through everywhere -- e.g., the URL env var name too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!