Skip to content

Commit

Permalink
Add a --running option to omdb db instances (#5291)
Browse files Browse the repository at this point in the history
Added a flag to the `omdb db instances` command: `--running`. 
It will only show running instances (or instances that are in that
state, specifically).

Co-authored-by: Alan Hanson <[email protected]>
  • Loading branch information
leftwo and Alan Hanson authored Mar 26, 2024
1 parent 53d8d3a commit 8fae16a
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use async_bb8_diesel::AsyncRunQueryDsl;
use async_bb8_diesel::AsyncSimpleConnection;
use camino::Utf8PathBuf;
use chrono::SecondsFormat;
use clap::ArgAction;
use clap::Args;
use clap::Subcommand;
use clap::ValueEnum;
Expand Down Expand Up @@ -92,6 +93,7 @@ use nexus_types::inventory::RotPageWhich;
use omicron_common::address::NEXUS_REDUNDANCY;
use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::Generation;
use omicron_common::api::external::InstanceState;
use omicron_common::api::external::LookupType;
use omicron_common::api::external::MacAddr;
use sled_agent_client::types::VolumeConstructionRequest;
Expand Down Expand Up @@ -257,7 +259,7 @@ enum DbCommands {
/// Print information about sleds
Sleds,
/// Print information about customer instances
Instances,
Instances(InstancesOptions),
/// Print information about the network
Network(NetworkArgs),
/// Print information about snapshots
Expand Down Expand Up @@ -346,6 +348,13 @@ impl CliDnsGroup {
}
}

#[derive(Debug, Args)]
struct InstancesOptions {
/// Only show the running instances
#[arg(short, long, action=ArgAction::SetTrue)]
running: bool,
}

#[derive(Debug, Args)]
struct InventoryArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -539,8 +548,14 @@ impl DbArgs {
DbCommands::Sleds => {
cmd_db_sleds(&opctx, &datastore, &self.fetch_opts).await
}
DbCommands::Instances => {
cmd_db_instances(&opctx, &datastore, &self.fetch_opts).await
DbCommands::Instances(instances_options) => {
cmd_db_instances(
&opctx,
&datastore,
&self.fetch_opts,
instances_options.running,
)
.await
}
DbCommands::Network(NetworkArgs {
command: NetworkCommands::ListEips,
Expand Down Expand Up @@ -1628,6 +1643,7 @@ async fn cmd_db_instances(
opctx: &OpContext,
datastore: &DataStore,
fetch_opts: &DbFetchOptions,
running: bool,
) -> Result<(), anyhow::Error> {
use db::schema::instance::dsl;
use db::schema::vmm::dsl as vmm_dsl;
Expand Down Expand Up @@ -1681,6 +1697,10 @@ async fn cmd_db_instances(
"-".to_string()
};

if running && i.effective_state() != InstanceState::Running {
continue;
}

let cir = CustomerInstanceRow {
id: i.instance().id().to_string(),
name: i.instance().name().to_string(),
Expand Down

0 comments on commit 8fae16a

Please sign in to comment.