Skip to content
9 changes: 9 additions & 0 deletions common/src/api/external/http_pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ pub enum PaginatedBy<'a> {
Name(DataPageParams<'a, Name>),
}

impl<'a> PaginatedBy<'a> {
pub fn limit(&self) -> NonZeroU32 {
match self {
PaginatedBy::Id(inner) => inner.limit,
PaginatedBy::Name(inner) => inner.limit,
}
}
}

impl<T: Clone + Debug + DeserializeOwned + JsonSchema + PartialEq + Serialize>
ScanParams for ScanByNameOrId<T>
{
Expand Down
33 changes: 32 additions & 1 deletion nexus/db-model/src/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ impl From<IpVersion> for shared::IpVersion {
/// IP pools can be external or internal. External IP pools can be associated
/// with a silo or project so that instance IP allocation draws from that pool
/// instead of a system pool.
#[derive(Queryable, Insertable, Selectable, Clone, Debug, Resource)]
#[derive(
Queryable, Insertable, Selectable, Clone, Debug, Resource, PartialEq,
)]
#[diesel(table_name = ip_pool)]
pub struct IpPool {
#[diesel(embed)]
Expand All @@ -89,9 +91,15 @@ pub struct IpPool {
/// Child resource generation number, for optimistic concurrency control of
/// the contained ranges.
pub rcgen: i64,

/// True if the IP Pool has been delegated for Oxide use.
pub is_delegated: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming at this review without much context, I'm wondering if is_delegated is too vague/generic and should say what it's delegated to, although I don't know how to be more specific without making it a lot longer. is_delegated_to_services? is_delegated_to_oxide? Entirely possible this is fine as-is and "look at the doc comment to see what it's delegated to", especially if we don't think we'll ever have other kinds of IP pool delegation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgallagher and I talked a bit live about this. I think we'll change the name here to something like purpose or intended_use, and make this an enum rather than a bool. We'd have two variants today, indicating the pool can be used for external silos or for Oxide internal use. We can add variants if we need in the future for expressing things like "use by Nexus" or "use by external DNS".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated all this in e4ff3b8.

}

impl IpPool {
/// Create a new IP Pool.
///
/// The pool is not delegated to Oxide.
pub fn new(
pool_identity: &external::IdentityMetadataCreateParams,
ip_version: IpVersion,
Expand All @@ -103,15 +111,38 @@ impl IpPool {
),
ip_version,
rcgen: 0,
is_delegated: false,
}
}

/// Create a new pool delegated for Oxide's internal use.
pub fn new_delegated(
pool_identity: &external::IdentityMetadataCreateParams,
ip_version: IpVersion,
) -> Self {
Self {
identity: IpPoolIdentity::new(
Uuid::new_v4(),
pool_identity.clone(),
),
ip_version,
rcgen: 0,
is_delegated: true,
}
}

/// Create a new IPv4 IP Pool.
///
/// The pool is not delegated to Oxide.
pub fn new_v4(
pool_identity: &external::IdentityMetadataCreateParams,
) -> Self {
Self::new(pool_identity, IpVersion::V4)
}

/// Create a new IPv6 IP Pool.
///
/// The pool is not delegated to Oxide.
pub fn new_v6(
pool_identity: &external::IdentityMetadataCreateParams,
) -> Self {
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(195, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(196, 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(196, "add-ip-pool-is-delegated-column"),
KnownVersion::new(195, "tuf-pruned-index"),
KnownVersion::new(194, "tuf-pruned"),
KnownVersion::new(193, "nexus-lockstep-port"),
Expand Down
Loading
Loading