Skip to content

Commit

Permalink
reticulating
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Aug 30, 2024
1 parent 6720e1d commit 9f110e2
Show file tree
Hide file tree
Showing 5 changed files with 619 additions and 53 deletions.
65 changes: 62 additions & 3 deletions nexus/db-model/src/internet_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use super::Generation;
use crate::schema::{
internet_gateway, internet_gateway_ip_address, internet_gateway_ip_pool,
};
use crate::DatastoreCollectionConfig;
use db_macros::Resource;
use ipnetwork::IpNetwork;
use nexus_types::external_api::views;
use nexus_types::external_api::{params, views};
use nexus_types::identity::Resource;
use uuid::Uuid;

Expand All @@ -19,6 +20,18 @@ pub struct InternetGateway {
pub resolved_version: i64,
}

impl InternetGateway {
pub fn new(
gateway_id: Uuid,
vpc_id: Uuid,
params: params::InternetGatewayCreate,
) -> Self {
let identity =
InternetGatewayIdentity::new(gateway_id, params.identity);
Self { identity, vpc_id, rcgen: Generation::new(), resolved_version: 0 }
}
}

impl From<InternetGateway> for views::InternetGateway {
fn from(value: InternetGateway) -> Self {
Self { identity: value.identity(), vpc_id: value.vpc_id }
Expand All @@ -29,11 +42,24 @@ impl From<InternetGateway> for views::InternetGateway {
#[diesel(table_name = internet_gateway_ip_pool)]
pub struct InternetGatewayIpPool {
#[diesel(embed)]
pub identity: InternetGatewayIpPoolIdentity,
identity: InternetGatewayIpPoolIdentity,

pub internet_gateway_id: Uuid,
pub ip_pool_id: Uuid,
}

impl InternetGatewayIpPool {
pub fn new(
pool_id: Uuid,
internet_gateway_id: Uuid,
params: params::InternetGatewayIpPoolCreate,
) -> Self {
let identity =
InternetGatewayIpPoolIdentity::new(pool_id, params.identity);
Self { identity, internet_gateway_id, ip_pool_id: params.ip_pool_id }
}
}

impl From<InternetGatewayIpPool> for views::InternetGatewayIpPool {
fn from(value: InternetGatewayIpPool) -> Self {
Self {
Expand All @@ -48,11 +74,28 @@ impl From<InternetGatewayIpPool> for views::InternetGatewayIpPool {
#[diesel(table_name = internet_gateway_ip_address)]
pub struct InternetGatewayIpAddress {
#[diesel(embed)]
pub identity: InternetGatewayIpAddressIdentity,
identity: InternetGatewayIpAddressIdentity,

pub internet_gateway_id: Uuid,
pub address: IpNetwork,
}

impl InternetGatewayIpAddress {
pub fn new(
pool_id: Uuid,
internet_gateway_id: Uuid,
params: params::InternetGatewayIpAddressCreate,
) -> Self {
let identity =
InternetGatewayIpAddressIdentity::new(pool_id, params.identity);
Self {
identity,
internet_gateway_id,
address: IpNetwork::from(params.address),
}
}
}

impl From<InternetGatewayIpAddress> for views::InternetGatewayIpAddress {
fn from(value: InternetGatewayIpAddress) -> Self {
Self {
Expand All @@ -62,3 +105,19 @@ impl From<InternetGatewayIpAddress> for views::InternetGatewayIpAddress {
}
}
}

impl DatastoreCollectionConfig<InternetGatewayIpPool> for InternetGateway {
type CollectionId = Uuid;
type GenerationNumberColumn = internet_gateway::dsl::rcgen;
type CollectionTimeDeletedColumn = internet_gateway::dsl::time_deleted;
type CollectionIdColumn =
internet_gateway_ip_pool::dsl::internet_gateway_id;
}

impl DatastoreCollectionConfig<InternetGatewayIpAddress> for InternetGateway {
type CollectionId = Uuid;
type GenerationNumberColumn = internet_gateway::dsl::rcgen;
type CollectionTimeDeletedColumn = internet_gateway::dsl::time_deleted;
type CollectionIdColumn =
internet_gateway_ip_address::dsl::internet_gateway_id;
}
4 changes: 2 additions & 2 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ table! {
}

table! {
internet_gateway_ip_pool(internet_gateway_id, ip_pool_id) {
internet_gateway_ip_pool(id) {
id -> Uuid,
name -> Text,
description -> Text,
Expand All @@ -1171,7 +1171,7 @@ table! {
}

table! {
internet_gateway_ip_address(internet_gateway_id, address) {
internet_gateway_ip_address(id) {
id -> Uuid,
name -> Text,
description -> Text,
Expand Down
Loading

0 comments on commit 9f110e2

Please sign in to comment.