Commit 210d8a3a authored by Heinz N. Gies's avatar Heinz N. Gies

Fix imgadm format

parent 0487e767
......@@ -21,6 +21,22 @@ use bzip2::read::BzDecoder;
use flate2::read::GzDecoder;
#[derive(Debug, Serialize, Deserialize, Clone)]
struct ManifestWrapper {
zpool: String,
manifest: Image
}
impl ManifestWrapper {
pub fn from_reader<R>(reader: R) -> Result<Self, Box<Error>>
where
R: Read,
{
let manifest: ManifestWrapper = serde_json::from_reader(reader)?;
return Ok(manifest);
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
struct ImageFile {
size: u64,
......@@ -118,8 +134,8 @@ pub fn list(config: &Config) -> Result<i32, Box<Error>> {
for entry in fs::read_dir(config.settings.image_dir.clone())? {
let entry = entry?;
let image_file = File::open(entry.path())?;
let image = Image::from_reader(image_file)?;
images.push(image);
let manifest = ManifestWrapper::from_reader(image_file)?;
images.push(manifest.manifest);
}
print_images(images, false, false);
Ok(0)
......@@ -141,8 +157,8 @@ pub fn get(config: &Config, uuid: Uuid) -> Result<i32, Box<Error>> {
debug!("Get image"; "dir" => config.settings.image_dir.clone(),
"uuid" => uuid_str.clone(), "filer" => file_name.clone());
let file = File::open(file_name)?;
let image = Image::from_reader(file)?;
let j = serde_json::to_string_pretty(&image)?;
let manifest = ManifestWrapper::from_reader(file)?;
let j = serde_json::to_string_pretty(&manifest.manifest)?;
println!("{}\n", j);
//print_images(images, false, false);
Ok(0)
......@@ -182,7 +198,7 @@ pub fn import(config: &Config, uuid: Uuid) -> Result<i32, Box<Error>> {
"uuid" => uuid_str.clone(), "url" => url.clone());
let resp = reqwest::get(url.as_str())?;
let image = Image::from_reader(resp)?;
match image.origin {
None => (),
Some(origin) => {
......@@ -222,6 +238,10 @@ pub fn import(config: &Config, uuid: Uuid) -> Result<i32, Box<Error>> {
cfg_path.push_str(".json");
println!("Writing manifest file: {}", cfg_path);
let cfg_file = File::create(cfg_path)?;
serde_json::to_writer(cfg_file, &image)?;
let manifest = ManifestWrapper{
manifest: image,
zpool: config.settings.pool.clone()
};
serde_json::to_writer(cfg_file, &manifest)?;
Ok(0)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment