Skip to content

Commit

Permalink
/v1/ip-pools/{pool} responds with SiloIpPool too
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Jan 18, 2024
1 parent 532dd5a commit b432677
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
9 changes: 4 additions & 5 deletions nexus/src/app/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,16 @@ impl super::Nexus {
&'a self,
opctx: &'a OpContext,
pool: &'a NameOrId,
) -> LookupResult<db::model::IpPool> {
) -> LookupResult<(db::model::IpPool, db::model::IpPoolResource)> {
let (authz_pool, pool) =
self.ip_pool_lookup(opctx, pool)?.fetch().await?;

// 404 if no link is found in the current silo
let link = self.db_datastore.ip_pool_fetch_link(opctx, pool.id()).await;
if link.is_err() {
return Err(authz_pool.not_found());
match link {
Ok(link) => Ok((pool, link)),
Err(_) => Err(authz_pool.not_found()),
}

Ok(pool)
}

/// List silos for a given pool
Expand Down
10 changes: 7 additions & 3 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,14 +1379,18 @@ async fn project_ip_pool_list(
async fn project_ip_pool_view(
rqctx: RequestContext<Arc<ServerContext>>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::IpPool>, HttpError> {
) -> Result<HttpResponseOk<views::SiloIpPool>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;
let nexus = &apictx.nexus;
let pool_selector = path_params.into_inner().pool;
let pool = nexus.silo_ip_pool_fetch(&opctx, &pool_selector).await?;
Ok(HttpResponseOk(IpPool::from(pool)))
let (pool, silo_link) =
nexus.silo_ip_pool_fetch(&opctx, &pool_selector).await?;
Ok(HttpResponseOk(views::SiloIpPool {
identity: pool.identity(),
is_default: silo_link.is_default,
}))
};
apictx.external_latencies.instrument_dropshot_handler(&rqctx, handler).await
}
Expand Down
10 changes: 10 additions & 0 deletions nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub static DEMO_SILO_NAME: Lazy<Name> =
Lazy::new(|| "demo-silo".parse().unwrap());
pub static DEMO_SILO_URL: Lazy<String> =
Lazy::new(|| format!("/v1/system/silos/{}", *DEMO_SILO_NAME));
pub static DEMO_SILO_IP_POOLS_URL: Lazy<String> =
Lazy::new(|| format!("{}/ip-pools", *DEMO_SILO_URL));
pub static DEMO_SILO_POLICY_URL: Lazy<String> =
Lazy::new(|| format!("/v1/system/silos/{}/policy", *DEMO_SILO_NAME));
pub static DEMO_SILO_QUOTAS_URL: Lazy<String> =
Expand Down Expand Up @@ -1110,6 +1112,14 @@ pub static VERIFY_ENDPOINTS: Lazy<Vec<VerifyEndpoint>> = Lazy::new(|| {
AllowedMethod::Delete,
],
},
VerifyEndpoint {
url: &DEMO_SILO_IP_POOLS_URL,
visibility: Visibility::Protected,
unprivileged_access: UnprivilegedAccess::None,
allowed_methods: vec![
AllowedMethod::Get,
],
},
VerifyEndpoint {
url: &DEMO_SILO_POLICY_URL,
visibility: Visibility::Protected,
Expand Down
3 changes: 2 additions & 1 deletion nexus/tests/integration_tests/ip_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,9 @@ async fn test_ip_pool_list_in_silo(cptestctx: &ControlPlaneTestContext) {

// fetch the pool directly too
let url = format!("/v1/ip-pools/{}", mypool_name);
let pool: IpPool = object_get(client, &url).await;
let pool = object_get::<SiloIpPool>(client, &url).await;
assert_eq!(pool.identity.name.as_str(), mypool_name);
assert!(pool.is_default);

// fetching the other pool directly 404s
let url = format!("/v1/ip-pools/{}", otherpool_name);
Expand Down
3 changes: 1 addition & 2 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ pub struct IpPool {
pub identity: IdentityMetadata,
}

/// A collection of IP ranges. If a pool is linked to a silo, IP addresses from
/// the pool can be allocated within that silo
/// An IP pool in the context of a silo, which means we can include is_default
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct SiloIpPool {
#[serde(flatten)]
Expand Down
4 changes: 2 additions & 2 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/IpPoolResultsPage"
"$ref": "#/components/schemas/SiloIpPoolResultsPage"
}
}
}
Expand Down Expand Up @@ -2232,7 +2232,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/IpPool"
"$ref": "#/components/schemas/SiloIpPool"
}
}
}
Expand Down

0 comments on commit b432677

Please sign in to comment.