Skip to content
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
26 changes: 22 additions & 4 deletions lib/bolt/cli/src/commands/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum SubCommand {
Pool {
#[clap(index = 1)]
pool: String,
#[clap(long, short = 'r')]
region: Option<String>,
#[clap(index = 2)]
command: Option<String>,
#[clap(short = 'a', long)]
Expand Down Expand Up @@ -57,13 +59,29 @@ impl SubCommand {
bolt_core::tasks::ssh::name(&ctx, &name, command.as_ref().map(String::as_str))
.await?;
}
Self::Pool { pool, command, all } => {
Self::Pool {
pool,
region,
command,
all,
} => {
if all {
let command = command.context("must provide command with --all")?;
bolt_core::tasks::ssh::pool_all(&ctx, &pool, &command).await?;
bolt_core::tasks::ssh::pool_all(
&ctx,
&pool,
region.as_ref().map(String::as_str),
&command,
)
.await?;
} else {
bolt_core::tasks::ssh::pool(&ctx, &pool, command.as_ref().map(String::as_str))
.await?;
bolt_core::tasks::ssh::pool(
&ctx,
&pool,
region.as_ref().map(String::as_str),
command.as_ref().map(String::as_str),
)
.await?;
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions lib/bolt/core/src/tasks/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ pub async fn name(ctx: &ProjectContext, name: &str, command: Option<&str>) -> Re
Ok(())
}

pub async fn pool(ctx: &ProjectContext, pool: &str, command: Option<&str>) -> Result<()> {
pub async fn pool(
ctx: &ProjectContext,
pool: &str,
region: Option<&str>,
command: Option<&str>,
) -> Result<()> {
// Choose IP
let tf_pools = terraform::output::read_pools(&ctx).await;
let server = tf_pools
.servers
.value
.into_iter()
.map(|x| x.1)
.find(|x| x.pool_id == pool)
.find(|x| x.pool_id == pool && region.map(|r| &x.region_id == r).unwrap_or(true))
.expect("failed to find server pool");

let ssh_key = TempSshKey::new(&ctx, "server").await?;
Expand All @@ -85,7 +90,12 @@ pub async fn pool(ctx: &ProjectContext, pool: &str, command: Option<&str>) -> Re
Ok(())
}

pub async fn pool_all(ctx: &ProjectContext, pool: &str, command: &str) -> Result<()> {
pub async fn pool_all(
ctx: &ProjectContext,
pool: &str,
region: Option<&str>,
command: &str,
) -> Result<()> {
let ssh_key = Arc::new(TempSshKey::new(&ctx, "server").await?);

let tf_pools = terraform::output::read_pools(&ctx).await;
Expand All @@ -95,7 +105,7 @@ pub async fn pool_all(ctx: &ProjectContext, pool: &str, command: &str) -> Result
.servers
.value
.into_iter()
.filter(|x| x.1.pool_id == pool),
.filter(|x| x.1.pool_id == pool && region.map(|r| &x.1.region_id == r).unwrap_or(true)),
)
.map(|(name, server)| {
let ctx = ctx.clone();
Expand Down