Commit 9bb95b8d authored by Heinz N. Gies's avatar Heinz N. Gies

Add -p and -H to list closes #3

parent 5acbcc63
......@@ -5,6 +5,7 @@ dependencies = [
"aud 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.25.0 (registry+https://github.com/rust-lang/crates.io-index)",
"clippy 0.0.142 (registry+https://github.com/rust-lang/crates.io-index)",
"prettytable-rs 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -47,6 +48,11 @@ name = "bitflags"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cargo_metadata"
version = "0.2.1"
......@@ -128,6 +134,16 @@ name = "crossbeam"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "csv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.1"
......@@ -138,6 +154,11 @@ name = "either"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "encode_unicode"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "isatty"
version = "0.1.3"
......@@ -185,6 +206,14 @@ name = "matches"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "nix"
version = "0.8.1"
......@@ -228,6 +257,19 @@ name = "num-traits"
version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "prettytable-rs"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"csv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"encode_unicode 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quine-mc_cluskey"
version = "0.2.4"
......@@ -256,6 +298,11 @@ name = "regex-syntax"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "semver"
version = "0.6.0"
......@@ -515,6 +562,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum aud 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9b275fc36d5afbd23cb73bc1524aaaa17050c2d98430f6d1f45492c636b54ed6"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
"checksum cargo_metadata 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d84cb53c78e573aa126a4b9f963fdb2629f8183b26e235da08bb36dc7381162"
"checksum cfg-if 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c47d456a36ebf0536a6705c83c1cbbcb9255fbc1d905a6ded104f479268a29"
"checksum chrono 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "158b0bd7d75cbb6bf9c25967a48a2e9f77da95876b858eadfabaa99cd069de6e"
......@@ -523,8 +571,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum clippy 0.0.142 (registry+https://github.com/rust-lang/crates.io-index)" = "e82a66cfefcffef361a3ba150954563c5a1e151467e8bf4e28551f931200c7e3"
"checksum clippy_lints 0.0.142 (registry+https://github.com/rust-lang/crates.io-index)" = "a8f0b1f90db91953dd03b115148df31427f006cf6d8958fa7582c4f9f2037df5"
"checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97"
"checksum csv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef22b37c7a51c564a365892c012dc0271221fdcc64c69b19ba4d6fa8bd96d9c"
"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90"
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
"checksum encode_unicode 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c088ec0ed2282dcd054f2c124c0327f953563e6c75fdc6ff5141779596289830"
"checksum isatty 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fa500db770a99afe2a0f2229be2a3d09c7ed9d7e4e8440bf71253141994e240f"
"checksum itertools 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "772a0928a97246167d59a2a4729df5871f1327ab8b36fd24c4224b229cb47b99"
"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c"
......@@ -532,16 +582,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf"
"checksum libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "38f5c2b18a287cf78b4097db62e20f43cace381dc76ae5c0a3073067f78b7ddc"
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
"checksum nix 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "47e49f6982987135c5e9620ab317623e723bd06738fd85377e8d55f57c8b6487"
"checksum num 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "2c3a3dc9f30bf824141521b30c908a859ab190b76e20435fcd89f35eb6583887"
"checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37"
"checksum num-iter 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "f7d1891bd7b936f12349b7d1403761c8a0b85a18b148e9da4429d5d102c1a41e"
"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6"
"checksum prettytable-rs 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "34dc1f4f6dddab3bf008ecfd4fd2a631b585fbf0af123f34c1324f51a034ff5f"
"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum redox_syscall 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "e4a357d14a12e90a37d658725df0e6468504750b5948b9710f83f94a0c5818e8"
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6a7c6b751a2e8d5df57a5ff71b5b4fc8aaee9ee28ff1341d640dd130bb5f4f7a"
......
......@@ -16,6 +16,7 @@ slog-async = "2"
slog-scope = "2"
slog-bunyan = "2"
aud = "0.1"
prettytable-rs = "^0.6"
# indicatif = "0.5"
[dependencies.clap]
......
......@@ -8,6 +8,11 @@ use std::str;
use std::cmp::PartialEq;
use std::collections::HashMap;
use prettytable::Table;
use prettytable::format;
use prettytable::row::Row;
use prettytable::cell::Cell;
use serde_json;
use jails;
......@@ -165,23 +170,6 @@ impl<'a> JDB<'a> {
}
}
/// Prints the jdb database
pub fn print(self: &'a JDB<'a>) -> Result<i32, Box<Error>> {
println!(
"{:37} {:5} {:8} {:17} {:5} {}",
"UUID",
"TYPE",
"RAM",
"STATE",
"ID",
"ALIAS"
);
for e in &(self.index.entries) {
self.print_entry(e)?;
}
Ok(0)
}
/// Reads the config file for a given entry
fn config(self: &'a JDB<'a>, entry: &IdxEntry) -> Result<JailConfig, Box<Error>> {
debug!("Loading vm config"; "vm" => &entry.uuid);
......@@ -224,8 +212,41 @@ impl<'a> JDB<'a> {
fn find(self: &'a JDB<'a>, uuid: &str) -> Option<usize> {
self.index.entries.iter().position(|x| *x.uuid == *uuid)
}
/// Prints the jdb database
pub fn print(self: &'a JDB<'a>, headerless: bool, parsable: bool) -> Result<i32, Box<Error>> {
let mut table = Table::new();
table.set_format(*format::consts::FORMAT_CLEAN);
if !headerless {
if parsable {
println!(
"{}:{}:{}:{}:{}:{}",
"UUID",
"TYPE",
"RAM",
"STATE",
"ID",
"ALIAS"
);
} else {
table.add_row(row!["UUID", "TYPE", "RAM", "STATE", "ID", "ALIAS"]);
}
}
for e in &(self.index.entries) {
self.print_entry(e, &mut table, parsable)?;
}
if !parsable {
table.printstd()
};
Ok(0)
}
/// Gets the config and prints an etry
fn print_entry(self: &'a JDB<'a>, entry: &IdxEntry) -> Result<i32, Box<Error>> {
fn print_entry(
self: &'a JDB<'a>,
entry: &IdxEntry,
table: &mut Table,
parsable: bool,
) -> Result<i32, Box<Error>> {
let conf = self.config(entry)?;
let id = match self.jails.get(&conf.uuid) {
Some(jail) => jail.id,
......@@ -235,15 +256,26 @@ impl<'a> JDB<'a> {
0 => &entry.state,
_ => "running",
};
println!(
"{:37} {:5} {:8} {:17} {:5} {}",
conf.uuid,
"OS",
conf.max_physical_memory,
state,
id,
conf.alias,
);
if parsable {
println!(
"{}:{}:{}:{}:{}:{}",
conf.uuid,
"OS",
conf.max_physical_memory,
state,
id,
conf.alias
);
} else {
table.add_row(Row::new(vec![
Cell::new(conf.uuid.as_str()),
Cell::new("OS"),
Cell::new(conf.max_physical_memory.to_string().as_str()),
Cell::new(state),
Cell::new(id.to_string().as_str()),
Cell::new(conf.alias.as_str()),
]));
};
Ok(0)
}
}
......@@ -20,6 +20,9 @@ extern crate serde_json;
extern crate toml;
//extern crate indicatif;
#[macro_use]
extern crate prettytable;
extern crate uuid;
use uuid::Uuid;
......@@ -287,9 +290,12 @@ fn update(_conf: &Config, _matches: &clap::ArgMatches) -> Result<i32, Box<Error>
Ok(0)
}
fn list(conf: &Config, _matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
fn list(conf: &Config, matches: &clap::ArgMatches) -> Result<i32, Box<Error>> {
let db = JDB::open(conf)?;
db.print()
db.print(
matches.is_present("headerless"),
matches.is_present("parsable"),
)
}
......
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