Fix layout show
to not show changes when there are no changes (#297)
fixes #295, partially Co-authored-by: Alex Auvolat <alex@adnab.me> Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/297 Co-authored-by: Alex <alex@adnab.me> Co-committed-by: Alex <alex@adnab.me>
This commit is contained in:
parent
c9ef3e461b
commit
277a20ec44
@ -43,14 +43,22 @@ pub async fn cmd_assign_role(
|
|||||||
resp => return Err(Error::Message(format!("Invalid RPC response: {:?}", resp))),
|
resp => return Err(Error::Message(format!("Invalid RPC response: {:?}", resp))),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut layout = fetch_layout(rpc_cli, rpc_host).await?;
|
||||||
|
|
||||||
let added_nodes = args
|
let added_nodes = args
|
||||||
.node_ids
|
.node_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|node_id| find_matching_node(status.iter().map(|adv| adv.id), node_id))
|
.map(|node_id| {
|
||||||
|
find_matching_node(
|
||||||
|
status
|
||||||
|
.iter()
|
||||||
|
.map(|adv| adv.id)
|
||||||
|
.chain(layout.node_ids().iter().cloned()),
|
||||||
|
node_id,
|
||||||
|
)
|
||||||
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
let mut layout = fetch_layout(rpc_cli, rpc_host).await?;
|
|
||||||
|
|
||||||
let mut roles = layout.roles.clone();
|
let mut roles = layout.roles.clone();
|
||||||
roles.merge(&layout.staging);
|
roles.merge(&layout.staging);
|
||||||
|
|
||||||
@ -323,11 +331,20 @@ pub fn print_cluster_layout(layout: &ClusterLayout) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_staging_role_changes(layout: &ClusterLayout) -> bool {
|
pub fn print_staging_role_changes(layout: &ClusterLayout) -> bool {
|
||||||
if !layout.staging.items().is_empty() {
|
let has_changes = layout
|
||||||
|
.staging
|
||||||
|
.items()
|
||||||
|
.iter()
|
||||||
|
.any(|(k, _, v)| layout.roles.get(k) != Some(v));
|
||||||
|
|
||||||
|
if has_changes {
|
||||||
println!();
|
println!();
|
||||||
println!("==== STAGED ROLE CHANGES ====");
|
println!("==== STAGED ROLE CHANGES ====");
|
||||||
let mut table = vec!["ID\tTags\tZone\tCapacity".to_string()];
|
let mut table = vec!["ID\tTags\tZone\tCapacity".to_string()];
|
||||||
for (id, _, role) in layout.staging.items().iter() {
|
for (id, _, role) in layout.staging.items().iter() {
|
||||||
|
if layout.roles.get(id) == Some(role) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let Some(role) = &role.0 {
|
if let Some(role) = &role.0 {
|
||||||
let tags = role.tags.join(",");
|
let tags = role.tags.join(",");
|
||||||
table.push(format!(
|
table.push(format!(
|
||||||
|
@ -208,7 +208,7 @@ pub fn find_matching_node(
|
|||||||
) -> Result<Uuid, Error> {
|
) -> Result<Uuid, Error> {
|
||||||
let mut candidates = vec![];
|
let mut candidates = vec![];
|
||||||
for c in cand {
|
for c in cand {
|
||||||
if hex::encode(&c).starts_with(&pattern) {
|
if hex::encode(&c).starts_with(&pattern) && !candidates.contains(&c) {
|
||||||
candidates.push(c);
|
candidates.push(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user