feat: report capacity

ref #13
This commit is contained in:
2025-03-05 11:46:26 +00:00
parent 6b909ba5bd
commit 2bd6b5f09f
5 changed files with 127 additions and 0 deletions

View File

@ -83,6 +83,9 @@ pub trait LNVpsDb: Sync + Send {
/// List all VM's
async fn list_vms(&self) -> Result<Vec<Vm>>;
/// List all VM's on a given host
async fn list_vms_on_host(&self, host_id: u64) -> Result<Vec<Vm>>;
/// List expired VM's
async fn list_expired_vms(&self) -> Result<Vec<Vm>>;

View File

@ -223,6 +223,14 @@ impl LNVpsDb for LNVpsDbMysql {
.map_err(Error::new)
}
async fn list_vms_on_host(&self, host_id: u64) -> Result<Vec<Vm>> {
sqlx::query_as("select * from vm where deleted = 0 and host_id = ?")
.bind(host_id)
.fetch_all(&self.db)
.await
.map_err(Error::new)
}
async fn list_expired_vms(&self) -> Result<Vec<Vm>> {
sqlx::query_as("select * from vm where expires > current_timestamp() and deleted = 0")
.fetch_all(&self.db)