Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions nexus/db-model/src/external_service_ip_pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Model types for assigning IP pools to individual external services.

use super::impl_enum_type;
use crate::DbTypedUuid;
use diesel::Insertable;
use diesel::Queryable;
use diesel::Selectable;
use nexus_db_schema::schema::external_service_ip_pool;
use omicron_uuid_kinds::IpPoolKind;
use serde::Deserialize;
use serde::Serialize;

impl_enum_type!(
ExternalServiceKindEnum:

#[derive(
Copy,
Clone,
Debug,
PartialEq,
Eq,
Serialize,
Deserialize,
AsExpression,
FromSqlRow,
)]
#[serde(rename_all = "snake_case")]
pub enum ExternalServiceKind;

Nexus => b"nexus"
BoundaryNtp => b"boundary_ntp"
ExternalDns => b"external_dns"
);

impl std::fmt::Display for ExternalServiceKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
ExternalServiceKind::Nexus => "nexus",
ExternalServiceKind::BoundaryNtp => "boundary_ntp",
ExternalServiceKind::ExternalDns => "external_dns",
};
f.write_str(s)
}
}

/// Assignment of an IP pool to an external service.
//
// NOTE: The associations here intentionally avoid any semantics like
// exclusivity or what an assignment means for the application. Each service
// could be different in that respect, and we haven't really fleshed out enough
// of the system to know how to use the records here. For now, we just enforce
// basic sanity checks, like that operators cannot delete the last pool assigned
// to a service, or concurrent operations on the pool and this record.
#[derive(
Queryable, Clone, Copy, Debug, PartialEq, Eq, Selectable, Insertable,
)]
#[diesel(table_name = external_service_ip_pool)]
pub struct ExternalServiceIpPool {
pub service: ExternalServiceKind,
pub ip_pool_id: DbTypedUuid<IpPoolKind>,
}
2 changes: 2 additions & 0 deletions nexus/db-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub mod ereport;
mod ereporter_restart;
mod ereporter_type;
mod external_ip;
mod external_service_ip_pool;
mod external_subnet;
pub mod fm;
mod generation;
Expand Down Expand Up @@ -306,6 +307,7 @@ pub use ereport::Ereport;
pub use ereporter_restart::*;
pub use ereporter_type::*;
pub use external_ip::*;
pub use external_service_ip_pool::*;
pub use external_subnet::*;
pub use fm::{SitrepMetadata, SitrepVersion};
pub use generation::*;
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: Version = Version::new(293, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(294, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ pub static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(294, "external-service-ip-pool"),
KnownVersion::new(293, "add-rendezvous-sled-bp-availability"),
KnownVersion::new(292, "allow-ddm-traffic"),
KnownVersion::new(291, "bgp-peer-src-addr"),
Expand Down
Loading
Loading