aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-12 12:22:19 -0400
committerCara Salter <cara@devcara.com>2022-04-12 12:29:32 -0400
commit34af52c58daae7ad75c0871e88e7b937fcd078fb (patch)
treebd1ca042e84efd708250595727db1a4bb76054e7 /src
downloadsolarlib-34af52c58daae7ad75c0871e88e7b937fcd078fb.tar.gz
solarlib-34af52c58daae7ad75c0871e88e7b937fcd078fb.zip
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/errors.rs9
-rw-r--r--src/lib.rs3
-rw-r--r--src/vm.rs31
3 files changed, 43 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs
new file mode 100644
index 0000000..2960ba9
--- /dev/null
+++ b/src/errors.rs
@@ -0,0 +1,9 @@
+use thiserror::Error;
+
+#[derive(Error, Debug)]
+pub enum Error {
+ #[error("libvirt: {0}")]
+ Libvirt(#[from] virt::error::Error),
+ #[error("Unknown: {0}")]
+ Other(String),
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..e29abd4
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,3 @@
+pub mod errors;
+
+pub mod vm;
diff --git a/src/vm.rs b/src/vm.rs
new file mode 100644
index 0000000..8e17659
--- /dev/null
+++ b/src/vm.rs
@@ -0,0 +1,31 @@
+use std::convert::TryFrom;
+use virt::{connect::Connect, domain::Domain;};
+
+use crate::errors::Error;
+
+
+/**
+ * Represents a virtual machine, that's active on some server
+ */
+pub struct VirtualMachine {
+ /// The assigned name of the VM
+ pub name: String,
+ /// The network address of the physical machine that's hosting this machine
+ pub host_server: String,
+ /// Whether or not the VM is active
+ pub is_active: bool,
+ /// The libvirtd-assigned UUID
+ pub uuid: String,
+ /// The network address of the VM
+ pub addr: Option<String>,
+ /// How much RAM (in MB) is assigned to the VM
+ pub assigned_mem_mb: u64,
+ /// How many vCPUs are assigned to the VM
+ pub assigned_cpus: u64,
+}
+
+impl TryFrom<Domain> for VirtualMachine {
+ type Error = Error;
+
+ fn try_from(d: Domain) -> Result<Self, Self::Error> {
+