Add dsmode cloud-init metadata
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-06-07 11:50:22 +02:00
parent 9609cfb33a
commit 8a7712ec42
2 changed files with 22 additions and 0 deletions

View File

@ -2,6 +2,15 @@ use crate::app_config::AppConfig;
use crate::constants; use crate::constants;
use std::process::Command; use std::process::Command;
/// Cloud init DS Mode
#[derive(Copy, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum CloudInitDSMode {
/// Networking is required
Net,
/// Does not require networking to be up before user-data actions are run
Local,
}
/// VM Cloud Init configuration /// VM Cloud Init configuration
/// ///
/// RedHat documentation: https://docs.redhat.com/fr/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_cloud-init_for_rhel_9/configuring-cloud-init_cloud-content /// RedHat documentation: https://docs.redhat.com/fr/documentation/red_hat_enterprise_linux/9/html/configuring_and_managing_cloud-init_for_rhel_9/configuring-cloud-init_cloud-content
@ -17,6 +26,9 @@ pub struct CloudInitConfig {
/// Local hostname, set in metadata file /// Local hostname, set in metadata file
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub local_hostname: Option<String>, pub local_hostname: Option<String>,
/// Data source mode
#[serde(skip_serializing_if = "Option::is_none")]
pub dsmode: Option<CloudInitDSMode>,
/// Network configuration /// Network configuration
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub network_configuration: Option<String>, pub network_configuration: Option<String>,
@ -53,6 +65,15 @@ impl CloudInitConfig {
if let Some(local_hostname) = &self.local_hostname { if let Some(local_hostname) = &self.local_hostname {
metadatas.push(format!("local-hostname: {}", local_hostname)); metadatas.push(format!("local-hostname: {}", local_hostname));
} }
if let Some(dsmode) = &self.dsmode {
metadatas.push(format!(
"dsmode: {}",
match dsmode {
CloudInitDSMode::Net => "net",
CloudInitDSMode::Local => "local",
}
));
}
let meta_data_path = temp_path.path().join("meta-data"); let meta_data_path = temp_path.path().join("meta-data");
std::fs::write(&meta_data_path, metadatas.join("\n"))?; std::fs::write(&meta_data_path, metadatas.join("\n"))?;
cmd.arg(meta_data_path); cmd.arg(meta_data_path);

View File

@ -87,6 +87,7 @@ export interface VMCloudInit {
user_data: string; user_data: string;
instance_id?: string; instance_id?: string;
local_hostname?: string; local_hostname?: string;
dsmode?: "Net" | "Local";
network_configuration?: string; network_configuration?: string;
} }