use std::net::Ipv4Addr;
use serde::{Deserialize, Serialize};
mod utils;
pub use utils::{Error, XnodeDeployerError};
#[cfg(feature = "hivelocity")]
pub mod hivelocity;
#[cfg(feature = "hyperstack")]
pub mod hyperstack;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct DeployInput {
pub xnode_owner: Option<String>,
pub domain: Option<String>,
pub acme_email: Option<String>,
pub user_passwd: Option<String>,
pub encrypted: Option<String>,
pub initial_config: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum OptionalSupport<T> {
NotSupported,
Supported(T),
}
pub trait XnodeDeployer: Send + Sync {
type ProviderOutput;
fn deploy(
&self,
input: DeployInput,
) -> impl Future<Output = Result<Self::ProviderOutput, Error>> + Send;
fn undeploy(
&self,
xnode: Self::ProviderOutput,
) -> impl Future<Output = Result<(), Error>> + Send;
fn ipv4(
&self,
xnode: &Self::ProviderOutput,
) -> impl Future<Output = Result<OptionalSupport<Option<Ipv4Addr>>, Error>> + Send;
}
impl DeployInput {
pub fn cloud_init(&self) -> String {
let mut env = vec![];
for (name, content) in [
("VERSION", &Some("v1.0.0".to_string())),
("XNODE_OWNER", &self.xnode_owner),
("DOMAIN", &self.domain),
("ACME_EMAIL", &self.acme_email),
("USER_PASSWD", &self.user_passwd),
("ENCRYPTED", &self.encrypted),
("INITIAL_CONFIG", &self.initial_config),
] {
if let Some(content) = content {
env.push(format!("export {name}=\"{content}\" && "));
}
}
let env = env.join("");
format!(
"#cloud-config\nruncmd:\n - |\n {env} curl https://raw.githubusercontent.com/Openmesh-Network/xnodeos/main/install.sh | bash 2>&1 | tee /tmp/xnodeos.log"
)
}
}