From 4959192ed242e8985881e2a6854376a45d355c26 Mon Sep 17 00:00:00 2001 From: Arthur Chaloin Date: Mon, 27 Nov 2023 12:08:32 +0000 Subject: [PATCH] refactor: proxmox -> proxmoxve --- docs/platforms.md | 2 +- docs/usage/attributes.md | 10 ++-- dracut/30afterburn/afterburn-hostname.service | 1 - src/metadata.rs | 4 +- src/providers/mod.rs | 2 +- .../{proxmox => proxmoxve}/cloudconfig.rs | 46 +++++++++---------- .../{proxmox => proxmoxve}/configdrive.rs | 16 +++---- src/providers/{proxmox => proxmoxve}/mod.rs | 0 src/providers/{proxmox => proxmoxve}/tests.rs | 20 ++++---- .../{proxmox => proxmoxve}/dhcp/meta-data | 0 .../dhcp/network-config | 0 .../{proxmox => proxmoxve}/dhcp/user-data | 0 .../{proxmox => proxmoxve}/dhcp/vendor-data | 0 .../{proxmox => proxmoxve}/static/meta-data | 0 .../static/network-config | 0 .../{proxmox => proxmoxve}/static/user-data | 0 .../{proxmox => proxmoxve}/static/vendor-data | 0 17 files changed, 50 insertions(+), 51 deletions(-) rename src/providers/{proxmox => proxmoxve}/cloudconfig.rs (85%) rename src/providers/{proxmox => proxmoxve}/configdrive.rs (77%) rename src/providers/{proxmox => proxmoxve}/mod.rs (100%) rename src/providers/{proxmox => proxmoxve}/tests.rs (87%) rename tests/fixtures/{proxmox => proxmoxve}/dhcp/meta-data (100%) rename tests/fixtures/{proxmox => proxmoxve}/dhcp/network-config (100%) rename tests/fixtures/{proxmox => proxmoxve}/dhcp/user-data (100%) rename tests/fixtures/{proxmox => proxmoxve}/dhcp/vendor-data (100%) rename tests/fixtures/{proxmox => proxmoxve}/static/meta-data (100%) rename tests/fixtures/{proxmox => proxmoxve}/static/network-config (100%) rename tests/fixtures/{proxmox => proxmoxve}/static/user-data (100%) rename tests/fixtures/{proxmox => proxmoxve}/static/vendor-data (100%) diff --git a/docs/platforms.md b/docs/platforms.md index 433e3f4a..53bee97a 100644 --- a/docs/platforms.md +++ b/docs/platforms.md @@ -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 diff --git a/docs/usage/attributes.md b/docs/usage/attributes.md index 1e392076..d6d030da 100644 --- a/docs/usage/attributes.md +++ b/docs/usage/attributes.md @@ -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 diff --git a/dracut/30afterburn/afterburn-hostname.service b/dracut/30afterburn/afterburn-hostname.service index 61acd128..e771d2b3 100644 --- a/dracut/30afterburn/afterburn-hostname.service +++ b/dracut/30afterburn/afterburn-hostname.service @@ -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 diff --git a/src/metadata.rs b/src/metadata.rs index 3bf957f3..3245999d 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -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; @@ -69,7 +69,7 @@ pub fn fetch_metadata(provider: &str) -> Result 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()?), diff --git a/src/providers/mod.rs b/src/providers/mod.rs index 975a5765..d74d0b98 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -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; diff --git a/src/providers/proxmox/cloudconfig.rs b/src/providers/proxmoxve/cloudconfig.rs similarity index 85% rename from src/providers/proxmox/cloudconfig.rs rename to src/providers/proxmoxve/cloudconfig.rs index 43af3488..0e874a88 100644 --- a/src/providers/proxmox/cloudconfig.rs +++ b/src/providers/proxmoxve/cloudconfig.rs @@ -17,25 +17,25 @@ 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, pub package_upgrade: bool, #[serde(default)] @@ -43,21 +43,21 @@ pub struct ProxmoxCloudUserData { } #[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, + pub config: Vec, } #[derive(Debug, Deserialize)] -pub struct ProxmoxCloudNetworkConfigEntry { +pub struct ProxmoxVECloudNetworkConfigEntry { #[serde(rename = "type")] pub network_type: String, pub name: Option, @@ -67,11 +67,11 @@ pub struct ProxmoxCloudNetworkConfigEntry { #[serde(default)] pub search: Vec, #[serde(default)] - pub subnets: Vec, + pub subnets: Vec, } #[derive(Debug, Deserialize)] -pub struct ProxmoxCloudNetworkConfigSubnet { +pub struct ProxmoxVECloudNetworkConfigSubnet { #[serde(rename = "type")] pub subnet_type: String, pub address: Option, @@ -79,7 +79,7 @@ pub struct ProxmoxCloudNetworkConfigSubnet { pub gateway: Option, } -impl ProxmoxCloudConfig { +impl ProxmoxVECloudConfig { pub fn try_new(path: &Path) -> Result { Ok(Self { meta_data: serde_yaml::from_reader(File::open(path.join("meta-data"))?)?, @@ -90,17 +90,17 @@ impl ProxmoxCloudConfig { } } -impl MetadataProvider for ProxmoxCloudConfig { +impl MetadataProvider for ProxmoxVECloudConfig { fn attributes(&self) -> Result> { 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(), ); @@ -108,13 +108,13 @@ impl MetadataProvider for ProxmoxCloudConfig { 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(), ); } @@ -169,7 +169,7 @@ impl MetadataProvider for ProxmoxCloudConfig { } } -impl ProxmoxCloudNetworkConfigEntry { +impl ProxmoxVECloudNetworkConfigEntry { pub fn to_interface(&self) -> Result { if self.network_type != "physical" { return Err(anyhow::anyhow!( @@ -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 diff --git a/src/providers/proxmox/configdrive.rs b/src/providers/proxmoxve/configdrive.rs similarity index 77% rename from src/providers/proxmox/configdrive.rs rename to src/providers/proxmoxve/configdrive.rs index 4a6b6246..8e61121d 100644 --- a/src/providers/proxmox/configdrive.rs +++ b/src/providers/proxmoxve/configdrive.rs @@ -1,4 +1,4 @@ -use super::ProxmoxCloudConfig; +use super::ProxmoxVECloudConfig; use crate::{network, providers::MetadataProvider}; use anyhow::{Context, Result}; use openssh_keys::PublicKey; @@ -6,12 +6,12 @@ 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 { const CONFIG_DRIVE_LABEL: &str = "cidata"; const TARGET_FS: &str = "iso9660"; @@ -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> { self.config.hostname() } @@ -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); }; } } diff --git a/src/providers/proxmox/mod.rs b/src/providers/proxmoxve/mod.rs similarity index 100% rename from src/providers/proxmox/mod.rs rename to src/providers/proxmoxve/mod.rs diff --git a/src/providers/proxmox/tests.rs b/src/providers/proxmoxve/tests.rs similarity index 87% rename from src/providers/proxmox/tests.rs rename to src/providers/proxmoxve/tests.rs index 1b6774d2..8a885e8c 100644 --- a/src/providers/proxmox/tests.rs +++ b/src/providers/proxmoxve/tests.rs @@ -1,4 +1,4 @@ -use super::ProxmoxCloudConfig; +use super::ProxmoxVECloudConfig; use crate::{ network::{self, NetworkRoute}, providers::MetadataProvider, @@ -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!( @@ -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 dummy@dummy.local").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!( @@ -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!( @@ -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!( diff --git a/tests/fixtures/proxmox/dhcp/meta-data b/tests/fixtures/proxmoxve/dhcp/meta-data similarity index 100% rename from tests/fixtures/proxmox/dhcp/meta-data rename to tests/fixtures/proxmoxve/dhcp/meta-data diff --git a/tests/fixtures/proxmox/dhcp/network-config b/tests/fixtures/proxmoxve/dhcp/network-config similarity index 100% rename from tests/fixtures/proxmox/dhcp/network-config rename to tests/fixtures/proxmoxve/dhcp/network-config diff --git a/tests/fixtures/proxmox/dhcp/user-data b/tests/fixtures/proxmoxve/dhcp/user-data similarity index 100% rename from tests/fixtures/proxmox/dhcp/user-data rename to tests/fixtures/proxmoxve/dhcp/user-data diff --git a/tests/fixtures/proxmox/dhcp/vendor-data b/tests/fixtures/proxmoxve/dhcp/vendor-data similarity index 100% rename from tests/fixtures/proxmox/dhcp/vendor-data rename to tests/fixtures/proxmoxve/dhcp/vendor-data diff --git a/tests/fixtures/proxmox/static/meta-data b/tests/fixtures/proxmoxve/static/meta-data similarity index 100% rename from tests/fixtures/proxmox/static/meta-data rename to tests/fixtures/proxmoxve/static/meta-data diff --git a/tests/fixtures/proxmox/static/network-config b/tests/fixtures/proxmoxve/static/network-config similarity index 100% rename from tests/fixtures/proxmox/static/network-config rename to tests/fixtures/proxmoxve/static/network-config diff --git a/tests/fixtures/proxmox/static/user-data b/tests/fixtures/proxmoxve/static/user-data similarity index 100% rename from tests/fixtures/proxmox/static/user-data rename to tests/fixtures/proxmoxve/static/user-data diff --git a/tests/fixtures/proxmox/static/vendor-data b/tests/fixtures/proxmoxve/static/vendor-data similarity index 100% rename from tests/fixtures/proxmox/static/vendor-data rename to tests/fixtures/proxmoxve/static/vendor-data