mock: clean up todos

This commit is contained in:
snow flurry 2024-08-19 12:08:39 -07:00
parent ba86368591
commit ece1f9a089

View file

@ -10,7 +10,7 @@ use futures::{future, StreamExt};
use tokio::{sync::RwLock, task::JoinHandle}; use tokio::{sync::RwLock, task::JoinHandle};
use crate::{ use crate::{
error::ApiError, error::{ApiError, ErrorType},
model, model,
net::{cidr::CidrV4, mac::MacAddr}, net::{cidr::CidrV4, mac::MacAddr},
InstanceQuery, Nazrin, NazrinClient, InstanceQuery, Nazrin, NazrinClient,
@ -241,27 +241,32 @@ impl Nazrin for MockServer {
interface: String, interface: String,
) -> Result<(), ApiError> { ) -> Result<(), ApiError> {
let mut db = self.db.write().await; let mut db = self.db.write().await;
db.instances {
.iter() let Some(subnet) = db
.filter_map(|inst| inst.as_ref()) .subnets
.for_each(|inst| { .iter_mut()
if inst.lease.subnet == interface { .find(|net| net.as_ref().filter(|n| n.name == interface).is_some())
todo!("what now") else {
} return Err(ErrorType::NotFound.into());
}); };
let Some(subnet) = db subnet.take();
.subnets }
.iter_mut() // Drop all instances that belong to this subnet
.find(|net| net.as_ref().filter(|n| n.name == interface).is_some()) db.instances.iter_mut().for_each(|inst| {
else { if inst
return Err("Subnet doesn't exist".into()); .as_mut()
}; .filter(|inst| inst.lease.subnet != interface)
subnet.take(); .is_some()
{
inst.take();
}
});
Ok(()) Ok(())
} }
async fn garbage_collect(self, _: tarpc::context::Context) -> Result<(), ApiError> { async fn garbage_collect(self, _: tarpc::context::Context) -> Result<(), ApiError> {
todo!() // no libvirt to compare against, no instances to GC
Ok(())
} }
async fn get_ssh_pubkeys( async fn get_ssh_pubkeys(