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

Deduplicate lctl calls in iml-agent #2099

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions iml-agent/src/action_plugins/action_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::action_plugins::{
check_kernel, check_stonith, firewall_cmd, high_availability, kernel_module, lamigo, lpurge,
ltuer, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{action_purge, action_warning, server},
use crate::{
action_plugins::{
check_kernel, check_stonith, firewall_cmd, high_availability, kernel_module, lamigo,
lpurge, ltuer, lustre,
ntp::{action_configure, is_ntp_configured},
ostpool, package, postoffice,
stratagem::{action_purge, action_warning, server},
},
lustre::lctl,
};
use iml_util::action_plugins;
use iml_wire_types::ActionName;
Expand Down Expand Up @@ -47,7 +50,7 @@ pub fn create_registry() -> action_plugins::Actions {
.add_plugin("add_firewall_port", firewall_cmd::add_port)
.add_plugin("remove_firewall_port", firewall_cmd::remove_port)
.add_plugin("pcs", high_availability::pcs)
.add_plugin("lctl", lustre::lctl)
.add_plugin("lctl", lctl::<Vec<_>, String>)
.add_plugin("ostpool_create", ostpool::action_pool_create)
.add_plugin("ostpool_wait", ostpool::action_pool_wait)
.add_plugin("ostpool_destroy", ostpool::action_pool_destroy)
Expand Down
12 changes: 0 additions & 12 deletions iml-agent/src/action_plugins/lctl.rs

This file was deleted.

9 changes: 1 addition & 8 deletions iml-agent/src/action_plugins/lustre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

use crate::{agent_error::ImlAgentError, lustre};
use crate::agent_error::ImlAgentError;
use futures::TryFutureExt;
use iml_cmd::{CheckedCommandExt, Command};

/// Runs lctl with given arguments
pub async fn lctl(args: Vec<String>) -> Result<String, ImlAgentError> {
lustre::lctl(args.iter().map(|s| s.as_ref()).collect())
.await
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
}

/// According to http://wiki.lustre.org/Mounting_a_Lustre_File_System_on_Client_Nodes
/// we need to execute mount command
/// ```bash
Expand Down
2 changes: 1 addition & 1 deletion iml-agent/src/action_plugins/ostpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn action_pool_destroy(cmd: CmdPool) -> Result<(), ImlAgentError> {

pub async fn pool_list(filesystem: &str) -> Result<Vec<String>, ImlAgentError> {
match lctl(vec!["pool_list", &filesystem]).await {
Ok(o) => Ok(String::from_utf8_lossy(&o.stdout)
Ok(o) => Ok(o
.lines()
.skip(1)
.map(|s| s.rsplit('.').next().unwrap().to_string())
Expand Down
3 changes: 1 addition & 2 deletions iml-agent/src/daemon_plugins/ostpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ async fn list_fs() -> Vec<String> {
lctl(vec!["get_param", "-N", "mdt.*-MDT0000"])
.await
.map(|o| {
String::from_utf8_lossy(&o.stdout)
.lines()
o.lines()
.filter_map(|line| {
line.split('.')
.nth(1)
Expand Down
9 changes: 8 additions & 1 deletion iml-agent/src/lustre.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use crate::agent_error::ImlAgentError;
use futures::TryFutureExt;
use iml_cmd::{CheckedCommandExt, Command};
use std::ffi::OsStr;

pub async fn lctl(args: Vec<&str>) -> Result<std::process::Output, ImlAgentError> {
/// Runs lctl with given arguments
pub async fn lctl<I, S>(args: I) -> Result<String, ImlAgentError>
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
Command::new("/usr/sbin/lctl")
.args(args)
.checked_output()
.err_into()
.await
.map(|o| String::from_utf8_lossy(&o.stdout).to_string())
}