Commit bc953cee authored by Heinz N. Gies's avatar Heinz N. Gies

Add image import template

parent 17360da8
......@@ -3,6 +3,7 @@ name = "vmadm"
version = "0.1.0"
dependencies = [
"aud 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"bzip2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.152 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -98,6 +99,24 @@ dependencies = [
"iovec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bzip2"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bzip2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bzip2-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cargo_metadata"
version = "0.2.3"
......@@ -1136,6 +1155,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
"checksum bytes 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d828f97b58cc5de3e40c421d0cf2132d6b2da4ee0e11b8632fa838f0f9333ad6"
"checksum bzip2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3eafc42c44e0d827de6b1c131175098fe7fb53b8ce8a47e65cb3ea94688be24"
"checksum bzip2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "98ce3fff84d4e90011f464bbdf48e3428f04270439f703868fd489d2aaedfc30"
"checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "158b0bd7d75cbb6bf9c25967a48a2e9f77da95876b858eadfabaa99cd069de6e"
......
......@@ -22,6 +22,7 @@ regex = "0.2"
rand = "0.3"
reqwest = "0.7"
chrono = { version = "0.4", features = ["serde", "rustc-serialize"] }
bzip2 = "0.3.2"
# indicatif = "0.5"
[dependencies.clap]
......
......@@ -102,3 +102,17 @@ subcommands:
subcommands:
- avail:
about: lists available images
- get:
about: lists available images
args:
- uuid:
help: UUID if the image to get
index: 1
required: true
- import:
about: lists available images
args:
- uuid:
help: UUID if the image to get
index: 1
required: true
......@@ -15,11 +15,12 @@ impl ValidationErrors {
pub fn new(errors: Vec<ValidationError>) -> Self {
ValidationErrors { errors }
}
/// Create a new error in a box
pub fn bx(errors: Vec<ValidationError>) -> Box<Error> {
Box::new(ValidationErrors::new(errors))
}
/// Create a new error in a box
pub fn bx(errors: Vec<ValidationError>) -> Box<Error> {
Box::new(ValidationErrors::new(errors))
}
}
impl fmt::Display for ValidationErrors {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut r = write!(f, "{} validaiton errors encountered", self.errors.len());
......@@ -51,10 +52,10 @@ impl ValidationError {
error: String::from(error),
}
}
/// Create a new error in a box
pub fn bx(field: &str, error: &str) -> Box<Error> {
Box::new(ValidationError::new(field, error))
}
// /// Create a new error in a box
// pub fn bx(field: &str, error: &str) -> Box<Error> {
// Box::new(ValidationError::new(field, error))
// }
}
impl fmt::Display for ValidationError {
......
......@@ -524,6 +524,8 @@ fn delete(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>>
fn images(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
match matches.subcommand() {
("avail", Some(avail_matches)) => images_avail(&conf, avail_matches),
("get", Some(get_matches)) => images_get(&conf, get_matches),
("import", Some(import_matches)) => images_import(&conf, import_matches),
("", None) => {
Ok(0)
}
......@@ -534,3 +536,15 @@ fn images(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>>
fn images_avail(conf: &Config, _matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
images::avail(conf)
}
fn images_get(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
let uuid_string = value_t!(matches, "uuid", String).unwrap();
let uuid = Uuid::parse_str(uuid_string.as_str()).unwrap();
images::get(conf, uuid)
}
fn images_import(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
let uuid_string = value_t!(matches, "uuid", String).unwrap();
let uuid = Uuid::parse_str(uuid_string.as_str()).unwrap();
images::import(conf, uuid)
}
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