Skip to content

Commit

Permalink
rename IP pools list and view endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Jun 20, 2024
1 parent 75f5b67 commit 82915c2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
58 changes: 29 additions & 29 deletions end-to-end-tests/src/bin/commtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,37 +279,37 @@ async fn rack_prepare(
})?;

let pool_name = "default";
api_retry!(
if let Err(e) = oxide.ip_pool_view().pool("default").send().await {
if let Some(reqwest::StatusCode::NOT_FOUND) = e.status() {
print!("default ip pool does not exist, creating ...");
oxide
.ip_pool_create()
.body(IpPoolCreate {
name: pool_name.parse().unwrap(),
description: "Default IP pool".to_string(),
})
.send()
.await?;
oxide
.ip_pool_silo_link()
.pool(pool_name)
.body(IpPoolLinkSilo {
silo: NameOrId::Name("recovery".parse().unwrap()),
is_default: true,
})
.send()
.await?;
println!("done");
Ok(())
} else {
Err(e)
}
} else {
println!("default ip pool already exists");
api_retry!(if let Err(e) =
oxide.system_ip_pool_view().pool("default").send().await
{
if let Some(reqwest::StatusCode::NOT_FOUND) = e.status() {
print!("default ip pool does not exist, creating ...");
oxide
.ip_pool_create()
.body(IpPoolCreate {
name: pool_name.parse().unwrap(),
description: "Default IP pool".to_string(),
})
.send()
.await?;
oxide
.ip_pool_silo_link()
.pool(pool_name)
.body(IpPoolLinkSilo {
silo: NameOrId::Name("recovery".parse().unwrap()),
is_default: true,
})
.send()
.await?;
println!("done");
Ok(())
} else {
Err(e)
}
)?;
} else {
println!("default ip pool already exists");
Ok(())
})?;

let pool = api_retry!(
oxide
Expand Down
27 changes: 17 additions & 10 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ pub(crate) fn external_api() -> NexusApiDescription {
api.register(project_update)?;
api.register(project_policy_view)?;
api.register(project_policy_update)?;
api.register(project_ip_pool_list)?;
api.register(project_ip_pool_view)?;
api.register(ip_pool_list)?;
api.register(ip_pool_view)?;

// Operator-Accessible IP Pools API
api.register(ip_pool_list)?;
api.register(system_ip_pool_list)?;
api.register(system_ip_pool_view)?;
api.register(ip_pool_create)?;
api.register(ip_pool_silo_list)?;
api.register(ip_pool_silo_link)?;
api.register(ip_pool_silo_unlink)?;
api.register(ip_pool_silo_update)?;
api.register(ip_pool_view)?;
api.register(ip_pool_delete)?;
api.register(ip_pool_update)?;
// Variants for internal services
Expand Down Expand Up @@ -1506,12 +1506,14 @@ async fn project_policy_update(
// IP Pools

/// List IP pools
///
/// List IP pools linked to current silo.
#[endpoint {
method = GET,
path = "/v1/ip-pools",
tags = ["projects"],
tags = ["silos"],
}]
async fn project_ip_pool_list(
async fn ip_pool_list(
rqctx: RequestContext<ApiContext>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<views::SiloIpPool>>, HttpError> {
Expand Down Expand Up @@ -1546,12 +1548,14 @@ async fn project_ip_pool_list(
}

/// Fetch IP pool
///
/// Fetch IP pool linked to current silo.
#[endpoint {
method = GET,
path = "/v1/ip-pools/{pool}",
tags = ["projects"],
tags = ["silos"],
}]
async fn project_ip_pool_view(
async fn ip_pool_view(
rqctx: RequestContext<ApiContext>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::SiloIpPool>, HttpError> {
Expand All @@ -1574,13 +1578,16 @@ async fn project_ip_pool_view(
.await
}

// Note system_ prefix only on list and view because they need to be distinguished
// from silo-scoped list and view

/// List IP pools
#[endpoint {
method = GET,
path = "/v1/system/ip-pools",
tags = ["system/networking"],
}]
async fn ip_pool_list(
async fn system_ip_pool_list(
rqctx: RequestContext<ApiContext>,
query_params: Query<PaginatedByNameOrId>,
) -> Result<HttpResponseOk<ResultsPage<IpPool>>, HttpError> {
Expand Down Expand Up @@ -1647,7 +1654,7 @@ async fn ip_pool_create(
path = "/v1/system/ip-pools/{pool}",
tags = ["system/networking"],
}]
async fn ip_pool_view(
async fn system_ip_pool_view(
rqctx: RequestContext<ApiContext>,
path_params: Path<params::IpPoolPath>,
) -> Result<HttpResponseOk<views::IpPool>, HttpError> {
Expand Down
8 changes: 4 additions & 4 deletions nexus/tests/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ API operations found with tag "projects"
OPERATION ID METHOD URL PATH
project_create POST /v1/projects
project_delete DELETE /v1/projects/{project}
project_ip_pool_list GET /v1/ip-pools
project_ip_pool_view GET /v1/ip-pools/{pool}
project_list GET /v1/projects
project_policy_update PUT /v1/projects/{project}/policy
project_policy_view GET /v1/projects/{project}/policy
Expand Down Expand Up @@ -115,6 +113,8 @@ certificate_list GET /v1/certificates
certificate_view GET /v1/certificates/{certificate}
group_list GET /v1/groups
group_view GET /v1/groups/{group_id}
ip_pool_list GET /v1/ip-pools
ip_pool_view GET /v1/ip-pools/{pool}
policy_update PUT /v1/policy
policy_view GET /v1/policy
user_list GET /v1/users
Expand Down Expand Up @@ -155,7 +155,6 @@ API operations found with tag "system/networking"
OPERATION ID METHOD URL PATH
ip_pool_create POST /v1/system/ip-pools
ip_pool_delete DELETE /v1/system/ip-pools/{pool}
ip_pool_list GET /v1/system/ip-pools
ip_pool_range_add POST /v1/system/ip-pools/{pool}/ranges/add
ip_pool_range_list GET /v1/system/ip-pools/{pool}/ranges
ip_pool_range_remove POST /v1/system/ip-pools/{pool}/ranges/remove
Expand All @@ -169,7 +168,6 @@ ip_pool_silo_unlink DELETE /v1/system/ip-pools/{pool}/sil
ip_pool_silo_update PUT /v1/system/ip-pools/{pool}/silos/{silo}
ip_pool_update PUT /v1/system/ip-pools/{pool}
ip_pool_utilization_view GET /v1/system/ip-pools/{pool}/utilization
ip_pool_view GET /v1/system/ip-pools/{pool}
networking_address_lot_block_list GET /v1/system/networking/address-lot/{address_lot}/blocks
networking_address_lot_create POST /v1/system/networking/address-lot
networking_address_lot_delete DELETE /v1/system/networking/address-lot/{address_lot}
Expand All @@ -195,6 +193,8 @@ networking_switch_port_settings_create POST /v1/system/networking/switch-p
networking_switch_port_settings_delete DELETE /v1/system/networking/switch-port-settings
networking_switch_port_settings_list GET /v1/system/networking/switch-port-settings
networking_switch_port_settings_view GET /v1/system/networking/switch-port-settings/{port}
system_ip_pool_list GET /v1/system/ip-pools
system_ip_pool_view GET /v1/system/ip-pools/{pool}

API operations found with tag "system/silos"
OPERATION ID METHOD URL PATH
Expand Down
14 changes: 8 additions & 6 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2679,10 +2679,11 @@
"/v1/ip-pools": {
"get": {
"tags": [
"projects"
"silos"
],
"summary": "List IP pools",
"operationId": "project_ip_pool_list",
"description": "List IP pools linked to current silo.",
"operationId": "ip_pool_list",
"parameters": [
{
"in": "query",
Expand Down Expand Up @@ -2738,10 +2739,11 @@
"/v1/ip-pools/{pool}": {
"get": {
"tags": [
"projects"
"silos"
],
"summary": "Fetch IP pool",
"operationId": "project_ip_pool_view",
"description": "Fetch IP pool linked to current silo.",
"operationId": "ip_pool_view",
"parameters": [
{
"in": "path",
Expand Down Expand Up @@ -5267,7 +5269,7 @@
"system/networking"
],
"summary": "List IP pools",
"operationId": "ip_pool_list",
"operationId": "system_ip_pool_list",
"parameters": [
{
"in": "query",
Expand Down Expand Up @@ -5361,7 +5363,7 @@
"system/networking"
],
"summary": "Fetch IP pool",
"operationId": "ip_pool_view",
"operationId": "system_ip_pool_view",
"parameters": [
{
"in": "path",
Expand Down

0 comments on commit 82915c2

Please sign in to comment.