Skip to content

Commit

Permalink
refactor: proxmox -> proxmoxve
Browse files Browse the repository at this point in the history
  • Loading branch information
arcln committed Nov 27, 2023
1 parent 0c1fe0c commit 4959192
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The following platforms are supported, with a different set of features availabl
* powervs
- Attributes
- SSH keys
* proxmox
* proxmoxve
- Attributes
- Hostname
- SSH keys
Expand Down
10 changes: 5 additions & 5 deletions docs/usage/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ Cloud providers with supported metadata endpoints and their respective attribute
* powervs
- AFTERBURN_POWERVS_INSTANCE_ID
- AFTERBURN_POWERVS_LOCAL_HOSTNAME
* proxmox
- AFTERBURN_PROXMOX_HOSTNAME
- AFTERBURN_PROXMOX_INSTANCE_ID
- AFTERBURN_PROXMOX_IPV4
- AFTERBURN_PROXMOX_IPV6
* proxmoxve
- AFTERBURN_PROXMOXVE_HOSTNAME
- AFTERBURN_PROXMOXVE_INSTANCE_ID
- AFTERBURN_PROXMOXVE_IPV4
- AFTERBURN_PROXMOXVE_IPV6
* scaleway
- AFTERBURN_SCALEWAY_HOSTNAME
- AFTERBURN_SCALEWAY_INSTANCE_ID
Expand Down
1 change: 0 additions & 1 deletion dracut/30afterburn/afterburn-hostname.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ConditionKernelCommandLine=|ignition.platform.id=digitalocean
ConditionKernelCommandLine=|ignition.platform.id=exoscale
ConditionKernelCommandLine=|ignition.platform.id=hetzner
ConditionKernelCommandLine=|ignition.platform.id=ibmcloud
ConditionKernelCommandLine=|ignition.platform.id=proxmox
ConditionKernelCommandLine=|ignition.platform.id=scaleway
ConditionKernelCommandLine=|ignition.platform.id=vultr

Expand Down
4 changes: 2 additions & 2 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::providers::openstack;
use crate::providers::openstack::network::OpenstackProviderNetwork;
use crate::providers::packet::PacketProvider;
use crate::providers::powervs::PowerVSProvider;
use crate::providers::proxmox::ProxmoxConfigDrive;
use crate::providers::proxmoxve::ProxmoxVEConfigDrive;
use crate::providers::scaleway::ScalewayProvider;
use crate::providers::vmware::VmwareProvider;
use crate::providers::vultr::VultrProvider;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn fetch_metadata(provider: &str) -> Result<Box<dyn providers::MetadataProvi
"openstack-metadata" => box_result!(OpenstackProviderNetwork::try_new()?),
"packet" => box_result!(PacketProvider::try_new()?),
"powervs" => box_result!(PowerVSProvider::try_new()?),
"proxmox" => box_result!(ProxmoxConfigDrive::try_new()?),
"proxmoxve" => box_result!(ProxmoxVEConfigDrive::try_new()?),
"scaleway" => box_result!(ScalewayProvider::try_new()?),
"vmware" => box_result!(VmwareProvider::try_new()?),
"vultr" => box_result!(VultrProvider::try_new()?),
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod microsoft;
pub mod openstack;
pub mod packet;
pub mod powervs;
pub mod proxmox;
pub mod proxmoxve;
pub mod scaleway;
pub mod vmware;
pub mod vultr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@ use std::{
};

#[derive(Debug)]
pub struct ProxmoxCloudConfig {
pub meta_data: ProxmoxCloudMetaData,
pub user_data: ProxmoxCloudUserData,
pub vendor_data: ProxmoxCloudVendorData,
pub network_config: ProxmoxCloudNetworkConfig,
pub struct ProxmoxVECloudConfig {
pub meta_data: ProxmoxVECloudMetaData,
pub user_data: ProxmoxVECloudUserData,
pub vendor_data: ProxmoxVECloudVendorData,
pub network_config: ProxmoxVECloudNetworkConfig,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudMetaData {
pub struct ProxmoxVECloudMetaData {
#[serde(rename = "instance-id")]
pub instance_id: String,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudUserData {
pub struct ProxmoxVECloudUserData {
pub hostname: String,
pub manage_etc_hosts: bool,
pub fqdn: String,
pub chpasswd: ProxmoxCloudChpasswdConfig,
pub chpasswd: ProxmoxVECloudChpasswdConfig,
pub users: Vec<String>,
pub package_upgrade: bool,
#[serde(default)]
pub ssh_authorized_keys: Vec<String>,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudChpasswdConfig {
pub struct ProxmoxVECloudChpasswdConfig {
pub expire: bool,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudVendorData {}
pub struct ProxmoxVECloudVendorData {}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudNetworkConfig {
pub struct ProxmoxVECloudNetworkConfig {
pub version: u32,
pub config: Vec<ProxmoxCloudNetworkConfigEntry>,
pub config: Vec<ProxmoxVECloudNetworkConfigEntry>,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudNetworkConfigEntry {
pub struct ProxmoxVECloudNetworkConfigEntry {
#[serde(rename = "type")]
pub network_type: String,
pub name: Option<String>,
Expand All @@ -67,19 +67,19 @@ pub struct ProxmoxCloudNetworkConfigEntry {
#[serde(default)]
pub search: Vec<String>,
#[serde(default)]
pub subnets: Vec<ProxmoxCloudNetworkConfigSubnet>,
pub subnets: Vec<ProxmoxVECloudNetworkConfigSubnet>,
}

#[derive(Debug, Deserialize)]
pub struct ProxmoxCloudNetworkConfigSubnet {
pub struct ProxmoxVECloudNetworkConfigSubnet {
#[serde(rename = "type")]
pub subnet_type: String,
pub address: Option<String>,
pub netmask: Option<String>,
pub gateway: Option<String>,
}

impl ProxmoxCloudConfig {
impl ProxmoxVECloudConfig {
pub fn try_new(path: &Path) -> Result<Self> {
Ok(Self {
meta_data: serde_yaml::from_reader(File::open(path.join("meta-data"))?)?,
Expand All @@ -90,31 +90,31 @@ impl ProxmoxCloudConfig {
}
}

impl MetadataProvider for ProxmoxCloudConfig {
impl MetadataProvider for ProxmoxVECloudConfig {
fn attributes(&self) -> Result<HashMap<String, String>> {
let mut out = HashMap::new();

out.insert(
"AFTERBURN_PROXMOX_HOSTNAME".to_owned(),
"AFTERBURN_PROXMOXVE_HOSTNAME".to_owned(),
self.hostname()?.unwrap_or_default(),
);

out.insert(
"AFTERBURN_PROXMOX_INSTANCE_ID".to_owned(),
"AFTERBURN_PROXMOXVE_INSTANCE_ID".to_owned(),
self.meta_data.instance_id.clone(),
);

if let Some(first_interface) = self.networks()?.first() {
first_interface.ip_addresses.iter().for_each(|ip| match ip {
IpNetwork::V4(network) => {
out.insert(
"AFTERBURN_PROXMOX_IPV4".to_owned(),
"AFTERBURN_PROXMOXVE_IPV4".to_owned(),
network.ip().to_string(),
);
}
IpNetwork::V6(network) => {
out.insert(
"AFTERBURN_PROXMOX_IPV6".to_owned(),
"AFTERBURN_PROXMOXVE_IPV6".to_owned(),
network.ip().to_string(),
);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ impl MetadataProvider for ProxmoxCloudConfig {
}
}

impl ProxmoxCloudNetworkConfigEntry {
impl ProxmoxVECloudNetworkConfigEntry {
pub fn to_interface(&self) -> Result<network::Interface> {
if self.network_type != "physical" {
return Err(anyhow::anyhow!(
Expand All @@ -190,7 +190,7 @@ impl ProxmoxCloudNetworkConfigEntry {
// filled below because Option::try_map doesn't exist yet
mac_address: None,

// unsupported by proxmox
// unsupported by proxmox ve
bond: None,

// default values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use super::ProxmoxCloudConfig;
use super::ProxmoxVECloudConfig;
use crate::{network, providers::MetadataProvider};
use anyhow::{Context, Result};
use openssh_keys::PublicKey;
use slog_scope::error;
use std::path::{Path, PathBuf};

#[derive(Debug)]
pub struct ProxmoxConfigDrive {
pub struct ProxmoxVEConfigDrive {
mount_path: PathBuf,
config: ProxmoxCloudConfig,
config: ProxmoxVECloudConfig,
}

impl ProxmoxConfigDrive {
impl ProxmoxVEConfigDrive {
pub fn try_new() -> Result<Self> {
const CONFIG_DRIVE_LABEL: &str = "cidata";
const TARGET_FS: &str = "iso9660";
Expand All @@ -30,13 +30,13 @@ impl ProxmoxConfigDrive {

let mount_path = target.path().to_owned();
Ok(Self {
config: ProxmoxCloudConfig::try_new(&mount_path)?,
config: ProxmoxVECloudConfig::try_new(&mount_path)?,
mount_path,
})
}
}

impl MetadataProvider for ProxmoxConfigDrive {
impl MetadataProvider for ProxmoxVEConfigDrive {
fn hostname(&self) -> Result<Option<String>> {
self.config.hostname()
}
Expand All @@ -50,10 +50,10 @@ impl MetadataProvider for ProxmoxConfigDrive {
}
}

impl Drop for ProxmoxConfigDrive {
impl Drop for ProxmoxVEConfigDrive {
fn drop(&mut self) {
if let Err(e) = crate::util::unmount(&self.mount_path, 3) {
error!("failed to cleanup Proxmox config-drive: {:?}", e);
error!("failed to cleanup Proxmox VE config-drive: {:?}", e);
};
}
}
File renamed without changes.
20 changes: 10 additions & 10 deletions src/providers/proxmox/tests.rs → src/providers/proxmoxve/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::ProxmoxCloudConfig;
use super::ProxmoxVECloudConfig;
use crate::{
network::{self, NetworkRoute},
providers::MetadataProvider,
Expand All @@ -10,34 +10,34 @@ use std::{net::IpAddr, path::Path, str::FromStr};

#[test]
fn test_attributes() {
let config = ProxmoxCloudConfig::try_new(Path::new("tests/fixtures/proxmox/static"))
let config = ProxmoxVECloudConfig::try_new(Path::new("tests/fixtures/proxmoxve/static"))
.expect("cannot parse config");
let attributes = config.attributes().expect("cannot get hostname");

assert_eq!(
attributes["AFTERBURN_PROXMOX_HOSTNAME"],
attributes["AFTERBURN_PROXMOXVE_HOSTNAME"],
"dummy".to_string()
);

assert_eq!(
attributes["AFTERBURN_PROXMOX_INSTANCE_ID"],
attributes["AFTERBURN_PROXMOXVE_INSTANCE_ID"],
"15a9919cb91024fbd1d70fa07f0efa749cbba03b".to_string()
);

assert_eq!(
attributes["AFTERBURN_PROXMOX_IPV4"],
attributes["AFTERBURN_PROXMOXVE_IPV4"],
"192.168.1.1".to_string()
);

assert_eq!(
attributes["AFTERBURN_PROXMOX_IPV6"],
attributes["AFTERBURN_PROXMOXVE_IPV6"],
"2001:db8:85a3::8a2e:370:0".to_string()
);
}

#[test]
fn test_hostname() {
let config = ProxmoxCloudConfig::try_new(Path::new("tests/fixtures/proxmox/dhcp"))
let config = ProxmoxVECloudConfig::try_new(Path::new("tests/fixtures/proxmoxve/dhcp"))
.expect("cannot parse config");

assert_eq!(
Expand All @@ -49,7 +49,7 @@ fn test_hostname() {
#[test]
fn test_ssh_keys() {
let test_ssh_key = PublicKey::from_str("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDd1hElre4j44sbmULXyO5j6dRnkRFCMjEGtRSy2SuvFD8WyB5uectcEMvz7ORhQIVbPlz94wFjpSX5wl/gmSKL/7GOyerJo0Y2cvyjJJahuDn+JnIL0tT0HS1pJ5iJqQpxXeOAzMK5Heum+uGw9BzbiUHnRzjJr8Ltx4CAGMfubevD4SX32Q8BTQiaU4ZnGtdHo16pWwRsq1f6/UtL4gDCni9vm8QmmGDRloi/pBn1csjKw+volFyu/kSEmGLWow6NuT6TrhGAbMKas5HfYq0Mn3LGPZL7XjqJQ6CO0TzkG/BNplZT2tiwHtsvXsbePTp4ZUi4dkCMz2xR4eikaI1V [email protected]").unwrap();
let config = ProxmoxCloudConfig::try_new(Path::new("tests/fixtures/proxmox/dhcp"))
let config = ProxmoxVECloudConfig::try_new(Path::new("tests/fixtures/proxmoxve/dhcp"))
.expect("cannot parse config");

assert_eq!(
Expand All @@ -60,7 +60,7 @@ fn test_ssh_keys() {

#[test]
fn test_network_dhcp() {
let config = ProxmoxCloudConfig::try_new(Path::new("tests/fixtures/proxmox/dhcp"))
let config = ProxmoxVECloudConfig::try_new(Path::new("tests/fixtures/proxmoxve/dhcp"))
.expect("cannot parse config");

assert_eq!(
Expand All @@ -85,7 +85,7 @@ fn test_network_dhcp() {

#[test]
fn test_network_static() {
let config = ProxmoxCloudConfig::try_new(Path::new("tests/fixtures/proxmox/static"))
let config = ProxmoxVECloudConfig::try_new(Path::new("tests/fixtures/proxmoxve/static"))
.expect("cannot parse config");

assert_eq!(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4959192

Please sign in to comment.