controller: split out commands into their own files

This commit is contained in:
Alex Zenla
2024-02-13 19:48:49 +00:00
parent 3524683ab4
commit 822b2e0227
7 changed files with 399 additions and 357 deletions

View File

@ -10,17 +10,12 @@ use uuid::Uuid;
pub struct ConfigBlock<'a> {
pub image_info: &'a ImageInfo,
pub config_bundle: Option<&'a str>,
pub file: PathBuf,
pub dir: PathBuf,
}
impl ConfigBlock<'_> {
pub fn new<'a>(
uuid: &Uuid,
image_info: &'a ImageInfo,
config_bundle: Option<&'a str>,
) -> Result<ConfigBlock<'a>> {
pub fn new<'a>(uuid: &Uuid, image_info: &'a ImageInfo) -> Result<ConfigBlock<'a>> {
let mut dir = std::env::temp_dir().clone();
dir.push(format!("hypha-cfg-{}", uuid));
fs::create_dir_all(&dir)?;
@ -28,7 +23,6 @@ impl ConfigBlock<'_> {
file.push("config.squashfs");
Ok(ConfigBlock {
image_info,
config_bundle,
file,
dir,
})
@ -36,10 +30,6 @@ impl ConfigBlock<'_> {
pub fn build(&self, launch_config: &LaunchInfo) -> Result<()> {
trace!("ConfigBlock build launch_config={:?}", launch_config);
let config_bundle_content = match self.config_bundle {
None => None,
Some(path) => Some(fs::read(path)?),
};
let manifest = self.image_info.config.to_string()?;
let launch = serde_json::to_string(launch_config)?;
let mut writer = FilesystemWriter::default();
@ -72,18 +62,6 @@ impl ConfigBlock<'_> {
mtime: 0,
},
)?;
if let Some(config_bundle_content) = config_bundle_content.as_ref() {
writer.push_file(
config_bundle_content.as_slice(),
"/bundle",
NodeHeader {
permissions: 384,
uid: 0,
gid: 0,
mtime: 0,
},
)?;
}
let mut file = File::create(&self.file)?;
trace!("ConfigBlock build write sqaushfs");
writer.write(&mut file)?;