Skip to content

Commit

Permalink
proxmoxve: implement proxmoxve provider
Browse files Browse the repository at this point in the history
allow reading cloud-init drive from proxmoxve. supports writing hostname, sshkeys and networkd configuration.
  • Loading branch information
arcln committed Jun 19, 2024
1 parent a9a70f2 commit a92c78d
Show file tree
Hide file tree
Showing 27 changed files with 707 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ The following platforms are supported, with a different set of features availabl
* powervs
- Attributes
- SSH keys
* proxmoxve
- Attributes
- Hostname
- SSH keys
- Network configuration
* scaleway
- Attributes
- Boot check-in
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ nav_order: 8

Major changes:

- Add support for Proxmox VE

Minor changes:

Packaging changes:
Expand Down
5 changes: 5 additions & 0 deletions docs/usage/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ Cloud providers with supported metadata endpoints and their respective attribute
* powervs
- AFTERBURN_POWERVS_INSTANCE_ID
- AFTERBURN_POWERVS_LOCAL_HOSTNAME
* 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: 1 addition & 0 deletions dracut/30afterburn/afterburn-hostname.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ConditionKernelCommandLine=|ignition.platform.id=exoscale
ConditionKernelCommandLine=|ignition.platform.id=hetzner
ConditionKernelCommandLine=|ignition.platform.id=ibmcloud
ConditionKernelCommandLine=|ignition.platform.id=kubevirt
ConditionKernelCommandLine=|ignition.platform.id=proxmoxve
ConditionKernelCommandLine=|ignition.platform.id=scaleway
ConditionKernelCommandLine=|ignition.platform.id=vultr

Expand Down
2 changes: 2 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::providers::openstack;
use crate::providers::openstack::network::OpenstackProviderNetwork;
use crate::providers::packet::PacketProvider;
use crate::providers::powervs::PowerVSProvider;
use crate::providers::proxmoxve::ProxmoxVEConfigDrive;
use crate::providers::scaleway::ScalewayProvider;
use crate::providers::vmware::VmwareProvider;
use crate::providers::vultr::VultrProvider;
Expand Down Expand Up @@ -70,6 +71,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()?),
"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
62 changes: 62 additions & 0 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct Interface {
pub priority: u8,
pub nameservers: Vec<IpAddr>,
pub ip_addresses: Vec<IpNetwork>,
// Optionally enable DHCP
pub dhcp: Option<DhcpSetting>,
pub routes: Vec<NetworkRoute>,
pub bond: Option<String>,
pub unmanaged: bool,
Expand Down Expand Up @@ -128,6 +130,31 @@ impl NetDevKind {
}
}

/// Optional use of DHCP.
#[allow(dead_code)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DhcpSetting {
Both,
V4,
V6,
}

impl DhcpSetting {
/// Return DHCP setting according to `systemd.network`
///
/// See [systemd documentation](dhcp) for the full list.
///
/// dhcp: https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#DHCP=
fn sd_dhcp_setting(&self) -> String {
let setting = match *self {
DhcpSetting::Both => "yes",
DhcpSetting::V4 => "ipv4",
DhcpSetting::V6 => "ipv6",
};
setting.to_string()
}
}

impl Interface {
/// Return a deterministic `systemd.network` unit name for this device.
pub fn sd_network_unit_name(&self) -> Result<String> {
Expand Down Expand Up @@ -158,6 +185,9 @@ impl Interface {

// [Network] section
writeln!(config, "\n[Network]").unwrap();
if let Some(dhcp) = &self.dhcp {
writeln!(config, "DHCP={}", dhcp.sd_dhcp_setting()).unwrap();
}
for ns in &self.nameservers {
writeln!(config, "DNS={ns}").unwrap()
}
Expand Down Expand Up @@ -246,6 +276,7 @@ mod tests {
priority: 20,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -261,6 +292,7 @@ mod tests {
priority: 10,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -276,6 +308,7 @@ mod tests {
priority: 20,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -291,6 +324,7 @@ mod tests {
priority: 20,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -306,6 +340,7 @@ mod tests {
priority: 20,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -330,6 +365,7 @@ mod tests {
priority: 20,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand Down Expand Up @@ -387,6 +423,7 @@ mod tests {
Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 128).unwrap(),
),
],
dhcp: None,
routes: vec![NetworkRoute {
destination: IpNetwork::V4(
Ipv4Network::new(Ipv4Addr::new(127, 0, 0, 1), 8).unwrap(),
Expand Down Expand Up @@ -428,6 +465,7 @@ Gateway=127.0.0.1
priority: 10,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -447,6 +485,7 @@ Gateway=127.0.0.1
priority: 10,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: false,
Expand All @@ -470,6 +509,7 @@ RequiredForOnline=no
priority: 10,
nameservers: vec![],
ip_addresses: vec![],
dhcp: None,
routes: vec![],
bond: None,
unmanaged: true,
Expand All @@ -482,6 +522,28 @@ Name=*
[Link]
Unmanaged=yes
",
),
// test the DHCP setting
(
Interface {
name: Some("*".to_owned()),
mac_address: None,
path: None,
priority: 10,
nameservers: vec![],
ip_addresses: vec![],
dhcp: Some(DhcpSetting::V4),
routes: vec![],
bond: None,
unmanaged: false,
required_for_online: None,
},
"[Match]
Name=*
[Network]
DHCP=ipv4
",
),
];
Expand Down
1 change: 1 addition & 0 deletions src/providers/digitalocean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl DigitalOceanProvider {
mac_address: Some(mac),
nameservers: self.dns.nameservers.clone(),
ip_addresses: addrs,
dhcp: None,
routes,
bond: None,
name: None,
Expand Down
1 change: 1 addition & 0 deletions src/providers/ibmcloud_classic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl IBMClassicProvider {
priority: 10,
nameservers: nameservers.clone(),
ip_addresses: vec![ip_net],
dhcp: None,
routes,
bond: None,
unmanaged: false,
Expand Down
1 change: 1 addition & 0 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod microsoft;
pub mod openstack;
pub mod packet;
pub mod powervs;
pub mod proxmoxve;
pub mod scaleway;
pub mod vmware;
pub mod vultr;
Expand Down
3 changes: 3 additions & 0 deletions src/providers/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ impl PacketProvider {
priority: 10,
nameservers: Vec::new(),
ip_addresses: Vec::new(),
dhcp: None,
routes: Vec::new(),
// the interface should be unmanaged if it doesn't have a bond
// section
Expand All @@ -241,6 +242,7 @@ impl PacketProvider {
path: None,
bond: None,
ip_addresses: Vec::new(),
dhcp: None,
routes: Vec::new(),
unmanaged: false,
required_for_online: Some("degraded-carrier".to_owned()),
Expand Down Expand Up @@ -334,6 +336,7 @@ impl PacketProvider {
bond: None,
nameservers: Vec::new(),
ip_addresses: Vec::new(),
dhcp: None,
routes: Vec::new(),
required_for_online: None,
};
Expand Down
Loading

0 comments on commit a92c78d

Please sign in to comment.