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 crate::{
error::ApiError,
error::{ApiError, ErrorType},
model,
net::{cidr::CidrV4, mac::MacAddr},
InstanceQuery, Nazrin, NazrinClient,
@ -241,27 +241,32 @@ impl Nazrin for MockServer {
interface: String,
) -> Result<(), ApiError> {
let mut db = self.db.write().await;
db.instances
.iter()
.filter_map(|inst| inst.as_ref())
.for_each(|inst| {
if inst.lease.subnet == interface {
todo!("what now")
}
});
let Some(subnet) = db
.subnets
.iter_mut()
.find(|net| net.as_ref().filter(|n| n.name == interface).is_some())
else {
return Err("Subnet doesn't exist".into());
};
subnet.take();
{
let Some(subnet) = db
.subnets
.iter_mut()
.find(|net| net.as_ref().filter(|n| n.name == interface).is_some())
else {
return Err(ErrorType::NotFound.into());
};
subnet.take();
}
// Drop all instances that belong to this subnet
db.instances.iter_mut().for_each(|inst| {
if inst
.as_mut()
.filter(|inst| inst.lease.subnet != interface)
.is_some()
{
inst.take();
}
});
Ok(())
}
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(