xnode_deployer/
lib.rs

1use serde::{Deserialize, Serialize};
2
3mod hivelocity;
4mod utils;
5
6pub use hivelocity::*;
7pub use utils::{Error, XnodeDeployerError};
8
9#[derive(Serialize, Deserialize, Debug)]
10pub struct DeployInput {
11    pub xnode_owner: Option<String>,
12    pub domain: Option<String>,
13    pub acme_email: Option<String>,
14    pub user_passwd: Option<String>,
15    pub encrypted: Option<String>,
16    pub initial_config: Option<String>,
17}
18#[derive(Serialize, Deserialize, Debug)]
19pub struct DeployOutput<ProviderOutput> {
20    pub ip: String,
21    pub provider: ProviderOutput,
22}
23
24pub trait XnodeDeployer: Send + Sync {
25    type ProviderOutput;
26
27    /// Decide who should be the current controller based on external data
28    fn deploy(
29        &self,
30        input: DeployInput,
31    ) -> impl Future<Output = Result<DeployOutput<Self::ProviderOutput>, Error>> + Send;
32}
33
34impl DeployInput {
35    pub fn cloud_init(&self) -> String {
36        let mut env = vec![];
37        for (name, content) in [
38            ("XNODE_OWNER", &self.xnode_owner),
39            ("DOMAIN", &self.domain),
40            ("ACME_EMAIL", &self.acme_email),
41            ("USER_PASSWD", &self.user_passwd),
42            ("ENCRYPTED", &self.encrypted),
43            ("INITIAL_CONFIG", &self.initial_config),
44        ] {
45            if let Some(content) = content {
46                env.push(format!("export {name}=\"{content}\" && "));
47            }
48        }
49
50        let env = env.join("");
51        format!(
52            "#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"
53        )
54    }
55}