Skip to content

Commit

Permalink
add sled agents, Omicron zones to inventory (#4727)
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco authored Jan 4, 2024
1 parent 12e6eb2 commit 5a81ef9
Show file tree
Hide file tree
Showing 43 changed files with 3,462 additions and 167 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 65 additions & 2 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use uuid::Uuid;

progenitor::generate_api!(
spec = "../../openapi/sled-agent.json",
derives = [ schemars::JsonSchema ],
derives = [ schemars::JsonSchema, PartialEq ],
inner_type = slog::Logger,
pre_hook = (|log: &slog::Logger, request: &reqwest::Request| {
slog::debug!(log, "client request";
Expand All @@ -25,7 +25,6 @@ progenitor::generate_api!(
//TODO trade the manual transformations later in this file for the
// replace directives below?
replace = {
//Ipv4Network = ipnetwork::Ipv4Network,
SwitchLocation = omicron_common::api::external::SwitchLocation,
Ipv6Network = ipnetwork::Ipv6Network,
IpNetwork = ipnetwork::IpNetwork,
Expand All @@ -34,6 +33,37 @@ progenitor::generate_api!(
}
);

// We cannot easily configure progenitor to derive `Eq` on all the client-
// generated types because some have floats and other types that can't impl
// `Eq`. We impl it explicitly for a few types on which we need it.
impl Eq for types::OmicronZonesConfig {}
impl Eq for types::OmicronZoneConfig {}
impl Eq for types::OmicronZoneType {}
impl Eq for types::OmicronZoneDataset {}

impl types::OmicronZoneType {
/// Human-readable label describing what kind of zone this is
///
/// This is just use for testing and reporting.
pub fn label(&self) -> impl std::fmt::Display {
match self {
types::OmicronZoneType::BoundaryNtp { .. } => "boundary_ntp",
types::OmicronZoneType::Clickhouse { .. } => "clickhouse",
types::OmicronZoneType::ClickhouseKeeper { .. } => {
"clickhouse_keeper"
}
types::OmicronZoneType::CockroachDb { .. } => "cockroach_db",
types::OmicronZoneType::Crucible { .. } => "crucible",
types::OmicronZoneType::CruciblePantry { .. } => "crucible_pantry",
types::OmicronZoneType::ExternalDns { .. } => "external_dns",
types::OmicronZoneType::InternalDns { .. } => "internal_dns",
types::OmicronZoneType::InternalNtp { .. } => "internal_ntp",
types::OmicronZoneType::Nexus { .. } => "nexus",
types::OmicronZoneType::Oximeter { .. } => "oximeter",
}
}
}

impl omicron_common::api::external::ClientError for types::Error {
fn message(&self) -> String {
self.message.clone()
Expand Down Expand Up @@ -245,6 +275,12 @@ impl From<&omicron_common::api::external::Name> for types::Name {
}
}

impl From<types::Name> for omicron_common::api::external::Name {
fn from(s: types::Name) -> Self {
Self::try_from(s.as_str().to_owned()).unwrap()
}
}

impl From<omicron_common::api::external::Vni> for types::Vni {
fn from(v: omicron_common::api::external::Vni) -> Self {
Self(u32::from(v))
Expand All @@ -264,6 +300,12 @@ impl From<omicron_common::api::external::MacAddr> for types::MacAddr {
}
}

impl From<types::MacAddr> for omicron_common::api::external::MacAddr {
fn from(s: types::MacAddr) -> Self {
s.parse().unwrap()
}
}

impl From<omicron_common::api::external::Ipv4Net> for types::Ipv4Net {
fn from(n: omicron_common::api::external::Ipv4Net) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
Expand Down Expand Up @@ -292,6 +334,12 @@ impl From<ipnetwork::Ipv4Network> for types::Ipv4Net {
}
}

impl From<types::Ipv4Net> for ipnetwork::Ipv4Network {
fn from(n: types::Ipv4Net) -> Self {
n.parse().unwrap()
}
}

impl From<ipnetwork::Ipv4Network> for types::Ipv4Network {
fn from(n: ipnetwork::Ipv4Network) -> Self {
Self::try_from(n.to_string()).unwrap_or_else(|e| panic!("{}: {}", n, e))
Expand All @@ -304,6 +352,12 @@ impl From<ipnetwork::Ipv6Network> for types::Ipv6Net {
}
}

impl From<types::Ipv6Net> for ipnetwork::Ipv6Network {
fn from(n: types::Ipv6Net) -> Self {
n.parse().unwrap()
}
}

impl From<ipnetwork::IpNetwork> for types::IpNet {
fn from(n: ipnetwork::IpNetwork) -> Self {
use ipnetwork::IpNetwork;
Expand All @@ -314,6 +368,15 @@ impl From<ipnetwork::IpNetwork> for types::IpNet {
}
}

impl From<types::IpNet> for ipnetwork::IpNetwork {
fn from(n: types::IpNet) -> Self {
match n {
types::IpNet::V4(v4) => ipnetwork::IpNetwork::V4(v4.into()),
types::IpNet::V6(v6) => ipnetwork::IpNetwork::V6(v6.into()),
}
}
}

impl From<std::net::Ipv4Addr> for types::Ipv4Net {
fn from(n: std::net::Ipv4Addr) -> Self {
Self::try_from(format!("{n}/32"))
Expand Down
4 changes: 3 additions & 1 deletion common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ impl JsonSchema for RoleName {
// to serialize the value.
//
// TODO: custom JsonSchema and Deserialize impls to enforce i64::MAX limit
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[derive(
Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq,
)]
pub struct ByteCount(u64);

#[allow(non_upper_case_globals)]
Expand Down
53 changes: 53 additions & 0 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ async fn cmd_db_inventory_collections_show(
inv_collection_print(&collection).await?;
let nerrors = inv_collection_print_errors(&collection).await?;
inv_collection_print_devices(&collection, &long_string_formatter).await?;
inv_collection_print_sleds(&collection);

if nerrors > 0 {
eprintln!(
Expand Down Expand Up @@ -2703,6 +2704,58 @@ async fn inv_collection_print_devices(
Ok(())
}

fn inv_collection_print_sleds(collection: &Collection) {
println!("SLED AGENTS");
for sled in collection.sled_agents.values() {
println!(
"\nsled {} (role = {:?}, serial {})",
sled.sled_id,
sled.sled_role,
match &sled.baseboard_id {
Some(baseboard_id) => &baseboard_id.serial_number,
None => "unknown",
},
);
println!(
" found at: {} from {}",
sled.time_collected, sled.source
);
println!(" address: {}", sled.sled_agent_address);
println!(" usable hw threads: {}", sled.usable_hardware_threads);
println!(
" usable memory (GiB): {}",
sled.usable_physical_ram.to_whole_gibibytes()
);
println!(
" reservoir (GiB): {}",
sled.reservoir_size.to_whole_gibibytes()
);

if let Some(zones) = collection.omicron_zones.get(&sled.sled_id) {
println!(
" zones collected from {} at {}",
zones.source, zones.time_collected,
);
println!(
" zones generation: {} (count: {})",
*zones.zones.generation,
zones.zones.zones.len()
);

if zones.zones.zones.is_empty() {
continue;
}

println!(" ZONES FOUND");
for z in &zones.zones.zones {
println!(" zone {} (type {})", z.id, z.zone_type.label());
}
} else {
println!(" warning: no zone information found");
}
}
}

#[derive(Debug)]
struct LongStringFormatter {
show_long_strings: bool,
Expand Down
Loading

0 comments on commit 5a81ef9

Please sign in to comment.