Skip to content

Commit

Permalink
feat: Duplicate get nodes subcommand into get cluster
Browse files Browse the repository at this point in the history
feat: Get cluster status
  • Loading branch information
Manuel Sopena Ballesteros committed Nov 16, 2023
1 parent 1d9bcc4 commit 8e895f3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 28 deletions.
26 changes: 24 additions & 2 deletions src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,31 @@ pub fn subcommand_get_bos_template(hsm_group: Option<&String>) -> Command {
get_bos_template
}

pub fn subcommand_get_cluster_details(hsm_group: Option<&String>) -> Command {
let mut get_node = Command::new("cluster")
.aliases(["C", "clstr"])
.about("Get cluster details")
.arg(arg!(-n --"nids-only-one-line" "Prints nids in one line eg nidxxxxxx,nidyyyyyy,nidzzzzzz,..."))
.arg(arg!(-x --"xnames-only-one-line" "Prints xnames in one line eg x1001c1s5b0n0,x1001c1s5b0n1,..."))
.arg(arg!(-s --"status" "Get cluster status:\n - OK: All nodes are operational (booted and configured)\n - ON: At least one node is not yet booted\n - STANDBY: At lesat one node's heartbeat is lost\n - UNCONFIGURED: All nodes are booted but at least one of them is being configured\n - FAILED: At least one node configuration failed"))
.arg(arg!(-o --output <FORMAT> "Output format. If missing it will print output data in human redeable (tabular) format").value_parser(["json"]));

match hsm_group {
None => {
get_node = get_node
.arg_required_else_help(true)
.arg(arg!(<HSM_GROUP_NAME> "hsm group name"))
}
Some(_) => {}
}

get_node
}

pub fn subcommand_get_node(hsm_group: Option<&String>) -> Command {
let mut get_node = Command::new("nodes")
.aliases(["n", "node", "nd"])
.about("Get members of a HSM group")
.about("This command will be DEPRECATED in manta v1.15.0. the new command to use will be replaced by 'manta get cluster'. Get members of a HSM group")
.arg(arg!(-n --"nids-only-one-line" "Prints nids in one line eg nidxxxxxx,nidyyyyyy,nidzzzzzz,..."))
.arg(arg!(-x --"xnames-only-one-line" "Prints xnames in one line eg x1001c1s5b0n0,x1001c1s5b0n1,..."))
.arg(arg!(-o --output <FORMAT> "Output format. If missing it will print output data in human redeable (tabular) format").value_parser(["json"]));
Expand All @@ -258,7 +279,7 @@ pub fn subcommand_get_node(hsm_group: Option<&String>) -> Command {
pub fn subcommand_get_hsm_groups_details(hsm_group: Option<&String>) -> Command {
let mut get_hsm_group = Command::new("hsm-groups")
.aliases(["h", "hg", "hsm", "hsmgrps"])
.about("Get HSM groups details");
.about("This command will be DEPRECATED in manta v1.15.0. the new command to use will be called 'manta get cluster' and the output will be similar to manta get nodes. Get HSM groups details");

match hsm_group {
None => {
Expand Down Expand Up @@ -303,6 +324,7 @@ pub fn subcommand_get(hsm_group: Option<&String>) -> Command {
.subcommand(subcommand_get_cfs_configuration(hsm_group))
.subcommand(subcommand_get_bos_template(hsm_group))
.subcommand(subcommand_get_node(hsm_group))
.subcommand(subcommand_get_cluster_details(hsm_group))
.subcommand(subcommand_get_hsm_groups_details(hsm_group))
.subcommand(subcommand_get_images(hsm_group))
}
Expand Down
31 changes: 30 additions & 1 deletion src/cli/commands/get_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub async fn exec(
silent: bool,
silent_xname: bool,
output_opt: Option<&String>,
status: bool,
) {
// Take all nodes for all hsm_groups found and put them in a Vec
let mut hsm_groups_node_list: Vec<String> = hsm::utils::get_member_vec_from_hsm_name_vec(
Expand All @@ -33,7 +34,35 @@ pub async fn exec(
)
.await;

if silent {
if status {
let status_output = if node_details_list.iter().any(|node_details| {
node_details
.configuration_status
.eq_ignore_ascii_case("failed")
}) {
"FAILED"
} else if node_details_list
.iter()
.any(|node_details| node_details.power_status.eq_ignore_ascii_case("standby"))
{
"STANDBY"
}else if node_details_list
.iter()
.any(|node_details| node_details.power_status.eq_ignore_ascii_case("on"))
{
"ON"
} else if !node_details_list.iter().any(|node_details| {
node_details
.configuration_status
.eq_ignore_ascii_case("configured")
}) {
"UNCONFIGURED"
} else {
"OK"
};

println!("{}", status_output);
} else if silent {
let node_nid_list = node_details_list
.iter()
.map(|node_details| node_details.nid.clone())
Expand Down
113 changes: 88 additions & 25 deletions src/cli/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use crate::{
};

use super::commands::{
self, apply_cluster, apply_ephemeral_env, apply_image, apply_node_off, apply_node_on,
apply_node_reset, apply_session, config_set_hsm, config_set_log, config_set_site, config_show,
config_unset_auth, config_unset_hsm, console_cfs_session_image_target_ansible, console_node,
get_configuration, get_hsm, get_images, get_nodes, get_session, get_template, update_hsm_group,
update_node, apply_configuration,
self, apply_cluster, apply_configuration, apply_ephemeral_env, apply_image, apply_node_off,
apply_node_on, apply_node_reset, apply_session, config_set_hsm, config_set_log,
config_set_site, config_show, config_unset_auth, config_unset_hsm,
console_cfs_session_image_target_ansible, console_node, get_configuration, get_hsm, get_images,
get_nodes, get_session, get_template, update_hsm_group, update_node,
};

pub async fn process_cli(
Expand Down Expand Up @@ -119,7 +119,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_configuration.get_one::<String>("hsm-group"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_configuration.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand All @@ -144,7 +148,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_session.get_one::<String>("hsm-group"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_session.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand Down Expand Up @@ -176,7 +184,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_template.get_one::<String>("hsm-group"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_template.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand All @@ -200,12 +212,45 @@ pub async fn process_cli(
cli_get_template.get_one::<u8>("limit"),
)
.await;
} else if let Some(cli_get_node) = cli_get.subcommand_matches("cluster") {
let hsm_group_target_vec = validate_target_hsm_name(
shasta_token,
shasta_base_url,
shasta_root_cert,
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_node.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;

get_nodes::exec(
shasta_token,
shasta_base_url,
shasta_root_cert,
&hsm_group_target_vec,
*cli_get_node
.get_one::<bool>("nids-only-one-line")
.unwrap_or(&false),
*cli_get_node
.get_one::<bool>("xnames-only-one-line")
.unwrap_or(&false),
cli_get_node.get_one::<String>("output"),
*cli_get_node.get_one::<bool>("status").unwrap_or(&false),
)
.await;
} else if let Some(cli_get_node) = cli_get.subcommand_matches("nodes") {
let hsm_group_target_vec = validate_target_hsm_name(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_node.get_one::<String>("HSM_GROUP_NAME"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_node.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand All @@ -222,14 +267,19 @@ pub async fn process_cli(
.get_one::<bool>("xnames-only-one-line")
.unwrap_or(&false),
cli_get_node.get_one::<String>("output"),
false,
)
.await;
} else if let Some(cli_get_hsm_groups) = cli_get.subcommand_matches("hsm-groups") {
let hsm_group_target_vec = validate_target_hsm_name(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_hsm_groups.get_one::<String>("HSM_GROUP_NAME"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_hsm_groups.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand All @@ -246,7 +296,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_get_images.get_one::<String>("hsm-group"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_get_images.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand All @@ -266,14 +320,17 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_apply_configuration
.try_get_one::<String>("hsm-group")
.unwrap_or(None),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_apply_configuration.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;

let tag = if let Some(input_tag) = cli_apply_configuration.get_one::<String>("tag") {
let tag = if let Some(input_tag) = cli_apply_configuration.get_one::<String>("tag")
{
input_tag.clone()
} else {
chrono::Utc::now().format("%Y%m%d%H%M%S").to_string()
Expand All @@ -293,7 +350,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_apply_session.get_one::<String>("HSM_GROUP_NAME"),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_apply_session.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand Down Expand Up @@ -346,9 +407,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_apply_image
.try_get_one::<String>("hsm-group")
.unwrap_or(None),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_apply_image.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand Down Expand Up @@ -395,9 +458,11 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_apply_cluster
.try_get_one::<String>("hsm-group")
.unwrap_or(None),
if let Some(hsm_group_name) = hsm_group_name_opt {
Some(hsm_group_name)
} else {
cli_apply_cluster.get_one::<String>("HSM_GROUP_NAME")
},
hsm_group_name_opt,
)
.await;
Expand Down Expand Up @@ -557,9 +622,7 @@ pub async fn process_cli(
shasta_token,
shasta_base_url,
shasta_root_cert,
cli_log
.try_get_one::<String>("hsm-group")
.unwrap_or(None),
cli_log.try_get_one::<String>("hsm-group").unwrap_or(None),
hsm_group_name_opt,
)
.await;
Expand Down

0 comments on commit 8e895f3

Please sign in to comment.