Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cd6c856
WIP: refactor of operator api networking endpoints
Jun 18, 2024
c5f042b
Merge branch 'main' into refactor-networking-apis
internet-diglett Jul 4, 2024
65b25dc
fix address lot testing
internet-diglett Jul 4, 2024
7bccb1b
refactor address lot APIs to resemble ip pools
internet-diglett Jul 8, 2024
812e991
rename AddressLotBlock params
internet-diglett Jul 17, 2024
85abe0e
Merge branch 'main' into refactor-networking-apis
internet-diglett Jul 17, 2024
047c6fe
WIP: allow partial update of switch port configuration
internet-diglett Jul 23, 2024
8a807d9
fixup! WIP: allow partial update of switch port configuration
internet-diglett Jul 29, 2024
78033b5
plumb through switch port geometry
internet-diglett Jul 31, 2024
d8c2f42
fixup! plumb through switch port geometry
internet-diglett Jul 31, 2024
bca07fe
list links
internet-diglett Aug 1, 2024
30c217c
return structured data for geometry
internet-diglett Aug 1, 2024
7000904
plumb through switch port link configuration
internet-diglett Aug 6, 2024
1c695d0
WIP: plumb switch port link create
internet-diglett Aug 6, 2024
ba50716
create / delete link config
internet-diglett Aug 9, 2024
d5b5553
Merge branch 'main' into refactor-networking-apis-2
internet-diglett Aug 27, 2024
6eb4be4
WIP: interface address management
internet-diglett Aug 27, 2024
69ff1f0
WIP: interface address management
internet-diglett Aug 29, 2024
2e392d2
WIP: more refactor work
internet-diglett Aug 29, 2024
8cad50e
Make addresses list-able without knowing interface name
internet-diglett Aug 29, 2024
7a32cbd
regen openapi
internet-diglett Aug 29, 2024
2377850
fix address remove logic
internet-diglett Aug 30, 2024
8416cac
WIP: route add / remove
internet-diglett Aug 30, 2024
d991823
WIP: route add / remove
internet-diglett Aug 30, 2024
de92b30
WIP: route add / remove / list
internet-diglett Aug 30, 2024
22fe92a
add bgp peer list / add / remove
internet-diglett Aug 30, 2024
193bcaf
don't require entire peer config for peer removal
internet-diglett Aug 30, 2024
1360445
WIP: bgp import/export/community add and list
internet-diglett Aug 30, 2024
a392a80
WIP: finish roughing out bgp import/export/community endpoints
internet-diglett Aug 30, 2024
a1a70fd
WIP: breakout bgp peer import/export/communities
internet-diglett Aug 31, 2024
b1cbebe
WIP unsquash switch port query errors
internet-diglett Sep 10, 2024
822953e
WIP: update tests
internet-diglett Oct 15, 2024
9ef3456
add integration tests for new endpoints
internet-diglett Oct 16, 2024
f65f6f9
change const to static in test fixtures
internet-diglett Oct 16, 2024
2225b77
Round 1 of PR review fixes
internet-diglett Oct 18, 2024
155e5d4
Round 2 of PR review fixes
internet-diglett Oct 19, 2024
36d700a
Endpoints for managing active switch port configs
internet-diglett Oct 22, 2024
4140aad
add tests for new active-configuration endpoints
internet-diglett Oct 24, 2024
4edf90a
Merge branch 'main' into refactor-networking-apis
internet-diglett Oct 25, 2024
7d8e38f
regen authz txt
internet-diglett Oct 25, 2024
d1e4739
Merge branch 'main' into refactor-networking-apis
internet-diglett Oct 27, 2024
4f04635
remove unused params
internet-diglett Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,7 @@ pub struct BgpPeerCombined {
/// peer.
pub bgp_config: NameOrId,

/// The name of interface to peer on. This is relative to the port
/// The name of the interface to peer on. This is relative to the port
/// configuration this BGP peer configuration is a part of. For example this
/// value could be phy0 to refer to a primary physical interface. Or it
/// could be vlan47 to refer to a VLAN interface.
Expand All @@ -2672,19 +2672,19 @@ pub struct BgpPeerCombined {
/// How often to send keepalive requests (seconds).
pub keepalive: u32,

/// Require that a peer has a specified ASN.
/// Require that this peer has a specified ASN.
pub remote_asn: Option<u32>,

/// Require messages from a peer have a minimum IP time to live field.
/// Require messages from this peer have a minimum IP time to live field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: "Require that messages...", to be consistent with line 2675.

pub min_ttl: Option<u8>,

/// Use the given key for TCP-MD5 authentication with the peer.
/// Use the given key for TCP-MD5 authentication with this peer.
pub md5_auth_key: Option<String>,

/// Apply the provided multi-exit discriminator (MED) updates sent to the peer.
/// Apply a multi-exit discriminator (MED) in updates sent to this peer.
pub multi_exit_discriminator: Option<u32>,

/// Include the provided communities in updates sent to the peer.
/// Include the provided communities in updates sent to this peer.
pub communities: Vec<u32>,

/// Apply a local preference to routes received from this peer.
Expand All @@ -2693,13 +2693,13 @@ pub struct BgpPeerCombined {
/// Enforce that the first AS in paths received from this peer is the peer's AS.
pub enforce_first_as: bool,

/// Define import policy for a peer.
/// Define import policy for this peer.
pub allowed_import: ImportExportPolicy,

/// Define export policy for a peer.
/// Define export policy for this peer.
pub allowed_export: ImportExportPolicy,

/// Associate a VLAN ID with a peer.
/// Associate a VLAN ID with this peer.
pub vlan_id: Option<u16>,
}

Expand All @@ -2710,7 +2710,7 @@ pub struct BgpPeer {
/// peer.
pub bgp_config: NameOrId,

/// The name of interface to peer on. This is relative to the port
/// The name of the interface to peer on. This is relative to the port
/// configuration this BGP peer configuration is a part of. For example this
/// value could be phy0 to refer to a primary physical interface. Or it
/// could be vlan47 to refer to a VLAN interface.
Expand All @@ -2722,7 +2722,7 @@ pub struct BgpPeer {
/// How long to hold peer connections between keepalives (seconds).
pub hold_time: u32,

/// How long to hold a peer in idle before attempting a new session
/// How long to hold this peer in idle before attempting a new session
/// (seconds).
pub idle_hold_time: u32,

Expand All @@ -2736,16 +2736,16 @@ pub struct BgpPeer {
/// How often to send keepalive requests (seconds).
pub keepalive: u32,

/// Require that a peer has a specified ASN.
/// Require that this peer have a specified ASN.
pub remote_asn: Option<u32>,

/// Require messages from a peer have a minimum IP time to live field.
/// Require messages from this peer to have a minimum IP time to live field.
pub min_ttl: Option<u8>,

/// Use the given key for TCP-MD5 authentication with the peer.
/// Use the given key for TCP-MD5 authentication with this peer.
pub md5_auth_key: Option<String>,

/// Apply the provided multi-exit discriminator (MED) updates sent to the peer.
/// Apply a multi-exit discriminator (MED) in updates sent to this peer.
pub multi_exit_discriminator: Option<u32>,

/// Apply a local preference to routes received from this peer.
Expand All @@ -2760,7 +2760,7 @@ pub struct BgpPeer {
/// Enable export policies
pub allow_export_list_active: bool,

/// Associate a VLAN ID with a peer.
/// Associate a VLAN ID with this peer.
pub vlan_id: Option<u16>,
}

Expand All @@ -2771,7 +2771,7 @@ pub struct BgpPeerRemove {
/// peer.
pub bgp_config: NameOrId,

/// The name of interface to peer on. This is relative to the port
/// The name of the interface to peer on. This is relative to the port
/// configuration this BGP peer configuration is a part of. For example this
/// value could be phy0 to refer to a primary physical interface. Or it
/// could be vlan47 to refer to a VLAN interface.
Expand Down
13 changes: 2 additions & 11 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2020,17 +2020,6 @@ allow_tables_to_appear_in_same_query!(external_ip, internet_gateway);
allow_tables_to_appear_in_same_query!(external_ip, internet_gateway_ip_pool);
allow_tables_to_appear_in_same_query!(external_ip, internet_gateway_ip_address);

allow_tables_to_appear_in_same_query!(
switch_port,
switch_port_settings_route_config
);

allow_tables_to_appear_in_same_query!(
switch_port,
switch_port_settings_bgp_peer_config,
bgp_config
);

allow_tables_to_appear_in_same_query!(disk, virtual_provisioning_resource);

allow_tables_to_appear_in_same_query!(volume, virtual_provisioning_resource);
Expand All @@ -2044,6 +2033,7 @@ allow_tables_to_appear_in_same_query!(sled, sled_instance);
joinable!(network_interface -> probe (parent_id));

allow_tables_to_appear_in_same_query!(
switch_port,
switch_port_settings,
switch_port_settings_port_config,
switch_port_settings_link_config,
Expand All @@ -2053,4 +2043,5 @@ allow_tables_to_appear_in_same_query!(
switch_port_settings_bgp_peer_config_allow_export,
switch_port_settings_bgp_peer_config_allow_import,
switch_port_settings_bgp_peer_config_communities,
bgp_config,
);
25 changes: 23 additions & 2 deletions nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::BTreeMap;
///
/// 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: SemverVersion = SemverVersion::new(91, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(112, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -29,7 +29,28 @@ static KNOWN_VERSIONS: Lazy<Vec<KnownVersion>> = Lazy::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(91, "refactor-network-apis"),
KnownVersion::new(112, "refactor-network-apis"),
KnownVersion::new(111, "drop-omicron-zone-underlay-address"),
KnownVersion::new(110, "clickhouse-policy"),
KnownVersion::new(109, "inv-clickhouse-keeper-membership"),
KnownVersion::new(108, "internet-gateway"),
KnownVersion::new(107, "add-instance-boot-disk"),
KnownVersion::new(106, "dataset-kinds-update"),
KnownVersion::new(105, "inventory-nvme-firmware"),
KnownVersion::new(104, "lookup-bgp-config-indexes"),
KnownVersion::new(103, "lookup-instances-by-state-index"),
KnownVersion::new(102, "add-instance-auto-restart-cooldown"),
KnownVersion::new(101, "auto-restart-policy-v2"),
KnownVersion::new(100, "add-instance-last-auto-restarted-timestamp"),
KnownVersion::new(99, "blueprint-add-clickhouse-tables"),
KnownVersion::new(98, "oximeter-add-time-expunged"),
KnownVersion::new(97, "lookup-region-snapshot-by-region-id"),
KnownVersion::new(96, "inv-dataset"),
KnownVersion::new(95, "turn-boot-on-fault-into-auto-restart"),
KnownVersion::new(94, "put-back-creating-vmm-state"),
KnownVersion::new(93, "dataset-kinds-zone-and-debug"),
KnownVersion::new(92, "lldp-link-config-nullable"),
KnownVersion::new(91, "add-management-gateway-producer-kind"),
KnownVersion::new(90, "lookup-bgp-config-by-asn"),
KnownVersion::new(89, "collapse_lldp_settings"),
KnownVersion::new(88, "route-local-pref"),
Expand Down
7 changes: 1 addition & 6 deletions nexus/db-queries/src/db/datastore/bgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,12 +1049,7 @@ mod tests {
.expect("create bgp config");

datastore
.bgp_config_delete(
&opctx,
&params::BgpConfigSelector {
name_or_id: NameOrId::Name(config_name),
},
)
.bgp_config_delete(&opctx, &NameOrId::Name(config_name))
.await
.expect("delete bgp config by name");

Expand Down
66 changes: 50 additions & 16 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use omicron_common::api::external::http_pagination::PaginatedBy;
use omicron_common::api::external::{
self, BgpPeer, BgpPeerRemove, CreateResult, DataPageParams, DeleteResult,
Error, ImportExportPolicy, ListResultVec, LookupResult, NameOrId,
ResourceType, UpdateResult,
ResourceType, SwitchLocation, UpdateResult,
};
use ref_cast::RefCast;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -467,7 +467,7 @@ impl DataStore {
let lldp_link_ids: Vec<Uuid> = result
.links
.iter()
.map(|link| link.lldp_link_config_id)
.filter_map(|link| link.lldp_link_config_id)
.collect();

use db::schema::lldp_link_config;
Expand Down Expand Up @@ -799,7 +799,7 @@ impl DataStore {

let link_config = SwitchPortLinkConfig {
port_settings_id: parent_id,
lldp_link_config_id,
lldp_link_config_id: Some(lldp_link_config_id),
link_name: new_settings.name.to_string(),
mtu: new_settings.mtu.into(),
fec: new_settings.fec.into(),
Expand Down Expand Up @@ -894,12 +894,12 @@ impl DataStore {
.await?;

// delete lldp service configuration
diesel::delete(lldp_link_dsl::lldp_link_config)
.filter(
lldp_link_dsl::id.eq(config.lldp_link_config_id),
)
.execute_async(&conn)
.await?;
if let Some(lldp_config_id) = config.lldp_link_config_id {
diesel::delete(lldp_link_dsl::lldp_link_config)
.filter(lldp_link_dsl::id.eq(lldp_config_id))
.execute_async(&conn)
.await?;
}

Ok(())
}
Expand Down Expand Up @@ -1060,8 +1060,8 @@ impl DataStore {
.map_err(|e| match e {
ReserveBlockTxnError::CustomError(e) => {
let message = match e {
ReserveBlockError::AddressUnavailable => "address is unavailable",
ReserveBlockError::AddressNotInLot => "address is not in lot",
ReserveBlockError::AddressUnavailable => "address unavailable",
ReserveBlockError::AddressNotInLot => "address not in lot",
};
err.bail(Error::conflict(message))
}
Expand Down Expand Up @@ -1296,7 +1296,7 @@ impl DataStore {
dst: new_settings.dst.into(),
gw: new_settings.gw.into(),
vid: new_settings.vid.map(Into::into),
local_pref: new_settings.local_pref.map(Into::into),
rib_priority: new_settings.rib_priority.map(Into::into),
};

let config = diesel::insert_into(route_config::table)
Expand Down Expand Up @@ -1890,7 +1890,7 @@ impl DataStore {
},
None => {
error!(opctx.log, "{message}"; "error" => ?e);
Error::internal_error("error while adding prefix to allowed import list")
Error::internal_error("error while adding entry to allowed import list")
},
}
})
Expand Down Expand Up @@ -2094,7 +2094,7 @@ impl DataStore {
},
None => {
error!(opctx.log, "{message}"; "error" => ?e);
Error::internal_error("error while adding prefix to allowed export list")
Error::internal_error("error while adding entry to allowed export list")
},
}
})
Expand Down Expand Up @@ -2210,7 +2210,7 @@ impl DataStore {
.load_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e: diesel::result::Error| {
let msg = "error while looking up bgp peer allowed export list";
let msg = "error while looking up bgp peer community list";
error!(opctx.log, "{msg}"; "error" => ?e);
Error::internal_error(msg)
})
Expand Down Expand Up @@ -2740,11 +2740,43 @@ impl DataStore {
Ok(())
}

pub async fn switch_port_get_active_configuration(
&self,
opctx: &OpContext,
rack_id: Uuid,
switch_location: SwitchLocation,
port_name: Name,
) -> LookupResult<Option<SwitchPortSettings>> {
use db::schema::switch_port;
use db::schema::switch_port_settings;

let conn = self.pool_connection_authorized(opctx).await?;

let active_configuration = switch_port::table
.inner_join(
switch_port_settings::table.on(switch_port_settings::id
.nullable()
.eq(switch_port::port_settings_id)),
)
.filter(switch_port::rack_id.eq(rack_id))
.filter(
switch_port::switch_location.eq(switch_location.to_string()),
)
.filter(switch_port::port_name.eq(port_name.to_string()))
.select(SwitchPortSettings::as_select())
.get_result_async::<SwitchPortSettings>(&*conn)
.await
.optional()
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))?;

Ok(active_configuration)
}

pub async fn switch_port_get_id(
&self,
opctx: &OpContext,
rack_id: Uuid,
switch_location: Name,
switch_location: SwitchLocation,
port_name: Name,
) -> LookupResult<Uuid> {
use db::schema::switch_port;
Expand Down Expand Up @@ -3263,10 +3295,12 @@ async fn do_switch_port_settings_delete(
.returning(SwitchPortLinkConfig::as_returning())
.get_results_async(conn)
.await?;

// delete lldp configs
use db::schema::lldp_link_config;
let lldp_link_ids: Vec<Uuid> =
links.iter().filter_map(|link| link.lldp_link_config_id).collect();

diesel::delete(lldp_link_config::dsl::lldp_link_config)
.filter(lldp_link_config::id.eq_any(lldp_link_ids))
.execute_async(conn)
Expand Down
10 changes: 10 additions & 0 deletions nexus/external-api/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ snapshot_view GET /v1/snapshots/{snapshot}

API operations found with tag "system/hardware"
OPERATION ID METHOD URL PATH
networking_switch_port_active_configuration_clear DELETE /v1/system/hardware/racks/{rack_id}/switch/{switch}/switch-port/{port}/configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird column alignment compared to rest of file, but ok.

networking_switch_port_active_configuration_set PUT /v1/system/hardware/racks/{rack_id}/switch/{switch}/switch-port/{port}/configuration
networking_switch_port_active_configuration_view GET /v1/system/hardware/racks/{rack_id}/switch/{switch}/switch-port/{port}/configuration
networking_switch_port_apply_settings POST /v1/system/hardware/switch-port/{port}/settings
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm looking at the diffs since my last review, and looking at this file as a whole, and looking in particular for consistency for the DELETE method (due to diff for line 195).

Are lines 50-51 similar to lines 135-136, in that a specific element is not specified at the end of the URL?

instance_ephemeral_ip_attach             POST     /v1/instances/{instance}/external-ips/ephemeral
instance_ephemeral_ip_detach             DELETE   /v1/instances/{instance}/external-ips/ephemeral

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There can only be one active configuration per switch port, so specifying which configuration to delete is unnecessary here.

networking_switch_port_clear_settings DELETE /v1/system/hardware/switch-port/{port}/settings
networking_switch_port_list GET /v1/system/hardware/switch-port
Expand Down Expand Up @@ -166,6 +169,13 @@ ip_pool_silo_update PUT /v1/system/ip-pools/{pool}/sil
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}

API operations found with tag "system/metrics"
OPERATION ID METHOD URL PATH
system_metric GET /v1/system/metrics/{metric_name}

API operations found with tag "system/networking"
OPERATION ID METHOD URL PATH
networking_address_lot_block_add POST /v1/system/networking/address-lot/{address_lot}/blocks/add
networking_address_lot_block_list GET /v1/system/networking/address-lot/{address_lot}/blocks
networking_address_lot_block_remove POST /v1/system/networking/address-lot/{address_lot}/blocks/remove
Expand Down
Loading