Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Add devices to iml-cli
Browse files Browse the repository at this point in the history
Add devices to iml-cli

Signed-off-by: johnsonw <[email protected]>
  • Loading branch information
johnsonw committed Apr 27, 2020
1 parent 39a78f4 commit 209e15b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
48 changes: 48 additions & 0 deletions iml-manager-cli/src/devices.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2020 DDN. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{
api_utils::get_all,
display_utils::{wrap_fut, DisplayType, IntoDisplayType as _},
error::ImlManagerCliError,
};
use console::Term;
use iml_wire_types::Volume;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub enum DevicesCommand {
/// List all configured devices
#[structopt(name = "list")]
List {
/// Set the display type
///
/// The display type can be one of the following:
/// tabular: display content in a table format
/// json: return data in json format
/// yaml: return data in yaml format
#[structopt(short = "d", long = "display", default_value = "tabular")]
display_type: DisplayType,
},
}

pub async fn devices_cli(command: DevicesCommand) -> Result<(), ImlManagerCliError> {
match command {
DevicesCommand::List { display_type } => {
let fut_volumes = get_all::<Volume>();

let volumes = wrap_fut("Fetching volumes...", fut_volumes).await?;

tracing::debug!("Volumes: {:?}", volumes);

let term = Term::stdout();

let x = volumes.objects.into_display_type(display_type);

term.write_line(&x).unwrap();
}
};

Ok(())
}
40 changes: 39 additions & 1 deletion iml-manager-cli/src/display_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use console::{style, Term};
use futures::{Future, FutureExt};
use iml_wire_types::{Command, Filesystem, Host, OstPool, ServerProfile, StratagemConfiguration};
use iml_wire_types::{
Command, Filesystem, Host, OstPool, ServerProfile, StratagemConfiguration, Volume,
};
use indicatif::ProgressBar;
use number_formatter::{format_bytes, format_number};
use prettytable::{Row, Table};
Expand Down Expand Up @@ -191,6 +193,42 @@ impl IntoTable for Vec<ServerProfile> {
}
}

impl IntoTable for Vec<Volume> {
fn into_table(self) -> Table {
generate_table(
&[
"Label",
"Size",
"Primary Host",
"Primary Path",
"Failover Host",
"Failover Path",
],
self.into_iter().map(|x| {
let primary = x
.volume_nodes
.iter()
.find(|vn| vn.primary)
.map_or_else(|| ("", ""), |v| (&v.host_label, &v.path));
let failover = x
.volume_nodes
.iter()
.find(|vn| !vn.primary)
.map_or_else(|| ("", ""), |v| (&v.host_label, &v.path));

vec![
x.label,
x.size.unwrap_or_default().to_string(),
primary.0.to_string(),
primary.1.to_string(),
failover.0.to_string(),
failover.1.to_string(),
]
}),
)
}
}

pub trait IntoDisplayType {
fn into_display_type(self, display_type: DisplayType) -> String;
}
Expand Down
1 change: 1 addition & 0 deletions iml-manager-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

pub mod api_utils;
pub mod devices;
pub mod display_utils;
pub mod error;
pub mod filesystem;
Expand Down
8 changes: 8 additions & 0 deletions iml-manager-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

use iml_manager_cli::{
devices::{self, devices_cli},
display_utils::display_error,
filesystem::{self, filesystem_cli},
server::{self, server_cli},
Expand All @@ -16,6 +17,12 @@ use structopt::StructOpt;
#[structopt(name = "iml", setting = structopt::clap::AppSettings::ColoredHelp)]
/// The Integrated Manager for Lustre CLI
pub enum App {
#[structopt(name = "devices")]
/// Work with devices
Devices {
#[structopt(subcommand)]
command: devices::DevicesCommand,
},
#[structopt(name = "stratagem")]
/// Work with Stratagem server
Stratagem {
Expand Down Expand Up @@ -50,6 +57,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::from_path("/var/lib/chroma/iml-settings.conf").expect("Could not load cli env");

let r = match matches {
App::Devices { command } => devices_cli(command).await,
App::Stratagem { command } => stratagem_cli(command).await,
App::Server { command } => server_cli(command).await,
App::UpdateRepoFile(config) => update_repo_file_cli(config).await,
Expand Down

0 comments on commit 209e15b

Please sign in to comment.