1use std::net::Ipv4Addr;
2
3use serde::{Deserialize, Serialize};
4
5mod utils;
6pub use utils::{Error, XnodeDeployerError};
7
8#[cfg(feature = "hivelocity")]
9pub mod hivelocity;
10#[cfg(feature = "hyperstack")]
11pub mod hyperstack;
12
13#[derive(Serialize, Deserialize, Debug)]
14pub struct DeployInput {
15 pub xnode_owner: Option<String>,
16 pub domain: Option<String>,
17 pub acme_email: Option<String>,
18 pub user_passwd: Option<String>,
19 pub encrypted: Option<String>,
20 pub initial_config: Option<String>,
21}
22
23#[derive(Debug)]
24pub enum OptionalSupport<T> {
25 NotSupported,
26 Supported(T),
27}
28
29pub trait XnodeDeployer: Send + Sync {
30 type ProviderOutput;
31
32 fn deploy(
34 &self,
35 input: DeployInput,
36 ) -> impl Future<Output = Result<Self::ProviderOutput, Error>> + Send;
37
38 fn undeploy(&self, xnode: Self::ProviderOutput) -> impl Future<Output = Option<Error>> + Send;
40
41 fn ipv4(
43 &self,
44 xnode: &Self::ProviderOutput,
45 ) -> impl Future<Output = Result<OptionalSupport<Option<Ipv4Addr>>, Error>> + Send;
46}
47
48impl DeployInput {
49 pub fn cloud_init(&self) -> String {
50 let mut env = vec![];
51 for (name, content) in [
52 ("XNODE_OWNER", &self.xnode_owner),
53 ("DOMAIN", &self.domain),
54 ("ACME_EMAIL", &self.acme_email),
55 ("USER_PASSWD", &self.user_passwd),
56 ("ENCRYPTED", &self.encrypted),
57 ("INITIAL_CONFIG", &self.initial_config),
58 ] {
59 if let Some(content) = content {
60 env.push(format!("export {name}=\"{content}\" && "));
61 }
62 }
63
64 let env = env.join("");
65 format!(
66 "#cloud-config\nruncmd:\n - {env} curl https://raw.githubusercontent.com/Openmesh-Network/xnode-manager/main/os/install.sh | bash 2>&1 | tee /tmp/xnodeos.log"
67 )
68 }
69}