aboutsummaryrefslogtreecommitdiff
path: root/src/house.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-19 12:46:15 -0400
committerCara Salter <cara@devcara.com>2022-04-19 12:46:15 -0400
commit53256aacaa8a8ec5728334afc20ba2945f829b69 (patch)
treea69ffbcd88124e6578fe8192458f7e37290a04a3 /src/house.rs
parent71d31463e019b5c5d6bea382eb490d53e7c0cea7 (diff)
downloadsolarlib-53256aacaa8a8ec5728334afc20ba2945f829b69.tar.gz
solarlib-53256aacaa8a8ec5728334afc20ba2945f829b69.zip
Unitype and tests
Diffstat (limited to 'src/house.rs')
-rw-r--r--src/house.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/house.rs b/src/house.rs
index 6159c33..735413e 100644
--- a/src/house.rs
+++ b/src/house.rs
@@ -30,19 +30,42 @@ pub struct House {
/// Hostname
pub name: String,
/// FQDN or IP address, a way to talk to the house
- pub address: Address
+ pub address: String,
+
+ /// Connection to the House, if available
+ #[serde(skip)]
+ con: Option<Connect>,
}
impl House {
- pub fn new(hostname: String, addr: Address) -> Result<Self, Error> {
- let mut c = Connect::open(&format!("qemu+ssh://{}/system", addr.to_string()))?;
+ pub fn new(url: String) -> Result<Self, Error> {
+ let mut c = Connect::open(&url.clone())?;
// If the connection succeeds, we've got one!
Ok(Self {
- name: hostname.clone(),
- address: addr
+ name: c.get_hostname()?,
+ address: c.get_uri()?,
+ con: Some(c),
})
}
+
+ pub fn inhabitants(&mut self) -> Result<Vec<Waifu>, Error> {
+ match &self.con {
+ Some(c) => {
+ let domains = c.list_all_domains(0)?;
+
+ let mut waifus: Vec<Waifu> = Vec::new();
+
+ for d in domains.iter() {
+ waifus.push(d.clone().try_into()?);
+ }
+ Ok(waifus)
+ },
+ None => {
+ return Err(Error::Connection("Domain connection was None".to_string()));
+ }
+ }
+ }
}
#[cfg(test)]
@@ -58,4 +81,19 @@ mod test {
assert_eq!(String::from("127.0.0.1"), a.to_string());
assert_eq!("example.com".to_string(), d.to_string());
}
+
+ #[test]
+ fn connect_to_house() {
+ let h: House = House::new("test:///default".to_string()).unwrap();
+ }
+
+ #[test]
+ fn list_inhabitants() {
+ let mut h: House = House::new("test:///default".to_string()).unwrap();
+
+ let empty_vec: Vec<Waifu> = vec![];
+
+ h.inhabitants().unwrap();
+ }
+
}