aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-09-18 11:57:36 +0200
committerAlex Auvolat <alex@adnab.me>2023-09-18 11:59:08 +0200
commit015ccb39aa511c72d0c899713a828491871da3e7 (patch)
tree4160c9170a0073c9b6f0f6415632ddf2cc1cc1ca /src/garage
parent2e229d44303bfafa22aaf0d4aa299021a937220e (diff)
downloadgarage-015ccb39aa511c72d0c899713a828491871da3e7.tar.gz
garage-015ccb39aa511c72d0c899713a828491871da3e7.zip
new layout: make zone_redundancy optionnal (if not set, is maximum)
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/cli/layout.rs37
-rw-r--r--src/garage/cli/structs.rs4
2 files changed, 24 insertions, 17 deletions
diff --git a/src/garage/cli/layout.rs b/src/garage/cli/layout.rs
index 9bb90309..557549e2 100644
--- a/src/garage/cli/layout.rs
+++ b/src/garage/cli/layout.rs
@@ -261,28 +261,35 @@ pub async fn cmd_config_layout(
let mut did_something = false;
match config_opt.redundancy {
None => (),
- Some(r) => {
- if r > layout.replication_factor {
- println!(
- "The zone redundancy must be smaller or equal to the \
- replication factor ({}).",
- layout.replication_factor
- );
- } else if r < 1 {
- println!("The zone redundancy must be at least 1.");
- } else {
- layout
- .staging_parameters
- .update(LayoutParameters { zone_redundancy: r });
- println!("The new zone redundancy has been saved ({}).", r);
+ Some(r_str) => {
+ let r = r_str
+ .parse::<ZoneRedundancy>()
+ .ok_or_message("invalid zone redundancy value")?;
+ if let ZoneRedundancy::AtLeast(r_int) = r {
+ if r_int > layout.replication_factor {
+ return Err(Error::Message(format!(
+ "The zone redundancy must be smaller or equal to the \
+ replication factor ({}).",
+ layout.replication_factor
+ )));
+ } else if r_int < 1 {
+ return Err(Error::Message(
+ "The zone redundancy must be at least 1.".into(),
+ ));
+ }
}
+
+ layout
+ .staging_parameters
+ .update(LayoutParameters { zone_redundancy: r });
+ println!("The new zone redundancy has been saved ({}).", r);
did_something = true;
}
}
if !did_something {
return Err(Error::Message(
- "Please specify an action for `garage layout config` to do".into(),
+ "Please specify an action for `garage layout config`".into(),
));
}
diff --git a/src/garage/cli/structs.rs b/src/garage/cli/structs.rs
index fd37a24e..c4ebeb1a 100644
--- a/src/garage/cli/structs.rs
+++ b/src/garage/cli/structs.rs
@@ -143,9 +143,9 @@ pub struct RemoveRoleOpt {
#[derive(StructOpt, Debug)]
pub struct ConfigLayoutOpt {
- /// Zone redundancy parameter
+ /// Zone redundancy parameter ('none'/'max' or integer)
#[structopt(short = "r", long = "redundancy")]
- pub(crate) redundancy: Option<usize>,
+ pub(crate) redundancy: Option<String>,
}
#[derive(StructOpt, Debug)]