Skip to content

Commit

Permalink
CLEO -> Fix apply and create cluster printing all devices instead…
Browse files Browse the repository at this point in the history
… of only those that are part of the cluster.
  • Loading branch information
mbfm committed Dec 19, 2024
1 parent 45d6353 commit bc7098c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions opendut-cleo/src/commands/cluster_configuration/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,37 @@ impl CreateClusterConfigurationCli {
}
}

pub async fn create_cluster_configuration(configuration: ClusterConfiguration, carl: &mut CarlClient, output: &CreateOutputFormat) -> crate::Result<()> {
carl.cluster.store_cluster_configuration(configuration.clone()).await
pub async fn create_cluster_configuration(cluster: ClusterConfiguration, carl: &mut CarlClient, output: &CreateOutputFormat) -> crate::Result<()> {
carl.cluster.store_cluster_configuration(cluster.clone()).await
.map_err(|err| format!("Could not store cluster configuration. Make sure the application is running. Error: {}", err))?;

let devices = carl.peers.list_devices().await.map_err(|error| format!("Error while trying to match devices.\n {}", error))?;
let device_names = devices.clone().into_iter()
let devices = carl.peers.list_devices().await
.map_err(|error| format!("Error while trying to list devices.\n {}", error))?;

let device_names = devices.into_iter()
.filter(|device| {
cluster.devices.contains(&device.id)
})
.map(|device| device.name)
.collect::<Vec<_>>();

match output {
CreateOutputFormat::Text => {
println!("Successfully stored new cluster configuration.");

println!("ClusterID: {}", configuration.id);
println!("Name of the Cluster: {}", configuration.name);
println!("ClusterID: {}", cluster.id);
println!("Name of the Cluster: {}", cluster.name);
println!("The following devices are part of the cluster configuration:");
for device_name in device_names.iter() {
println!("\x09{}", device_name);
};
}
CreateOutputFormat::Json => {
let json = serde_json::to_string(&configuration).unwrap();
let json = serde_json::to_string(&cluster).unwrap();
println!("{}", json);
}
CreateOutputFormat::PrettyJson => {
let json = serde_json::to_string_pretty(&configuration).unwrap();
let json = serde_json::to_string_pretty(&cluster).unwrap();
println!("{}", json);
}
}
Expand Down

0 comments on commit bc7098c

Please sign in to comment.