Skip to content

Commit

Permalink
Merge pull request #145 from jlebon/pr/fallback-hardcode
Browse files Browse the repository at this point in the history
azure: hardcode fallback for wireserver endpoint
  • Loading branch information
Luca Bruno committed Jan 14, 2019
2 parents 22078e9 + 8ae38a0 commit 8253c15
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/providers/azure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Content-Transfer-Encoding: base64
";

/// This is a known working wireserver endpoint within Azure.
/// See: https://blogs.msdn.microsoft.com/mast/2015/05/18/what-is-the-ip-address-168-63-129-16/
const FALLBACK_WIRESERVER_ADDR: [u8; 4] = [168, 63, 129, 16]; // for grep: 168.63.129.16

#[derive(Debug, Deserialize, Clone, Default)]
struct GoalState {
#[serde(rename = "Container")]
Expand Down Expand Up @@ -150,8 +154,7 @@ pub struct Azure {

impl Azure {
pub fn try_new() -> Result<Azure> {
let addr = Azure::get_fabric_address()
.chain_err(|| "failed to get fabric address")?;
let addr = Azure::get_fabric_address();
let client = retry::Client::try_new()?
.header(HeaderName::from_static(HDR_AGENT_NAME),
HeaderValue::from_static(MS_AGENT_NAME))
Expand Down Expand Up @@ -179,7 +182,16 @@ impl Azure {
.ok_or_else(|| "failed to get goal state: not found response".into())
}

fn get_fabric_address() -> Result<IpAddr> {
fn get_fabric_address() -> IpAddr {
// try to fetch from dhcp, else use fallback; this is similar to what WALinuxAgent does
Azure::get_fabric_address_from_dhcp().unwrap_or_else(|e| {
warn!("Failed to get fabric address from DHCP: {}", e);
info!("Using fallback address");
IpAddr::from(FALLBACK_WIRESERVER_ADDR)
})
}

fn get_fabric_address_from_dhcp() -> Result<IpAddr> {
let v = util::dns_lease_key_lookup(OPTION_245)?;
// value is an 8 digit hex value. convert it to u32 and
// then parse that into an ip. Ipv4Addr::from(u32)
Expand Down

0 comments on commit 8253c15

Please sign in to comment.