summaryrefslogtreecommitdiff
path: root/src/spec.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-20 08:55:17 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-20 19:39:24 +0200
commita315fab485429c0e4dfd665ced86f51130e3ac3c (patch)
tree8e320e2a4595befaff447005868d47ad266c0463 /src/spec.rs
parent0d10bc096bb4d791b6528d7ca6d450c83cfd1778 (diff)
downloadvmadm-a315fab485429c0e4dfd665ced86f51130e3ac3c.tar.gz
feat: vmadm command to create, list, and delete virtual machines
Includes test suite.
Diffstat (limited to 'src/spec.rs')
-rw-r--r--src/spec.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/spec.rs b/src/spec.rs
new file mode 100644
index 0000000..1209040
--- /dev/null
+++ b/src/spec.rs
@@ -0,0 +1,37 @@
+use serde::{Deserialize, Serialize};
+use std::path::PathBuf;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Specification {
+ pub name: String,
+
+ #[serde(default)]
+ pub ssh_key_files: Vec<PathBuf>,
+
+ pub base: PathBuf,
+ pub image: PathBuf,
+ pub image_size_gib: u64,
+ pub memory_mib: u64,
+ pub cpus: u64,
+}
+
+#[derive(Debug, thiserror::Error)]
+pub enum SpecificationError {
+ #[error(transparent)]
+ IoError(#[from] std::io::Error),
+
+ #[error(transparent)]
+ FromUtf8Error(#[from] std::string::FromUtf8Error),
+}
+
+impl Specification {
+ pub fn ssh_keys(&self) -> Result<String, SpecificationError> {
+ let mut keys = String::new();
+ for filename in self.ssh_key_files.iter() {
+ let key = std::fs::read(filename)?;
+ let key = String::from_utf8(key)?;
+ keys.push_str(&key);
+ }
+ Ok(keys)
+ }
+}