diff --git a/src/cli/build.rs b/src/cli/build.rs index 88431af4..8467fe84 100644 --- a/src/cli/build.rs +++ b/src/cli/build.rs @@ -648,18 +648,16 @@ pub fn subcommand_update_hsm_group(hsm_group: Option<&String>) -> Command { } pub fn subcommand_migrate_backup() -> Command { - let migrate_backup = Command::new("backup") + Command::new("backup") .aliases(["mb"]) .arg_required_else_help(true) .about("Backup the configuration (BOS, CFS, image and HSM group) of a given vCluster/BOS session template.") .arg(arg!(-b --"bos" "BOS Sessiontemplate to use to derive CFS, boot parameters and HSM group")) - .arg(arg!(-d --"destination" "Destination folder to store the backup on")); - - migrate_backup + .arg(arg!(-d --"destination" "Destination folder to store the backup on")) } pub fn subcommand_migrate_restore() -> Command { - let migrate_restore = Command::new("restore") + Command::new("restore") .aliases(["mr"]) .arg_required_else_help(true) .about("MIGRATE RESTORE of all the nodes in a HSM group. Boot configuration means updating the image used to boot the machine. Configuration of a node means the CFS configuration with the ansible scripts running once a node has been rebooted.\neg:\nmanta update hsm-group --boot-image --desired-configuration ") @@ -667,14 +665,7 @@ pub fn subcommand_migrate_restore() -> Command { .arg(arg!(-c --"cfs-file" "CFS session template of the cluster backed previously with migrate backup")) .arg(arg!(-j --"hsm-file" "HSM group description file of the cluster backed previously with migrate backup")) .arg(arg!(-m --"ims-file" "IMS file backed previously with migrate backup")) - .arg(arg!(-i --"image-dir" "Path where the image files are stored.")); - - // migrate_restore = match hsm_group { - // Some(_) => update_hsm_group, - // None => update_hsm_group.arg(arg!( "HSM group name").required(true)), - // }; - - migrate_restore + .arg(arg!(-i --"image-dir" "Path where the image files are stored.")) } pub fn subcommand_power() -> Command { diff --git a/src/cli/commands.rs b/src/cli/commands.rs index c12cdcf9..0bc09c76 100644 --- a/src/cli/commands.rs +++ b/src/cli/commands.rs @@ -39,4 +39,3 @@ pub mod remove_hw_component_cluster; pub mod remove_nodes; pub mod update_hsm_group; pub mod update_node; - diff --git a/src/cli/commands/add_nodes.rs b/src/cli/commands/add_nodes.rs index 6ec30cd9..75a10d83 100644 --- a/src/cli/commands/add_nodes.rs +++ b/src/cli/commands/add_nodes.rs @@ -9,7 +9,7 @@ pub async fn exec( xname_string: &str, ) { let new_target_hsm_members = xname_string - .split(",") + .split(',') .map(|xname| xname.trim()) .collect::>(); @@ -39,7 +39,7 @@ pub async fn exec( // merge HSM group list with the list of xnames provided by the user target_hsm_group_member_vec.extend( xname_string - .split(",") + .split(',') .map(|xname| xname.trim().to_string()) .collect::>(), ); diff --git a/src/cli/commands/apply_hw_cluster.rs b/src/cli/commands/apply_hw_cluster.rs index 7949f03c..8db1ffd5 100644 --- a/src/cli/commands/apply_hw_cluster.rs +++ b/src/cli/commands/apply_hw_cluster.rs @@ -271,10 +271,8 @@ pub mod utils { let combined_target_parent_hsm_hw_component_type_scores_based_on_scarcity_hashmap: HashMap< String, f32, - > = calculate_scarcity_scores( - &combined_target_parent_hsm_node_hw_component_count_vec, - ) - .await; + > = calculate_scarcity_scores(&combined_target_parent_hsm_node_hw_component_count_vec) + .await; // ********************************************************************************************************* // CALCULATE FINAL HSM SUMMARY COUNTERS AFTER REMOVING THE NODES THAT NEED TO GO TO TARGET @@ -291,9 +289,7 @@ pub mod utils { let hw_component_counters_to_move_out_from_combined_hsm = crate::cli::commands::apply_hw_cluster::utils::downscale_from_final_hsm_group( &final_combined_target_parent_hsm_hw_component_summary.clone(), - &final_combined_target_parent_hsm_hw_component_summary - .into_iter() - .map(|(hw_component, _)| hw_component) + &final_combined_target_parent_hsm_hw_component_summary.into_keys() .collect::>(), &mut combined_target_parent_hsm_node_hw_component_count_vec, &combined_target_parent_hsm_hw_component_type_scores_based_on_scarcity_hashmap, @@ -606,18 +602,14 @@ pub mod utils { } */ pub async fn calculate_scarcity_scores( - hsm_node_hw_component_count: &Vec<( - String, - HashMap, - )>, + hsm_node_hw_component_count: &Vec<(String, HashMap)>, ) -> HashMap { let total_num_nodes = hsm_node_hw_component_count.len(); - let mut hw_component_vec: Vec<&String> = - hsm_node_hw_component_count - .iter() - .flat_map(|(_, hw_component_counter_hashmap)| hw_component_counter_hashmap.keys()) - .collect(); + let mut hw_component_vec: Vec<&String> = hsm_node_hw_component_count + .iter() + .flat_map(|(_, hw_component_counter_hashmap)| hw_component_counter_hashmap.keys()) + .collect(); hw_component_vec.sort(); hw_component_vec.dedup(); @@ -626,9 +618,7 @@ pub mod utils { for hw_component in hw_component_vec { let mut node_count = 0; - for (_, hw_component_counter_hashmap) in - hsm_node_hw_component_count - { + for (_, hw_component_counter_hashmap) in hsm_node_hw_component_count { if hw_component_counter_hashmap.contains_key(hw_component) { node_count += 1; } diff --git a/src/cli/commands/apply_session.rs b/src/cli/commands/apply_session.rs index e740d2f9..6512f8ef 100644 --- a/src/cli/commands/apply_session.rs +++ b/src/cli/commands/apply_session.rs @@ -306,7 +306,7 @@ pub async fn check_nodes_are_ready_to_run_cfs_configuration_and_run_cfs_session( shasta_token, shasta_base_url, shasta_root_cert, - &vec![xname.clone()], + &[xname.clone()], ) .await?; diff --git a/src/cli/commands/get_nodes.rs b/src/cli/commands/get_nodes.rs index 0aabad3d..51b145cc 100644 --- a/src/cli/commands/get_nodes.rs +++ b/src/cli/commands/get_nodes.rs @@ -13,7 +13,6 @@ pub async fn exec( 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 = hsm::group::shasta::utils::get_member_vec_from_hsm_name_vec( diff --git a/src/cli/commands/migrate_backup.rs b/src/cli/commands/migrate_backup.rs index 3c3d6b36..d382971a 100644 --- a/src/cli/commands/migrate_backup.rs +++ b/src/cli/commands/migrate_backup.rs @@ -18,8 +18,6 @@ pub async fn exec( let dest_path = Path::new(destination.unwrap()); let bucket_name = "boot-images"; let files2download = ["manifest.json", "initrd", "kernel", "rootfs"]; - let countfiles2download = files2download.len() + 3; // BOS + CFS + HSM - // let files2download = ["manifest.json"]; log::debug!("Create directory '{}'", destination.unwrap()); match std::fs::create_dir_all(dest_path) { @@ -27,7 +25,7 @@ pub async fn exec( Err(error) => panic!( "Unable to create directory {}. Error returned: {}", &dest_path.to_string_lossy(), - error.to_string() + error ), }; @@ -146,7 +144,7 @@ pub async fn exec( download_counter += 1; // Image ---------------------------------------------------------------------------------- - for (_boot_sets_param, boot_sets_value) in bos_templates[0].boot_sets.as_ref().unwrap() { + for boot_sets_value in bos_templates[0].boot_sets.as_ref().unwrap().values() { if let Some(path) = &boot_sets_value.path { let image_id_related_to_bos_sessiontemplate = path .trim_start_matches("s3://boot-images/") @@ -175,7 +173,7 @@ pub async fn exec( ); let sts_value = - match s3_auth(&shasta_token, &shasta_base_url, &shasta_root_cert).await { + match s3_auth(shasta_token, shasta_base_url, shasta_root_cert).await { Ok(sts_value) => { log::debug!("Debug - STS token:\n{:#?}", sts_value); sts_value @@ -194,17 +192,16 @@ pub async fn exec( &download_counter, &files2download.len() + 2 ); - let _result = - match s3_download_object(&sts_value, &src, &bucket_name, &dest).await { - Ok(_result) => { - download_counter = download_counter + 1; - } - Err(error) => panic!( - "Unable to download file {} from s3. Error returned: {}", - &src, - error.to_string() - ), - }; + + match s3_download_object(&sts_value, &src, bucket_name, &dest).await { + Ok(_result) => { + download_counter += 1; + } + Err(error) => panic!( + "Unable to download file {} from s3. Error returned: {}", + &src, error + ), + }; } } else { panic!( diff --git a/src/cli/commands/migrate_restore.rs b/src/cli/commands/migrate_restore.rs index faf4a238..8dda4321 100644 --- a/src/cli/commands/migrate_restore.rs +++ b/src/cli/commands/migrate_restore.rs @@ -77,10 +77,10 @@ pub async fn exec( artifacts: vec![], }; - let backup_ims_file = ims_file.clone().unwrap().to_string(); - let backup_cfs_file = cfs_file.clone().unwrap().to_string(); - let backup_bos_file = bos_file.clone().unwrap().to_string(); - let backup_hsm_file = hsm_file.clone().unwrap().to_string(); + let backup_ims_file = ims_file.unwrap().to_string(); + let backup_cfs_file = cfs_file.unwrap().to_string(); + let backup_bos_file = bos_file.unwrap().to_string(); + let backup_hsm_file = hsm_file.unwrap().to_string(); let ims_image_name: String = get_image_name_from_ims_file(&backup_ims_file); println!("\tImage name: {}", ims_image_name); @@ -114,9 +114,9 @@ pub async fn exec( // Do we have another image with this name? println!("Registering new image with IMS..."); let ims_image_id: String = ims_register_image( - &shasta_token, - &shasta_base_url, - &shasta_root_cert, + shasta_token, + shasta_base_url, + shasta_root_cert, &ims_image_name, ) .await; @@ -224,7 +224,7 @@ async fn create_bos_sessiontemplate( // This is as ugly as it can be // println!("Path: {}", bos_sessiontemplate.clone().boot_sets.clone().unwrap().compute.clone().unwrap().path.clone().unwrap().to_string()); let path_modified = format!("s3://boot-images/{}/manifest.json", ims_image_id); - let bos_sessiontemplate_modified = bos_sessiontemplate + bos_sessiontemplate .boot_sets .as_mut() .unwrap() @@ -234,10 +234,7 @@ async fn create_bos_sessiontemplate( .path = Some(path_modified); log::debug!("BOS sessiontemplate loaded:\n{:#?}", bos_sessiontemplate); - log::debug!( - "BOS sessiontemplate modified:\n{:#?}", - &bos_sessiontemplate_modified - ); + log::debug!("BOS sessiontemplate modified:\n{:#?}", &bos_sessiontemplate); match bos::template::shasta::http_client::post( shasta_token, @@ -312,7 +309,7 @@ async fn create_cfs_config( shasta_base_url, shasta_root_cert, &cfs_config, - &cfs_config_name.as_str(), + cfs_config_name.as_str(), ) .await { @@ -338,10 +335,11 @@ async fn ims_update_image_add_manifest( ims_image_name: &String, ims_image_id: &String, ) { - match mesa::ims::image::shasta::http_client::get(&shasta_token, - &shasta_base_url, - &shasta_root_cert, - Some(ims_image_name) + match mesa::ims::image::shasta::http_client::get( + shasta_token, + shasta_base_url, + shasta_root_cert, + Some(ims_image_name) ).await { Ok(_vector) => { if _vector.is_empty() { @@ -433,7 +431,7 @@ async fn s3_upload_image_artifacts( }; for file in vec_image_files { - let filename = Path::new(file).file_name().clone().unwrap(); + let filename = Path::new(file).file_name().unwrap(); let file_size = match fs::metadata(file) { Ok(_file_metadata) => { let res: String = humansize::format_size(_file_metadata.len(), DECIMAL); @@ -550,7 +548,6 @@ fn file_md5sum(filename: PathBuf) -> Digest { let buf_len = len.min(100_000_000) as usize; let mut buf = BufReader::with_capacity(buf_len, f); let mut context = md5::Context::new(); - let mut i = 0; let bar = ProgressBar::new(len / buf_len as u64); loop { @@ -565,7 +562,6 @@ fn file_md5sum(filename: PathBuf) -> Digest { // Tell the buffer that the chunk is consumed let part_len = part.len(); buf.consume(part_len); - i += 1; bar.inc(1); // println!("Consumed {} out of {}; step {}/{}", // humansize::format_size(part_len, DECIMAL), @@ -585,7 +581,7 @@ fn calculate_image_checksums( vec_backup_image_files: &Vec, ) { for file in vec_backup_image_files { - let file_size = match fs::metadata(&file) { + let file_size = match fs::metadata(file) { Ok(_file_metadata) => { let res: String = humansize::format_size(_file_metadata.len(), DECIMAL); res @@ -654,11 +650,12 @@ async fn ims_register_image( link: None, arch: None, }; - let list_images_with_same_name = match mesa::ims::image::mesa::http_client::get(&shasta_token, - &shasta_base_url, - &shasta_root_cert, - Some(ims_image_name) - ).await { + let list_images_with_same_name = match mesa::ims::image::mesa::http_client::get( + shasta_token, + shasta_base_url, + shasta_root_cert, + Some(ims_image_name) + ).await { Ok(vector) => vector, Err(error) => panic!("Error: Unable to determine if there are other images in IMS with the name {}. Error code: {}", &ims_image_name, &error), }; @@ -678,9 +675,9 @@ async fn ims_register_image( } let json_response = match register_new_image( - &shasta_token, - &shasta_base_url, - &shasta_root_cert, + shasta_token, + shasta_base_url, + shasta_root_cert, &ims_record, ) .await @@ -689,7 +686,7 @@ async fn ims_register_image( Err(error) => panic!( "Error: Unable to register a new image {} into IMS {}", &ims_image_name.to_string(), - error.to_string() + error ), }; json_response["id"].to_string().replace('"', "") diff --git a/src/cli/commands/remove_hw_component_cluster.rs b/src/cli/commands/remove_hw_component_cluster.rs index 5d844404..d7a8bc94 100644 --- a/src/cli/commands/remove_hw_component_cluster.rs +++ b/src/cli/commands/remove_hw_component_cluster.rs @@ -159,9 +159,6 @@ pub async fn exec( ] .concat(); - let combined_target_parent_hsm_hw_component_summary_hashmap = - calculate_hsm_hw_component_summary(&combined_target_parent_hsm_node_hw_component_count_vec); - // ********************************************************************************************************* // CALCULATE HW COMPONENT TYPE SCORE BASED ON SCARCITY @@ -193,8 +190,7 @@ pub async fn exec( crate::cli::commands::apply_hw_cluster::utils::downscale_from_final_hsm_group( &final_target_hsm_hw_component_summary.clone(), &final_target_hsm_hw_component_summary - .into_iter() - .map(|(hw_component, _)| hw_component) + .into_keys() .collect::>(), &mut target_hsm_node_hw_component_count_vec, &combined_target_parent_hsm_hw_component_type_scores_based_on_scarcity_hashmap, diff --git a/src/cli/commands/remove_nodes.rs b/src/cli/commands/remove_nodes.rs index f96b51e9..7181bdc7 100644 --- a/src/cli/commands/remove_nodes.rs +++ b/src/cli/commands/remove_nodes.rs @@ -9,7 +9,7 @@ pub async fn exec( xname_string: &str, ) { let new_target_hsm_members = xname_string - .split(",") + .split(',') .map(|xname| xname.trim()) .collect::>(); diff --git a/src/cli/process.rs b/src/cli/process.rs index 19efb92e..55afc3d3 100644 --- a/src/cli/process.rs +++ b/src/cli/process.rs @@ -1066,8 +1066,9 @@ pub async fn process_cli( cfs_file, hsm_file, ims_file, - image_dir - ).await; + image_dir, + ) + .await; } } else if let Some(cli_migrate) = cli_root.subcommand_matches("migrate") { if let Some(cli_migrate) = cli_migrate.subcommand_matches("backup") {