Skip to content

Commit

Permalink
make rack_topology required to save me from myself
Browse files Browse the repository at this point in the history
  • Loading branch information
faithanalog committed Sep 29, 2023
1 parent d9845ec commit e689108
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
20 changes: 18 additions & 2 deletions package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,25 @@ pub enum TargetCommand {
#[clap(
short,
long,
default_value_if("image", "standard", "single-sled")
default_value_if("image", "trampoline", Some("single-sled")),
// This opt is required, and clap will enforce that even with
// `required = false`, since it's not an Option. But the
// default_value_if only works if we set `required` to false. It's
// jank, but it is what it is.
// https://github.com/clap-rs/clap/issues/4086
required = false
)]
rack_topology: Option<crate::target::RackTopology>,
/// Specify whether nexus will run in a single-sled or multi-sled
/// environment.
///
/// Set single-sled for dev purposes when you're running a single
/// sled-agent. Set multi-sled if you're running with mulitple sleds.
/// Currently this only affects the crucible disk allocation strategy-
/// VM disks will require 3 distinct sleds with `multi-sled`, which will
/// fail in a single-sled environment. `single-sled` relaxes this
/// requirement.
rack_topology: crate::target::RackTopology,
},
/// List all existing targets
List,
Expand Down
17 changes: 10 additions & 7 deletions package/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ pub struct KnownTarget {
image: Image,
machine: Option<Machine>,
switch: Option<Switch>,
rack_topology: Option<RackTopology>,
rack_topology: RackTopology,
}

impl KnownTarget {
pub fn new(
image: Image,
machine: Option<Machine>,
switch: Option<Switch>,
rack_topology: Option<RackTopology>,
rack_topology: RackTopology,
) -> Result<Self> {
if matches!(image, Image::Trampoline) {
if machine.is_some() {
Expand All @@ -103,7 +103,7 @@ impl Default for KnownTarget {
image: Image::Standard,
machine: Some(Machine::NonGimlet),
switch: Some(Switch::Stub),
rack_topology: Some(RackTopology::MultiSled),
rack_topology: RackTopology::MultiSled,
}
}
}
Expand All @@ -118,9 +118,7 @@ impl From<KnownTarget> for Target {
if let Some(switch) = kt.switch {
map.insert("switch".to_string(), switch.to_string());
}
if let Some(rack_topology) = kt.rack_topology {
map.insert("rack-topology".to_string(), rack_topology.to_string());
}
map.insert("rack-topology".to_string(), kt.rack_topology.to_string());
Target(map)
}
}
Expand Down Expand Up @@ -170,6 +168,11 @@ impl std::str::FromStr for KnownTarget {
}
}
}
KnownTarget::new(image, machine, switch, rack_topology)
KnownTarget::new(
image,
machine,
switch,
rack_topology.unwrap_or(RackTopology::MultiSled),
)
}
}

0 comments on commit e689108

Please sign in to comment.