Skip to content

Commit

Permalink
feat: start command supports custom inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
jacderida committed Nov 4, 2024
1 parent b677fdb commit 756fc26
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
29 changes: 27 additions & 2 deletions src/ansible/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ use evmlib::common::U256;
use log::{debug, error, trace};
use semver::Version;
use sn_service_management::NodeRegistry;
use std::{net::SocketAddr, path::PathBuf, time::{Instant, Duration}};
use std::{
net::SocketAddr,
path::PathBuf,
time::{Duration, Instant},
};
use walkdir::WalkDir;

use crate::ansible::extra_vars;
Expand Down Expand Up @@ -490,9 +494,30 @@ impl AnsibleProvisioner {
Ok(())
}

pub fn start_nodes(&self, interval: Duration) -> Result<()> {
pub fn start_nodes(
&self,
environment_name: &str,
interval: Duration,
custom_inventory: Option<Vec<VirtualMachine>>,
) -> Result<()> {
let mut extra_vars = ExtraVarsDocBuilder::default();
extra_vars.add_variable("interval", &interval.as_millis().to_string());

if let Some(custom_inventory) = custom_inventory {
println!("Running the start telegraf playbook with a custom inventory");
generate_custom_environment_inventory(
&custom_inventory,
environment_name,
&self.ansible_runner.working_directory_path.join("inventory"),
)?;
self.ansible_runner.run_playbook(
AnsiblePlaybook::StartNodes,
AnsibleInventoryType::Custom,
Some(extra_vars.build()),
)?;
return Ok(());
}

for node_inv_type in AnsibleInventoryType::iter_node_type() {
self.ansible_runner.run_playbook(
AnsiblePlaybook::StartNodes,
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,13 @@ impl TestnetDeployer {
Ok(())
}

pub fn start(&self, interval: Duration) -> Result<()> {
self.ansible_provisioner.start_nodes(interval)?;
pub fn start(
&self,
interval: Duration,
custom_inventory: Option<Vec<VirtualMachine>>,
) -> Result<()> {
self.ansible_provisioner
.start_nodes(&self.environment_name, interval, custom_inventory)?;
Ok(())
}

Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ enum Commands {
/// This can be useful if all nodes did not upgrade successfully.
#[clap(name = "start")]
Start {
/// Provide a list of VM names to use as a custom inventory.
///
/// This will start nodes on a particular subset of VMs.
#[clap(name = "custom-inventory", long, use_value_delimiter = true)]
custom_inventory: Option<Vec<String>>,
/// Maximum number of forks Ansible will use to execute tasks on target hosts.
#[clap(long, default_value_t = 50)]
forks: usize,
Expand Down Expand Up @@ -1978,6 +1983,7 @@ async fn main() -> Result<()> {
Ok(())
}
Commands::Start {
custom_inventory,
forks,
interval,
name,
Expand All @@ -2000,7 +2006,14 @@ async fn main() -> Result<()> {
return Err(eyre!("The {name} environment does not exist"));
}

testnet_deployer.start(interval)?;
let custom_inventory = if let Some(custom_inventory) = custom_inventory {
let custom_vms = get_custom_inventory(&inventory, &custom_inventory)?;
Some(custom_vms)
} else {
None
};

testnet_deployer.start(interval, custom_inventory)?;

Ok(())
}
Expand Down

0 comments on commit 756fc26

Please sign in to comment.