Skip to content

Commit

Permalink
fix: filter bos sessiontemplate by list of xnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Sopena Ballesteros committed Jan 30, 2024
1 parent 46ecaa9 commit deb8b78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/bos/template/mesa/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@ use crate::bos::template::mesa::r#struct::response_payload::BosSessionTemplate;
pub async fn filter(
bos_sessiontemplate_vec: &mut Vec<BosSessionTemplate>,
hsm_group_name_vec: &[String],
xname_vec: &[String],
cfs_configuration_name_opt: Option<&str>,
limit_number_opt: Option<&u8>,
) -> Vec<BosSessionTemplate> {
// Filter by target (hsm group name or xnames)
if !hsm_group_name_vec.is_empty() {
// Filter by list of HSM group or xnames as target
if !hsm_group_name_vec.is_empty() || !xname_vec.is_empty() {
bos_sessiontemplate_vec.retain(|bos_sessiontemplate| {
bos_sessiontemplate
.boot_sets
.as_ref()
.unwrap()
.iter()
.any(|(_parameter, boot_set)| {
boot_set.node_groups.is_some()
&& !boot_set.node_groups.as_ref().unwrap().is_empty()
&& boot_set
.node_groups
.as_ref()
.unwrap()
.iter()
.all(|node_group| hsm_group_name_vec.contains(node_group))
.any(|(_, boot_set)| {
boot_set.node_groups.as_ref().is_some_and(|node_group| {
!node_group.is_empty()
&& node_group
.iter()
.all(|node_group| hsm_group_name_vec.contains(node_group))
}) || boot_set.node_list.as_ref().is_some_and(|node_list| {
!node_list.is_empty()
&& node_list.iter().all(|node| xname_vec.contains(node))
})
})
});
}
Expand Down
1 change: 1 addition & 0 deletions src/cfs/configuration/mesa/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub async fn filter(
bos::template::mesa::utils::filter(
&mut bos_sessiontemplate_vec,
hsm_group_name_vec,
&Vec::new(),
None,
None,
)
Expand Down
2 changes: 2 additions & 0 deletions src/ims/image/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub async fn filter(
bos::template::mesa::utils::filter(
&mut bos_sessiontemplate_value_vec,
hsm_group_name_vec,
&Vec::new(),
None,
None,
)
Expand Down Expand Up @@ -240,6 +241,7 @@ pub async fn get_image_cfsconfiguration_targetgroups_tuple(
bos::template::mesa::utils::filter(
&mut bos_sessiontemplate_vec,
hsm_group_name_vec,
&Vec::new(),
None,
None,
)
Expand Down

0 comments on commit deb8b78

Please sign in to comment.