diff options
author | Cara Salter <cara@devcara.com> | 2022-04-12 12:22:19 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-04-12 12:29:32 -0400 |
commit | 34af52c58daae7ad75c0871e88e7b937fcd078fb (patch) | |
tree | bd1ca042e84efd708250595727db1a4bb76054e7 | |
download | solarlib-34af52c58daae7ad75c0871e88e7b937fcd078fb.tar.gz solarlib-34af52c58daae7ad75c0871e88e7b937fcd078fb.zip |
Initial commit
-rw-r--r-- | .envrc | 1 | ||||
-rw-r--r-- | .gitignore | 19 | ||||
-rw-r--r-- | Cargo.toml | 12 | ||||
-rw-r--r-- | flake.lock | 74 | ||||
-rw-r--r-- | flake.nix | 38 | ||||
-rw-r--r-- | src/errors.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/vm.rs | 31 |
8 files changed, 187 insertions, 0 deletions
@@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2db6895 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +/target + + +# Added by cargo +# +# already existing elements were commented out + +#/target +Cargo.lock + + +# Added by cargo +# +# already existing elements were commented out + +#/target +#Cargo.lock +design/ +.direnv/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7d4c363 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "waifulib" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +virt = "0.2" + +thiserror = "1" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b22496e --- /dev/null +++ b/flake.lock @@ -0,0 +1,74 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1649096192, + "narHash": "sha256-7O8e+eZEYeU+ET98u/zW5epuoN/xYx9G+CIh4DjZVzY=", + "owner": "nix-community", + "repo": "naersk", + "rev": "d626f73332a8f587b613b0afe7293dd0777be07d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1648219316, + "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..568bf22 --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + }; + + outputs = { self, nixpkgs, flake-utils, naersk }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = nixpkgs.legacyPackages."${system}"; + naersk-lib = naersk.lib."${system}"; + + build-inputs = with pkgs; [ + libvirt + ]; + in + rec { + # `nix build` + packages.waifulib = naersk-lib.buildPackage { + pname = "waifulib"; + root = ./.; + buildInputs = build-inputs; + }; + defaultPackage = packages.waifulib; + + # `nix run` + apps.waifulib = flake-utils.lib.mkApp { + drv = packages.waifulib; + }; + defaultApp = apps.waifulib; + + # `nix develop` + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo ] ++ build-inputs; + }; + } + ); +} 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> { + |