feat: add network policy

This commit is contained in:
2025-02-28 12:40:45 +00:00
parent 29488d75a3
commit 5e2088f09c
21 changed files with 700 additions and 155 deletions

View File

@ -1,6 +1,4 @@
use anyhow::Result;
use async_trait::async_trait;
mod model;
#[cfg(feature = "mysql")]
mod mysql;
@ -9,6 +7,8 @@ pub use model::*;
#[cfg(feature = "mysql")]
pub use mysql::*;
pub use async_trait::async_trait;
#[async_trait]
pub trait LNVpsDb: Sync + Send {
/// Migrate database
@ -65,6 +65,9 @@ pub trait LNVpsDb: Sync + Send {
/// List available IP Ranges
async fn list_ip_range(&self) -> Result<Vec<IpRange>>;
/// List available IP Ranges in a given region
async fn list_ip_range_in_region(&self, region_id: u64) -> Result<Vec<IpRange>>;
/// Get a VM cost plan by id
async fn get_cost_plan(&self, id: u64) -> Result<VmCostPlan>;

View File

@ -220,6 +220,7 @@ pub struct VmIpAssignment {
pub vm_id: u64,
pub ip_range_id: u64,
pub ip: String,
pub deleted: bool,
}
impl Display for VmIpAssignment {

View File

@ -171,7 +171,15 @@ impl LNVpsDb for LNVpsDbMysql {
}
async fn list_ip_range(&self) -> Result<Vec<IpRange>> {
sqlx::query_as("select * from ip_range")
sqlx::query_as("select * from ip_range where enabled = 1")
.fetch_all(&self.db)
.await
.map_err(Error::new)
}
async fn list_ip_range_in_region(&self, region_id: u64) -> Result<Vec<IpRange>> {
sqlx::query_as("select * from ip_range where region_id = ? and enabled = 1")
.bind(region_id)
.fetch_all(&self.db)
.await
.map_err(Error::new)