-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/stakwork/sphinx-swarm
- Loading branch information
Showing
9 changed files
with
172 additions
and
52 deletions.
There are no files selected for viewing
52 changes: 26 additions & 26 deletions
52
app/dist/assets/index-4b30c25b.js → app/dist/assets/index-9ca5ffe9.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use anyhow::Error; | ||
use aws_config::meta::region::RegionProviderChain; | ||
use aws_config::Region; | ||
use aws_sdk_ec2::Client; | ||
use aws_smithy_types::retry::RetryConfig; | ||
use sphinx_swarm::utils::getenv; | ||
|
||
pub async fn make_aws_client() -> Result<Client, Error> { | ||
let region = getenv("AWS_S3_REGION_NAME")?; | ||
let region_provider = RegionProviderChain::first_try(Some(Region::new(region))); | ||
let config = aws_config::from_env() | ||
.region(region_provider) | ||
.retry_config(RetryConfig::standard().with_max_attempts(10)) | ||
.load() | ||
.await; | ||
|
||
Ok(Client::new(&config)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{aws_util::make_aws_client, state::InstanceFromAws}; | ||
use anyhow::{anyhow, Error}; | ||
use aws_sdk_ec2::types::Filter; | ||
|
||
pub async fn get_swarms_by_tag(key: &str, value: &str) -> Result<Vec<InstanceFromAws>, Error> { | ||
let client = make_aws_client().await?; | ||
|
||
let mut instances: Vec<InstanceFromAws> = vec![]; | ||
|
||
let tag_filter = Filter::builder() | ||
.name(format!("tag:{}", key)) | ||
.values(format!("{}", value)) | ||
.build(); | ||
|
||
let response = client | ||
.describe_instances() | ||
.filters(tag_filter) | ||
.send() | ||
.await?; | ||
|
||
if response.reservations().is_empty() { | ||
log::error!("No instances found with the given tag."); | ||
return Err(anyhow!("No instances found with the given tag.")); | ||
} | ||
|
||
for reservation in response.reservations.unwrap() { | ||
if !reservation.instances().is_empty() { | ||
for instance in reservation.instances.unwrap() { | ||
if instance.public_ip_address.is_some() | ||
&& instance.instance_id.is_some() | ||
&& instance.instance_type.is_some() | ||
{ | ||
instances.push(InstanceFromAws { | ||
instacne_id: instance.instance_id.unwrap(), | ||
intance_type: instance.instance_type.unwrap().to_string(), | ||
}); | ||
} | ||
} | ||
} else { | ||
log::error!("Instances do not exist") | ||
} | ||
} | ||
|
||
return Ok(instances); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters