Skip to content

Commit

Permalink
feat(cli): Add support for excluding features or nodes when removing
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic committed Jul 10, 2023
1 parent 193b45a commit 36d0715
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ pub(crate) mod nodes {
/// Specifies the filter used to remove extra nodes
extra_nodes_filter: Vec<String>,

/// Features or Node IDs to not remove (exclude from the removal)
#[clap(long, num_args(1..))]
exclude: Vec<String>,

/// Motivation for removing additional nodes
#[clap(long)]
motivation: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn main() -> Result<(), anyhow::Error> {

cli::Commands::Nodes(nodes) => {
match &nodes.subcommand {
cli::nodes::Commands::Remove { extra_nodes_filter, no_auto, motivation } => {
cli::nodes::Commands::Remove { extra_nodes_filter, no_auto, exclude, motivation } => {
if motivation.is_none() && !extra_nodes_filter.is_empty() {
cmd.error(
ErrorKind::MissingRequiredArgument,
Expand All @@ -218,6 +218,7 @@ async fn main() -> Result<(), anyhow::Error> {
runner.remove_nodes(NodesRemoveRequest {
extra_nodes_filter: extra_nodes_filter.clone(),
no_auto: *no_auto,
exclude: Some(exclude.clone()),
motivation: motivation.clone().unwrap_or_default(),
}).await
},
Expand Down
9 changes: 9 additions & 0 deletions rs/ic-management-backend/src/endpoints/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ async fn remove(
}

let decentralization_node = DecentralizationNode::from(&n);

if let Some(exclude) = request.exclude.as_ref() {
for exclude_feature in exclude {
if decentralization_node.matches_feature_value(exclude_feature) {
return None;
}
}
}

if let Some(filter) = request
.extra_nodes_filter
.iter()
Expand Down
1 change: 1 addition & 0 deletions rs/ic-management-types/src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct SubnetResizeRequest {
pub struct NodesRemoveRequest {
pub no_auto: bool,
pub extra_nodes_filter: Vec<String>,
pub exclude: Option<Vec<String>>,
pub motivation: String,
}

Expand Down

0 comments on commit 36d0715

Please sign in to comment.