Skip to content
Open
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
19 changes: 19 additions & 0 deletions nexus/db-model/src/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,32 @@ impl std::fmt::Display for IpPoolType {
}
}

/// IP pool resource type.
///
/// `pool_type` and `ip_version` are denormalized from [IpPool]
/// for a unique index on defaults.
#[derive(Queryable, Insertable, Selectable, Clone, Copy, Debug, PartialEq)]
#[diesel(table_name = ip_pool_resource)]
pub struct IpPoolResource {
pub ip_pool_id: Uuid,
pub resource_type: IpPoolResourceType,
pub resource_id: Uuid,
pub is_default: bool,
pub pool_type: IpPoolType,
pub ip_version: IpVersion,
}

/// Input for creating an IP pool resource.
///
/// The `pool_type` and `ip_version` fields are populated from [IpPool]
/// by the `link_ip_pool_to_external_silo_query` query, so they are not needed
/// as input.
#[derive(Clone, Copy, Debug)]
pub struct IncompleteIpPoolResource {
pub ip_pool_id: Uuid,
pub resource_type: IpPoolResourceType,
pub resource_id: Uuid,
pub is_default: bool,
}

impl From<IpPoolResource> for views::IpPoolSiloLink {
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(214, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(215, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ 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(215, "multiple-default-ip-pools-per-silo"),
KnownVersion::new(214, "multicast-drop-mvlan"),
KnownVersion::new(213, "multicast-member-ip-and-indexes"),
KnownVersion::new(212, "local-storage-disk-type"),
Expand Down
12 changes: 9 additions & 3 deletions nexus/db-queries/src/db/datastore/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl DataStore {
pool: Option<authz::IpPool>,
) -> CreateResult<ExternalIp> {
let authz_pool = self
.resolve_pool_for_allocation(opctx, pool, IpPoolType::Unicast)
.resolve_pool_for_allocation(opctx, pool, IpPoolType::Unicast, None)
.await?;
let data = IncompleteExternalIp::for_ephemeral_probe(
ip_id,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl DataStore {
// IP was not attached, including on idempotent success.

let authz_pool = self
.resolve_pool_for_allocation(opctx, pool, IpPoolType::Unicast)
.resolve_pool_for_allocation(opctx, pool, IpPoolType::Unicast, None)
.await?;
let data = IncompleteExternalIp::for_ephemeral(ip_id, authz_pool.id());

Expand Down Expand Up @@ -198,11 +198,17 @@ impl DataStore {
identity: IdentityMetadataCreateParams,
ip: Option<IpAddr>,
pool: Option<authz::IpPool>,
ip_version: Option<IpVersion>,
) -> CreateResult<ExternalIp> {
let ip_id = Uuid::new_v4();

let authz_pool = self
.resolve_pool_for_allocation(opctx, pool, IpPoolType::Unicast)
.resolve_pool_for_allocation(
opctx,
pool,
IpPoolType::Unicast,
ip_version,
)
.await?;

let data = if let Some(ip) = ip {
Expand Down
Loading
Loading