Skip to content

Commit

Permalink
add bgp peer list / add / remove
Browse files Browse the repository at this point in the history
  • Loading branch information
internet-diglett committed Aug 30, 2024
1 parent de92b30 commit 22fe92a
Show file tree
Hide file tree
Showing 7 changed files with 992 additions and 334 deletions.
4 changes: 4 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,4 +1911,8 @@ allow_tables_to_appear_in_same_query!(
switch_port_settings_link_config,
switch_port_settings_address_config,
switch_port_settings_route_config,
switch_port_settings_bgp_peer_config,
switch_port_settings_bgp_peer_config_allow_export,
switch_port_settings_bgp_peer_config_allow_import,
switch_port_settings_bgp_peer_config_communities,
);
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub use region::RegionAllocationParameters;
pub use silo::Discoverability;
pub use sled::SledTransition;
pub use sled::TransitionError;
pub use switch_port::BgpPeerConfig;
pub use switch_port::SwitchPortSettingsCombinedResult;
pub use virtual_provisioning_collection::StorageType;
pub use vmm::VmmStateUpdateResult;
Expand Down
1,185 changes: 885 additions & 300 deletions nexus/db-queries/src/db/datastore/switch_port.rs

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions nexus/src/app/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ use nexus_db_model::SwitchPortRouteConfig;
use nexus_db_queries::authz;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db;
use nexus_db_queries::db::datastore::BgpPeerConfig;
use nexus_db_queries::db::datastore::UpdatePrecondition;
use nexus_db_queries::db::model::{SwitchPort, SwitchPortSettings};
use nexus_db_queries::db::DataStore;
use omicron_common::api::external::http_pagination::PaginatedBy;
use omicron_common::api::external::BgpPeer;
use omicron_common::api::external::SwitchLocation;
use omicron_common::api::external::{
self, CreateResult, DataPageParams, DeleteResult, Error, ListResultVec,
Expand Down Expand Up @@ -288,6 +290,49 @@ impl super::Nexus {
.await
}

pub(crate) async fn switch_port_configuration_bgp_peer_list(
&self,
opctx: &OpContext,
configuration: NameOrId,
) -> ListResultVec<BgpPeerConfig> {
opctx.authorize(authz::Action::Read, &authz::FLEET).await?;
self.db_datastore
.switch_port_configuration_bgp_peer_list(opctx, configuration)
.await
}

pub(crate) async fn switch_port_configuration_bgp_peer_add(
&self,
opctx: &OpContext,
configuration: NameOrId,
bgp_peer: BgpPeer,
) -> CreateResult<BgpPeerConfig> {
opctx.authorize(authz::Action::CreateChild, &authz::FLEET).await?;
self.db_datastore
.switch_port_configuration_bgp_peer_add(
opctx,
configuration,
bgp_peer,
)
.await
}

pub(crate) async fn switch_port_configuration_bgp_peer_remove(
&self,
opctx: &OpContext,
configuration: NameOrId,
bgp_peer: BgpPeer,
) -> DeleteResult {
opctx.authorize(authz::Action::Delete, &authz::FLEET).await?;
self.db_datastore
.switch_port_configuration_bgp_peer_remove(
opctx,
configuration,
bgp_peer,
)
.await
}

async fn switch_port_create(
&self,
opctx: &OpContext,
Expand Down
76 changes: 44 additions & 32 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ use nexus_db_queries::db::identity::Resource;
use nexus_db_queries::db::lookup::ImageLookup;
use nexus_db_queries::db::lookup::ImageParentLookup;
use nexus_db_queries::db::model::Name;
use nexus_types::external_api::{
params::BgpPeerConfig,
shared::{BfdStatus, ProbeInfo},
};
use nexus_types::external_api::shared::{BfdStatus, ProbeInfo};
use omicron_common::api::external::AddressLot;
use omicron_common::api::external::AddressLotCreateResponse;
use omicron_common::api::external::AggregateBgpMessageHistory;
Expand Down Expand Up @@ -279,51 +276,49 @@ pub(crate) fn external_api() -> NexusApiDescription {
api.register(networking_switch_port_configuration_delete)?;

// /v1/system/networking/switch-port-configuration/{name_or_id}/geometry
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_geometry_view)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_geometry_set)?;

// /v1/system/networking/switch-port-configuration/{name_or_id}/link
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_link_create)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_link_delete)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_link_view)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_link_list)?;

// /v1/system/networking/switch-port-configuration/{name_or_id}/interface/{interface}/address
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_address_add)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_address_remove)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_address_list)?;

// /v1/system/networking/switch-port-configuration/{name_or_id}/interface/{interface}/route
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_route_add)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_route_remove)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_route_list)?;

// /v1/system/networking/switch-port-configuration/{name_or_id}/interface/{interface}/bgp-peer
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_bgp_peer_add)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_bgp_peer_remove)?;
// TODO: Levon - test
// TODO: Levon - add tests
api.register(networking_switch_port_configuration_bgp_peer_list)?;

api.register(networking_switch_port_list)?;
api.register(networking_switch_port_status)?;
api.register(networking_switch_port_apply_settings)?;
api.register(networking_switch_port_clear_settings)?;
// TODO: Levon - test
// api.register(networking_switch_port_view_settings)?;

api.register(networking_bgp_config_create)?;
api.register(networking_bgp_config_list)?;
Expand Down Expand Up @@ -4190,7 +4185,7 @@ async fn networking_switch_port_configuration_route_add(
.await
}

/// Remove address from an interface configuration
/// Remove route from an interface configuration
#[endpoint {
method = POST,
path ="/v1/system/networking/switch-port-configuration/{configuration}/route/remove",
Expand Down Expand Up @@ -4233,15 +4228,18 @@ async fn networking_switch_port_configuration_route_remove(
async fn networking_switch_port_configuration_bgp_peer_list(
rqctx: RequestContext<ApiContext>,
path_params: Path<params::SwitchPortSettingsInfoSelector>,
) -> Result<HttpResponseOk<BgpPeerConfig>, HttpError> {
) -> Result<HttpResponseOk<Vec<BgpPeer>>, HttpError> {
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;
let query = path_params.into_inner().configuration;
let configuration = path_params.into_inner().configuration;
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;

let settings = nexus.switch_port_settings_get(&opctx, &query).await?;
todo!("list interface routes")
let settings = nexus
.switch_port_configuration_bgp_peer_list(&opctx, configuration)
.await?;

Ok(HttpResponseOk(settings.into_iter().map(Into::into).collect()))
};
apictx
.context
Expand All @@ -4264,11 +4262,18 @@ async fn networking_switch_port_configuration_bgp_peer_add(
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;
let query = path_params.into_inner().configuration;
let configuration = path_params.into_inner().configuration;
let bgp_peer = bgp_peer.into_inner();
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;

let settings = nexus.switch_port_settings_get(&opctx, &query).await?;
todo!("add interface route")
let settings = nexus
.switch_port_configuration_bgp_peer_add(
&opctx,
configuration,
bgp_peer,
)
.await?;
Ok(HttpResponseCreated(settings.into()))
};
apictx
.context
Expand All @@ -4291,11 +4296,18 @@ async fn networking_switch_port_configuration_bgp_peer_remove(
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.context.nexus;
let query = path_params.into_inner().configuration;
let configuration = path_params.into_inner().configuration;
let bgp_peer = bgp_peer.into_inner();
let opctx = crate::context::op_context_for_external_api(&rqctx).await?;

let settings = nexus.switch_port_settings_get(&opctx, &query).await?;
todo!("remove interface route")
nexus
.switch_port_configuration_bgp_peer_remove(
&opctx,
configuration,
bgp_peer,
)
.await?;
Ok(HttpResponseDeleted())
};
apictx
.context
Expand Down
7 changes: 7 additions & 0 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,13 @@ pub struct OptionalBgpAnnounceSetSelector {
pub name_or_id: Option<NameOrId>,
}

/// Optionally select a BGP Peer by a name or id.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct OptionalBgpPeerSelector {
/// A name or id to use when filtering or paginating bgp peers
pub name_or_id: Option<NameOrId>,
}

/// Select a BGP announce set by a name or id.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
pub struct BgpAnnounceSetSelector {
Expand Down
8 changes: 6 additions & 2 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -7423,7 +7423,11 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BgpPeerConfig"
"title": "Array_of_BgpPeer",
"type": "array",
"items": {
"$ref": "#/components/schemas/BgpPeer"
}
}
}
}
Expand Down Expand Up @@ -7878,7 +7882,7 @@
"tags": [
"system/networking"
],
"summary": "Remove address from an interface configuration",
"summary": "Remove route from an interface configuration",
"operationId": "networking_switch_port_configuration_route_remove",
"parameters": [
{
Expand Down

0 comments on commit 22fe92a

Please sign in to comment.