summaryrefslogtreecommitdiff
path: root/src/cmd/cloud_init.rs
blob: a9b358888dbd6b5e11c307815cea13f21353242f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::cloudinit::{CloudInitConfig, CloudInitError};
use crate::spec::Specification;
use log::{debug, info};
use std::path::Path;

#[derive(Debug, thiserror::Error)]
pub enum CloudInitCommandError {
    #[error(transparent)]
    CloudInitError(#[from] CloudInitError),

    #[error(transparent)]
    IoError(#[from] std::io::Error),
}

pub fn cloud_init(specs: &[Specification], dirname: &Path) -> Result<(), CloudInitCommandError> {
    for spec in specs {
        let dirname = dirname.join(&spec.name);
        info!(
            "generating cloud-init configuration for {} into {}",
            spec.name,
            dirname.display()
        );

        let init = CloudInitConfig::from(&spec)?;

        debug!("creating directory {}", dirname.display());
        std::fs::create_dir_all(&dirname)?;
        init.create_dir(&dirname)?;
    }

    Ok(())
}