@@ -14,6 +14,7 @@ use crate::db::collection_insert::DatastoreCollection;
1414use crate :: db:: error:: diesel_pool_result_optional;
1515use crate :: db:: error:: public_error_from_diesel_pool;
1616use crate :: db:: error:: ErrorHandler ;
17+ use crate :: db:: fixed_data:: silo:: INTERNAL_SILO_ID ;
1718use crate :: db:: identity:: Resource ;
1819use crate :: db:: lookup:: LookupPath ;
1920use crate :: db:: model:: IpPool ;
@@ -27,7 +28,6 @@ use async_bb8_diesel::{AsyncRunQueryDsl, PoolError};
2728use chrono:: Utc ;
2829use diesel:: prelude:: * ;
2930use ipnetwork:: IpNetwork ;
30- use nexus_types:: external_api:: params;
3131use nexus_types:: external_api:: shared:: IpRange ;
3232use omicron_common:: api:: external:: http_pagination:: PaginatedBy ;
3333use omicron_common:: api:: external:: CreateResult ;
@@ -65,7 +65,8 @@ impl DataStore {
6565 & pagparams. map_name ( |n| Name :: ref_cast ( n) ) ,
6666 ) ,
6767 }
68- . filter ( dsl:: internal. eq ( false ) )
68+ // != excludes nulls so we explicitly include them
69+ . filter ( dsl:: silo_id. ne ( * INTERNAL_SILO_ID ) . or ( dsl:: silo_id. is_null ( ) ) )
6970 . filter ( dsl:: time_deleted. is_null ( ) )
7071 . select ( db:: model:: IpPool :: as_select ( ) )
7172 . get_results_async ( self . pool_authorized ( opctx) . await ?)
@@ -98,7 +99,8 @@ impl DataStore {
9899 . ip_pool_name ( & name)
99100 . fetch_for ( action)
100101 . await ?;
101- if pool. internal {
102+ // Can't look up the internal pool
103+ if pool. silo_id == Some ( * INTERNAL_SILO_ID ) {
102104 return Err ( authz_pool. not_found ( ) ) ;
103105 }
104106
@@ -120,7 +122,7 @@ impl DataStore {
120122
121123 // Look up this IP pool by rack ID.
122124 let ( authz_pool, pool) = dsl:: ip_pool
123- . filter ( dsl:: internal . eq ( true ) )
125+ . filter ( dsl:: silo_id . eq ( * INTERNAL_SILO_ID ) )
124126 . filter ( dsl:: time_deleted. is_null ( ) )
125127 . select ( IpPool :: as_select ( ) )
126128 . get_result_async ( self . pool_authorized ( opctx) . await ?)
@@ -142,20 +144,15 @@ impl DataStore {
142144 }
143145
144146 /// Creates a new IP pool.
145- ///
146- /// - If `internal` is set, this IP pool is used for Oxide services.
147147 pub async fn ip_pool_create (
148148 & self ,
149149 opctx : & OpContext ,
150- new_pool : & params:: IpPoolCreate ,
151- internal : bool ,
152- silo_id : Option < Uuid > ,
150+ pool : IpPool ,
153151 ) -> CreateResult < IpPool > {
154152 use db:: schema:: ip_pool:: dsl;
155153 opctx
156154 . authorize ( authz:: Action :: CreateChild , & authz:: IP_POOL_LIST )
157155 . await ?;
158- let pool = IpPool :: new ( & new_pool. identity , internal, silo_id) ;
159156 let pool_name = pool. name ( ) . as_str ( ) . to_string ( ) ;
160157
161158 diesel:: insert_into ( dsl:: ip_pool)
@@ -205,7 +202,10 @@ impl DataStore {
205202 // in between the above check for children and this query.
206203 let now = Utc :: now ( ) ;
207204 let updated_rows = diesel:: update ( dsl:: ip_pool)
208- . filter ( dsl:: internal. eq ( false ) )
205+ // != excludes nulls so we explicitly include them
206+ . filter (
207+ dsl:: silo_id. ne ( * INTERNAL_SILO_ID ) . or ( dsl:: silo_id. is_null ( ) ) ,
208+ )
209209 . filter ( dsl:: time_deleted. is_null ( ) )
210210 . filter ( dsl:: id. eq ( authz_pool. id ( ) ) )
211211 . filter ( dsl:: rcgen. eq ( db_pool. rcgen ) )
@@ -237,7 +237,10 @@ impl DataStore {
237237 use db:: schema:: ip_pool:: dsl;
238238 opctx. authorize ( authz:: Action :: Modify , authz_pool) . await ?;
239239 diesel:: update ( dsl:: ip_pool)
240- . filter ( dsl:: internal. eq ( false ) )
240+ // != excludes nulls so we explicitly include them
241+ . filter (
242+ dsl:: silo_id. ne ( * INTERNAL_SILO_ID ) . or ( dsl:: silo_id. is_null ( ) ) ,
243+ )
241244 . filter ( dsl:: id. eq ( authz_pool. id ( ) ) )
242245 . filter ( dsl:: time_deleted. is_null ( ) )
243246 . set ( updates)
0 commit comments