-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6750 Add support for post-install LLDP configuration #7132
base: main
Are you sure you want to change the base?
Changes from 1 commit
23d9e4c
7d5c18c
04eb485
3bb9008
2c953c1
836e130
2e27caf
27c40f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
use super::DataStore; | ||
use crate::context::OpContext; | ||
use crate::db; | ||
use crate::db::error::public_error_from_diesel; | ||
use crate::db::error::ErrorHandler; | ||
use crate::db::model::LldpLinkConfig; | ||
use async_bb8_diesel::AsyncRunQueryDsl; | ||
use chrono::Utc; | ||
use diesel::ExpressionMethods; | ||
use diesel::QueryDsl; | ||
use diesel::SelectableHelper; | ||
use ipnetwork::IpNetwork; | ||
use omicron_common::api::external; | ||
use omicron_common::api::external::Error; | ||
use omicron_common::api::external::LookupResult; | ||
use omicron_common::api::external::Name; | ||
use omicron_common::api::external::ResourceType; | ||
use omicron_common::api::external::UpdateResult; | ||
use uuid::Uuid; | ||
|
||
// The LLDP configuration has been defined as a leaf of the switch-port-settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this whole thing be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant it to be useful to somebody reading the code, rather than somebody using the API. |
||
// tree, and is identified in the database with a UUID stored in that tree. | ||
// Using the uuid as the target argument for the config operations would be | ||
// reasonable, and similar in spirit to the link configuration operations. | ||
// | ||
// On the other hand, the neighbors are discovered on a configured link, but the | ||
// data is otherwise completely independent of the configuration. Furthermore, | ||
// the questions answered by the neighbor information have to do with the | ||
// physical connections between the Oxide rack and the upstream, datacenter | ||
// switch. Accordingly, it seems more appropriate to use the physical | ||
// rack/switch/port triple to identify the port of interest for the neighbors | ||
// query. | ||
// | ||
// For consistency across the lldp operations, all use rack/switch/port rather | ||
// than the uuid. | ||
// XXX: Is this the right call? The other options being: uuid for all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it? Should we decide before merging this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is, which is why I implemented it this way. The comment was meant to solicit feedback from the reviewers with more API experience - i.e, you. I probably should have made that a github/review comment rather than a rust comment to make that clearer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarifying. I think it's fine to use rack_id / switch-port rather than the uuid. I do think it's a little odd that the port is often a path param and the rack is a query param. Was there some particular motivation for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. Having rack/switch/port in the path seems more natural to me, but this was the pattern Ry used in the original stake-in-the-ground API. I don't know if he had something specific in mind, or if it was the result of a quick decision that was never revisited. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest using both the rack id and port in the path, and there seems to be at least some precedent for that. |
||
// operations, or uuid for config and r/s/p for neighbors. | ||
Nieuwejaar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
impl DataStore { | ||
/// Look up the settings id for this port in the switch_port table by its | ||
/// rack/switch/port triple, and then use that id to look up the lldp | ||
/// config id in the switch_port_settings_link_config table. | ||
async fn lldp_config_id_get( | ||
&self, | ||
opctx: &OpContext, | ||
rack_id: Uuid, | ||
switch_location: Name, | ||
port_name: Name, | ||
) -> LookupResult<Uuid> { | ||
use db::schema::switch_port; | ||
use db::schema::switch_port::dsl as switch_port_dsl; | ||
use db::schema::switch_port_settings_link_config; | ||
use db::schema::switch_port_settings_link_config::dsl as config_dsl; | ||
|
||
let conn = self.pool_connection_authorized(opctx).await?; | ||
|
||
let port_settings_id: Uuid = switch_port_dsl::switch_port | ||
.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(switch_port::port_settings_id) | ||
.limit(1) | ||
.first_async::<Option<Uuid>>(&*conn) | ||
.await | ||
.map_err(|_| { | ||
Error::not_found_by_name(ResourceType::SwitchPort, &port_name) | ||
})? | ||
.ok_or(Error::invalid_value( | ||
"settings", | ||
"switch port not yet configured".to_string(), | ||
))?; | ||
|
||
let lldp_id: Uuid = config_dsl::switch_port_settings_link_config | ||
.filter( | ||
switch_port_settings_link_config::port_settings_id | ||
.eq(port_settings_id), | ||
) | ||
.select(switch_port_settings_link_config::lldp_link_config_id) | ||
.limit(1) | ||
.first_async::<Option<Uuid>>(&*conn) | ||
.await | ||
.map_err(|_| { | ||
Error::not_found_by_id( | ||
ResourceType::SwitchPortSettings, | ||
&port_settings_id, | ||
) | ||
})? | ||
.ok_or(Error::invalid_value( | ||
"settings", | ||
"lldp not configured for this port".to_string(), | ||
))?; | ||
Ok(lldp_id) | ||
} | ||
|
||
/// Fetch the current LLDP configuration settings for the link identified | ||
/// using the rack/switch/port triple. | ||
pub async fn lldp_config_get( | ||
&self, | ||
opctx: &OpContext, | ||
rack_id: Uuid, | ||
switch_location: Name, | ||
port_name: Name, | ||
) -> LookupResult<external::LldpLinkConfig> { | ||
use db::schema::lldp_link_config; | ||
use db::schema::lldp_link_config::dsl; | ||
|
||
let id = self | ||
.lldp_config_id_get(opctx, rack_id, switch_location, port_name) | ||
.await?; | ||
|
||
let conn = self.pool_connection_authorized(opctx).await?; | ||
dsl::lldp_link_config | ||
.filter(lldp_link_config::id.eq(id)) | ||
.select(LldpLinkConfig::as_select()) | ||
.limit(1) | ||
.first_async::<LldpLinkConfig>(&*conn) | ||
.await | ||
.map(|config| config.into()) | ||
.map_err(|e| { | ||
let msg = "failed to lookup lldp config by id"; | ||
error!(opctx.log, "{msg}"; "error" => ?e); | ||
|
||
match e { | ||
diesel::result::Error::NotFound => Error::not_found_by_id( | ||
ResourceType::LldpLinkConfig, | ||
&id, | ||
), | ||
_ => Error::internal_error(msg), | ||
} | ||
}) | ||
} | ||
|
||
/// Update the current LLDP configuration settings for the link identified | ||
/// using the rack/switch/port triple. n.b.: each link is given an empty | ||
/// configuration structure at link creation time, so there are no | ||
/// lldp config create/delete operations. | ||
pub async fn lldp_config_update( | ||
&self, | ||
opctx: &OpContext, | ||
rack_id: Uuid, | ||
switch_location: Name, | ||
port_name: Name, | ||
config: external::LldpLinkConfig, | ||
) -> UpdateResult<()> { | ||
use db::schema::lldp_link_config::dsl; | ||
|
||
let id = self | ||
.lldp_config_id_get(opctx, rack_id, switch_location, port_name) | ||
.await?; | ||
if id != config.id { | ||
return Err(external::Error::invalid_request(&format!( | ||
"id ({}) doesn't match provided config ({})", | ||
id, config.id | ||
))); | ||
} | ||
|
||
diesel::update(dsl::lldp_link_config) | ||
.filter(dsl::time_deleted.is_null()) | ||
.filter(dsl::id.eq(id)) | ||
.set(( | ||
dsl::time_modified.eq(Utc::now()), | ||
dsl::enabled.eq( config.enabled), | ||
dsl::link_name.eq( config.link_name.clone()), | ||
dsl::link_description.eq( config.link_description.clone()), | ||
dsl::chassis_id.eq( config.chassis_id.clone()), | ||
dsl::system_name.eq( config.system_name.clone()), | ||
dsl::system_description.eq( config.system_description.clone()), | ||
dsl::management_ip.eq( config.management_ip.map(|a| IpNetwork::from(a))))) | ||
.execute_async(&*self.pool_connection_authorized(opctx).await?) | ||
.await | ||
.map_err(|err| { | ||
error!(opctx.log, "lldp link config update failed"; "error" => ?err); | ||
public_error_from_diesel(err, ErrorHandler::Server) | ||
})?; | ||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,9 @@ networking_bgp_status GET /v1/system/networking/bgp-stat | |
networking_loopback_address_create POST /v1/system/networking/loopback-address | ||
networking_loopback_address_delete DELETE /v1/system/networking/loopback-address/{rack_id}/{switch_location}/{address}/{subnet_mask} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it does seem like including the rack-id in the path might make more sense based on this precedent. I'm not sure what @internet-diglett has in mind to wrangle the API, but I infer that's still in the works. |
||
networking_loopback_address_list GET /v1/system/networking/loopback-address | ||
networking_switch_port_lldp_config_update POST /v1/system/hardware/switch-port/{port}/lldp/config | ||
networking_switch_port_lldp_config_view GET /v1/system/hardware/switch-port/{port}/lldp/config | ||
networking_switch_port_lldp_neighbors GET /v1/system/hardware/switch-port/{port}/lldp/neighbors | ||
networking_switch_port_settings_create POST /v1/system/networking/switch-port-settings | ||
networking_switch_port_settings_delete DELETE /v1/system/networking/switch-port-settings | ||
networking_switch_port_settings_list GET /v1/system/networking/switch-port-settings | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyright and license headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a license header. I didn't look at every other file in that directory, but none of the ones I did look at had a copyright line. Should they all be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably; but out of scope here I suppose!