Skip to content
This repository has been archived by the owner on Nov 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #43 from vitorenesduarte/public_dns
Browse files Browse the repository at this point in the history
Set Machine's public_dns in AWS and private_ip in Azure
  • Loading branch information
jonhoo committed Jun 26, 2020
2 parents 17c5685 + 25ca609 commit 6808f93
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/launch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use color_eyre::Report;
use color_eyre::{eyre, Report};
use structopt::StructOpt;
use tsunami::Tsunami;

Expand Down
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ pub mod providers;
#[derive(Debug)]
struct MachineDescriptor<'tsunami> {
pub(crate) nickname: String,
pub(crate) public_dns: Option<String>,
pub(crate) public_ip: String,
pub(crate) private_ip: Option<String>,
pub(crate) public_dns: String,

// tie the lifetime of the machine to the Tsunami.
_tsunami: std::marker::PhantomData<&'tsunami ()>,
Expand All @@ -203,15 +203,15 @@ pub struct Machine<'tsunami> {
///
/// Corresponds to the name set in [`TsunamiBuilder::add`].
pub nickname: String,
/// The public IP address of the machine.
pub public_ip: String,
/// The private IP address of the machine, if available.
pub private_ip: Option<String>,
/// The public DNS name of the machine.
///
/// If the instance doesn't have a DNS name, this field will be
/// equivalent to `public_ip`.
pub public_dns: String,
/// The public IP address of the machine.
pub public_ip: String,
/// The private IP address of the machine, if available.
pub private_ip: Option<String>,

/// An established SSH session to this host.
pub ssh: openssh::Session,
Expand Down Expand Up @@ -251,11 +251,13 @@ impl<'t> MachineDescriptor<'t> {
let sess = sess.connect(&self.public_ip).await?;
tracing::trace!("connected");

let public_ip = self.public_ip;
Ok(Machine {
nickname: self.nickname,
public_ip: self.public_ip,
// if not defined, set public dns to be the public ip
public_dns: self.public_dns.unwrap_or_else(|| public_ip.clone()),
public_ip,
private_ip: self.private_ip,
public_dns: self.public_dns,
_tsunami: self._tsunami,
ssh: sess,
username: username.to_string(),
Expand Down
12 changes: 7 additions & 5 deletions src/providers/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,12 @@ impl RegionLauncher {
// try connecting. If can't, not ready.
let tag_setup = instances.get_mut(&instance_id).unwrap();

// no need to set public dns nor private ip since `connect_ssh` only uses the public ip
let m = crate::MachineDescriptor {
nickname: Default::default(),
public_dns: Default::default(),
public_ip: public_ip.to_string(),
private_ip: None,
private_ip: Default::default(),
_tsunami: Default::default(),
};

Expand All @@ -1092,8 +1093,8 @@ impl RegionLauncher {
tracing::debug!("instance ready");

tag_setup.ip_info = Some(IpInfo {
public_ip: public_ip.clone(),
public_dns: public_dns.clone(),
public_ip: public_ip.clone(),
private_ip: private_ip.clone(),
});
}
Expand Down Expand Up @@ -1130,9 +1131,9 @@ impl RegionLauncher {
},
)| {
let IpInfo {
public_dns,
public_ip,
private_ip,
..
} = ip_info.as_ref().unwrap();
let instance_span = tracing::debug_span!("instance", %instance_id, ip = %public_ip);
async move {
Expand All @@ -1144,8 +1145,9 @@ impl RegionLauncher {
{
super::setup_machine(
&name,
Some(&private_ip),
Some(&public_dns),
&public_ip,
Some(&private_ip),
&username,
max_wait,
Some(private_key_path.path()),
Expand Down Expand Up @@ -1184,8 +1186,8 @@ impl RegionLauncher {
}),
} => {
let m = crate::MachineDescriptor {
public_dns: Some(public_dns.clone()),
public_ip: public_ip.clone(),
public_dns: public_dns.clone(),
private_ip: Some(private_ip.clone()),
nickname: name.clone(),
_tsunami: Default::default(),
Expand Down
3 changes: 2 additions & 1 deletion src/providers/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ impl super::Launcher for RegionLauncher {
&nickname,
None,
&ipinfo.public_ip,
Some(&ipinfo.private_ip),
&username,
max_wait,
None,
Expand Down Expand Up @@ -424,7 +425,7 @@ impl super::Launcher for RegionLauncher {
} = desc;
let m = crate::MachineDescriptor {
nickname: name.clone(),
public_dns: public_ip.clone(),
public_dns: None,
public_ip: public_ip.clone(),
private_ip: Some(private_ip.clone()),
_tsunami: Default::default(),
Expand Down
6 changes: 3 additions & 3 deletions src/providers/baremetal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async fn try_addrs(

let m = crate::MachineDescriptor {
nickname: Default::default(),
public_dns: addr.ip().to_string(),
public_dns: None,
public_ip: addr.ip().to_string(),
private_ip: None,
_tsunami: Default::default(),
Expand Down Expand Up @@ -220,7 +220,7 @@ impl super::Launcher for Machine {
{
let m = crate::MachineDescriptor {
nickname: Default::default(),
public_dns: addr.ip().to_string(),
public_dns: None,
public_ip: addr.ip().to_string(),
private_ip: None,
_tsunami: Default::default(),
Expand Down Expand Up @@ -252,7 +252,7 @@ impl super::Launcher for Machine {
let addr = self.addr.ok_or_else(|| eyre!("Address uninitialized"))?;
let m = crate::MachineDescriptor {
nickname: self.name.clone(),
public_dns: addr.ip().to_string(),
public_dns: None,
public_ip: addr.ip().to_string(),
private_ip: None,
_tsunami: Default::default(),
Expand Down
11 changes: 6 additions & 5 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ fn rand_name_sep(prefix: &str, sep: impl Into<Sep>) -> String {
#[instrument(skip(max_wait, private_key, f))]
async fn setup_machine(
nickname: &str,
priv_ip: Option<&str>,
pub_ip: &str,
public_dns: Option<&str>,
public_ip: &str,
private_ip: Option<&str>,
username: &str,
max_wait: Option<std::time::Duration>,
private_key: Option<&std::path::Path>,
Expand All @@ -183,9 +184,9 @@ async fn setup_machine(
) -> Result<(), Report> {
let m = crate::MachineDescriptor {
nickname: Default::default(),
public_dns: pub_ip.to_string(),
public_ip: pub_ip.to_string(),
private_ip: priv_ip.map(String::from),
public_dns: public_dns.map(String::from),
public_ip: public_ip.to_string(),
private_ip: private_ip.map(String::from),
_tsunami: Default::default(),
};

Expand Down

0 comments on commit 6808f93

Please sign in to comment.