Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

providers: add an AzureStack stub #463

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::providers;
use crate::providers::aliyun::AliyunProvider;
use crate::providers::aws::AwsProvider;
use crate::providers::azure::Azure;
use crate::providers::azurestack::AzureStack;
use crate::providers::cloudstack::configdrive::ConfigDrive;
use crate::providers::cloudstack::network::CloudstackNetwork;
use crate::providers::digitalocean::DigitalOceanProvider;
Expand Down Expand Up @@ -48,6 +49,7 @@ pub fn fetch_metadata(provider: &str) -> errors::Result<Box<dyn providers::Metad
#[cfg(not(feature = "cl-legacy"))]
"aws" => box_result!(AwsProvider::try_new()?),
"azure" => box_result!(Azure::try_new()?),
"azurestack" => box_result!(AzureStack::new()),
"cloudstack-metadata" => box_result!(CloudstackNetwork::try_new()?),
"cloudstack-configdrive" => box_result!(ConfigDrive::try_new()?),
"digitalocean" => box_result!(DigitalOceanProvider::try_new()?),
Expand Down
17 changes: 1 addition & 16 deletions src/providers/aliyun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#[cfg(test)]
use mockito;
use openssh_keys::PublicKey;
use slog_scope::{error, warn};
use slog_scope::error;
use std::collections::{BTreeSet, HashMap};

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;

Expand Down Expand Up @@ -172,18 +171,4 @@ impl MetadataProvider for AliyunProvider {

Ok(out)
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
15 changes: 0 additions & 15 deletions src/providers/aws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use serde_derive::Deserialize;
use slog_scope::warn;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;

Expand Down Expand Up @@ -234,18 +233,4 @@ impl MetadataProvider for AwsProvider {
.collect::<Result<Vec<_>>>()
})?
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
10 changes: 0 additions & 10 deletions src/providers/azure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use slog_scope::warn;

use self::crypto::x509;
use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;

Expand Down Expand Up @@ -505,15 +504,6 @@ impl MetadataProvider for Azure {
Ok(vec![key])
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
let body = ready_state!(self.container_id(), self.instance_id()?);
let url = self.fabric_base_url() + "/machine/?comp=health";
Expand Down
33 changes: 33 additions & 0 deletions src/providers/azurestack/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This is a stub provider. Right now the AzureStack provider does
// asbolutely nothing interesting.

//! azurestack/azurestack metadata fetcher
use crate::providers::MetadataProvider;

use slog_scope::debug;

#[derive(Clone, Copy, Debug)]
pub struct AzureStack;

impl AzureStack {
pub fn new() -> Self {
debug!("azure stack provider is a noop stub");
Self
}
}

impl MetadataProvider for AzureStack{}
21 changes: 1 addition & 20 deletions src/providers/cloudstack/configdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::io::Read;
use std::path::{Path, PathBuf};

use openssh_keys::PublicKey;
use slog_scope::{error, warn};
use slog_scope::error;
use tempfile::TempDir;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;

const CONFIG_DRIVE_LABEL_1: &str = "config-2";
Expand Down Expand Up @@ -124,27 +123,9 @@ impl MetadataProvider for ConfigDrive {
Ok(out)
}

fn hostname(&self) -> Result<Option<String>> {
Ok(None)
}

fn ssh_keys(&self) -> Result<Vec<PublicKey>> {
self.fetch_publickeys()
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}

impl Drop for ConfigDrive {
Expand Down
16 changes: 0 additions & 16 deletions src/providers/cloudstack/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use std::collections::HashMap;
use std::net::IpAddr;

use openssh_keys::PublicKey;
use slog_scope::warn;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;
use crate::util;
Expand Down Expand Up @@ -94,18 +92,4 @@ impl MetadataProvider for CloudstackNetwork {
Ok(vec![])
}
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
11 changes: 0 additions & 11 deletions src/providers/digitalocean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
use openssh_keys::PublicKey;
use pnet_base::MacAddr;
use serde_derive::Deserialize;
use slog_scope::warn;

use crate::errors::*;
use crate::network;
Expand Down Expand Up @@ -293,14 +292,4 @@ impl MetadataProvider for DigitalOceanProvider {
fn networks(&self) -> Result<Vec<network::Interface>> {
self.parse_network()
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
16 changes: 0 additions & 16 deletions src/providers/exoscale/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
use std::collections::HashMap;

use openssh_keys::PublicKey;
use slog_scope::warn;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;

Expand Down Expand Up @@ -106,18 +104,4 @@ impl MetadataProvider for ExoscaleProvider {
.map(|s| PublicKey::read_keys(s.as_bytes()))
.unwrap_or_else(|| Ok(vec![]))?)
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
16 changes: 0 additions & 16 deletions src/providers/gcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
use mockito;
use openssh_keys::PublicKey;
use reqwest::header::{HeaderName, HeaderValue};
use slog_scope::warn;
use std::collections::HashMap;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;
use crate::retry;

Expand Down Expand Up @@ -189,18 +187,4 @@ impl MetadataProvider for GcpProvider {

Ok(out)
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}
23 changes: 0 additions & 23 deletions src/providers/ibmcloud/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ use std::fs::File;
use std::io::{BufRead, BufReader, Read};
use std::path::{Path, PathBuf};

use openssh_keys::PublicKey;
use slog_scope::warn;
use tempfile::TempDir;

use crate::errors::*;
use crate::network;
use crate::providers::MetadataProvider;

const CONFIG_DRIVE_LABEL: &str = "cidata";
Expand Down Expand Up @@ -126,26 +123,6 @@ impl MetadataProvider for IBMGen2Provider {
let hostname = metadata.get("local-hostname").map(String::from);
Ok(hostname)
}

fn ssh_keys(&self) -> Result<Vec<PublicKey>> {
warn!("cloud SSH keys requested, but not supported on this platform");
Ok(vec![])
}

fn networks(&self) -> Result<Vec<network::Interface>> {
warn!("network metadata requested, but not supported on this platform");
Ok(vec![])
}

fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
warn!("virtual network devices metadata requested, but not supported on this platform");
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}
}

impl Drop for IBMGen2Provider {
Expand Down
32 changes: 26 additions & 6 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
pub mod aliyun;
pub mod aws;
pub mod azure;
pub mod azurestack;
pub mod cloudstack;
pub mod digitalocean;
pub mod exoscale;
Expand Down Expand Up @@ -195,19 +196,38 @@ fn write_ssh_keys(user: User, ssh_keys: Vec<PublicKey>) -> Result<()> {
}

pub trait MetadataProvider {
fn attributes(&self) -> Result<HashMap<String, String>>;
fn hostname(&self) -> Result<Option<String>>;
fn ssh_keys(&self) -> Result<Vec<PublicKey>>;
fn networks(&self) -> Result<Vec<network::Interface>>;
fn boot_checkin(&self) -> Result<()>;
fn attributes(&self) -> Result<HashMap<String, String>> {
let attributes = maplit::hashmap! { };
Ok(attributes)
}

fn hostname(&self) -> Result<Option<String>> {
Ok(None)
}

fn ssh_keys(&self) -> Result<Vec<PublicKey>> {
warn!("ssh-keys requested, but not supported on this platform");
Ok(vec![])
}

fn networks(&self) -> Result<Vec<network::Interface>> {
Ok(vec![])
}

fn boot_checkin(&self) -> Result<()> {
warn!("boot check-in requested, but not supported on this platform");
Ok(())
}

/// Return a list of virtual network devices for this machine.
///
/// This is used to setup virtual interfaces, e.g. via [systemd.netdev][netdev]
/// configuration fragments.
///
/// netdev: https://www.freedesktop.org/software/systemd/man/systemd.netdev.html
fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>>;
fn virtual_network_devices(&self) -> Result<Vec<network::VirtualNetDev>> {
Ok(vec![])
}

/// Return custom initrd network kernel arguments, if any.
fn rd_network_kargs(&self) -> Result<Option<String>> {
Expand Down
Loading