Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ mod db_metadata;
mod ereport;
mod saga;
mod sitrep;
mod target_release;
mod user_data_export;
mod whatis;

Expand Down Expand Up @@ -405,6 +406,8 @@ enum DbCommands {
Sleds(SledsArgs),
/// Show instances grouped by the sled they are running on
SledInstances(SledInstancesArgs),
/// Print the current target release and the update date
TargetRelease(target_release::TargetReleaseArgs),
/// Print information about customer instances.
Instance(InstanceArgs),
/// Alias to `omdb instance list`.
Expand Down Expand Up @@ -1453,6 +1456,9 @@ impl DbArgs {
)
.await
}
DbCommands::TargetRelease(args) => {
target_release::cmd_db_target_release(&opctx, &datastore, args).await
}
DbCommands::Instance(InstanceArgs {
command: InstanceCommands::List(args),
}) => {
Expand Down
103 changes: 103 additions & 0 deletions dev-tools/omdb/src/bin/omdb/db/target_release.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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 db target-release` subcommand
//!
//! Shows the current target release and date when update was requested.
//! When `--all` option is used, lists all target release records.

use crate::helpers::datetime_rfc3339_concise;
use anyhow::Context;
use async_bb8_diesel::AsyncRunQueryDsl;
use clap::Args;
use diesel::QueryDsl;
use diesel::SelectableHelper;
use nexus_db_model::TargetRelease;
use nexus_db_model::TargetReleaseSource;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::DataStore;
use nexus_db_queries::db::datastore::SQL_BATCH_SIZE;
use nexus_db_queries::db::pagination::Paginator;
use nexus_db_queries::db::pagination::paginated;
use nexus_db_schema::schema::target_release::dsl;
use tabled::Tabled;

#[derive(Debug, Args, Clone)]
pub(super) struct TargetReleaseArgs {
/// List of target releases sorted from oldest to newest
#[clap(long)]
all: bool,
}

#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct TargetReleaseRow {
system_version: String,
time_requested: String,
}

pub(super) async fn cmd_db_target_release(
opctx: &OpContext,
datastore: &DataStore,
args: &TargetReleaseArgs,
) -> Result<(), anyhow::Error> {
let releases = if args.all {
let conn = datastore.pool_connection_for_tests().await?;
let mut releases: Vec<TargetRelease> = Vec::new();
let mut paginator = Paginator::new(
SQL_BATCH_SIZE,
dropshot::PaginationOrder::Ascending,
);
while let Some(p) = paginator.next() {
let batch = paginated(
dsl::target_release,
dsl::generation,
&p.current_pagparams(),
)
.select(TargetRelease::as_select())
.load_async(&*conn)
.await
.context("listing target releases")?;
paginator =
p.found_batch(&batch, &|r: &TargetRelease| r.generation);
releases.extend(batch);
}
releases
} else {
vec![
datastore
.target_release_get_current(opctx)
.await
.context("fetching current target release")?,
]
};

let mut rows = Vec::with_capacity(releases.len());
for release in releases {
let system_version = match release
.release_source()
.context("interpreting target release source")?
{
TargetReleaseSource::Unspecified => "<unspecified>".to_string(),
TargetReleaseSource::SystemVersion(tuf_repo_id) => datastore
.tuf_repo_get_version(opctx, &tuf_repo_id)
.await
.with_context(|| format!("fetching TUF repo {tuf_repo_id}"))?
.to_string(),
};
rows.push(TargetReleaseRow {
system_version,
time_requested: datetime_rfc3339_concise(&release.time_requested),
});
}

let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.with(tabled::settings::Padding::new(1, 1, 0, 0))
.to_string();

println!("{}", table);

Ok(())
}
2 changes: 2 additions & 0 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Commands:
sitreps Show the current history of fault management situation reports
sleds Print information about sleds
sled-instances Show instances grouped by the sled they are running on
target-release Print the current target release and the update date
instance Print information about customer instances
instances Alias to `omdb instance list`
network Print information about the network
Expand Down Expand Up @@ -210,6 +211,7 @@ Commands:
sitreps Show the current history of fault management situation reports
sleds Print information about sleds
sled-instances Show instances grouped by the sled they are running on
target-release Print the current target release and the update date
instance Print information about customer instances
instances Alias to `omdb instance list`
network Print information about the network
Expand Down
Loading