Skip to content

Commit

Permalink
fix database insert data
Browse files Browse the repository at this point in the history
  • Loading branch information
Nieuwejaar committed Jul 25, 2024
1 parent fbd959b commit f73e472
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 38 deletions.
22 changes: 12 additions & 10 deletions nexus/db-queries/src/db/datastore/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,19 +1047,21 @@ async fn do_switch_port_settings_create(
let mut link_config = Vec::with_capacity(params.links.len());

for (link_name, c) in &params.links {
/*
let lldp_config_id = match c.lldp.lldp_config {
Some(_) => todo!(), // TODO actual lldp support
None => None,
};
*/
let lldp_link_config =
LldpLinkConfig::new(true, None, None, None, None, None, None);
lldp_config.push(lldp_link_config.clone());
let lldp_link_config = LldpLinkConfig::new(
c.lldp.enabled,
c.lldp.link_name.clone(),
c.lldp.link_description.clone(),
c.lldp.chassis_id.clone(),
c.lldp.system_name.clone(),
c.lldp.system_description.clone(),
c.lldp.management_ip.map(|a| a.into()),
);
let lldp_config_id = lldp_link_config.id;
lldp_config.push(lldp_link_config);

link_config.push(SwitchPortLinkConfig::new(
psid,
lldp_link_config.id,
lldp_config_id,
link_name.clone(),
c.mtu,
c.fec.into(),
Expand Down
29 changes: 18 additions & 11 deletions nexus/src/app/background/tasks/sync_switch_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,22 +987,29 @@ impl BackgroundTask for SwitchPortSettingsManager {
.map(|l| l.fec)
.unwrap_or(SwitchLinkFec::None)
.into(),
uplink_port_speed: info
uplink_port_speed: info
.links
.get(0) //TODO https://github.com/oxidecomputer/omicron/issues/3062
.map(|l| l.speed)
.unwrap_or(SwitchLinkSpeed::Speed100G)
.into(),
lldp: Some(LldpPortConfig {
status: LldpAdminStatus::Enabled,
chassis_id: None,
port_id: None,
port_description: None,
system_name: None,
system_description: Some("description".to_string()),
management_addrs: None,
}),
};
lldp: info
.link_lldp
.get(0) //TODO https://github.com/oxidecomputer/omicron/issues/3062
.map(|c| LldpPortConfig {
status: match c.enabled {
true => LldpAdminStatus::Enabled,
false=> LldpAdminStatus::Disabled,
},
port_id: c.link_name.clone(),
port_description: c.link_description.clone(),
chassis_id: c.chassis_id.clone(),
system_name: c.system_name.clone(),
system_description: c.system_description.clone(),
management_addrs:c.management_ip.map(|a| vec![a.ip().into()]),
})
}
;

for peer in port_config.bgp_peers.iter_mut() {
peer.communities = match self
Expand Down
29 changes: 20 additions & 9 deletions nexus/src/app/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use omicron_common::api::external::Name;
use omicron_common::api::external::NameOrId;
use omicron_common::api::external::ResourceType;
use omicron_common::api::internal::shared::ExternalPortDiscovery;
use omicron_common::api::internal::shared::LldpAdminStatus;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use oxnet::IpNet;
Expand Down Expand Up @@ -608,20 +609,30 @@ impl super::Nexus {
.bgp_peers
.insert("phy0".to_string(), BgpPeerConfig { peers });

let link = LinkConfigCreate {
mtu: 1500, //TODO https://github.com/oxidecomputer/omicron/issues/2274
lldp: LldpLinkConfigCreate {
let lldp = match &uplink_config.lldp {
None => LldpLinkConfigCreate {
enabled: false,
link_name: None,
link_description: None,
chassis_id: None,
system_name: None,
system_description: None,
management_ip: None,
..Default::default()
},
Some(l) => LldpLinkConfigCreate {
enabled: l.status == LldpAdminStatus::Enabled,
link_name: l.port_id.clone(),
link_description: l.port_description.clone(),
chassis_id: l.chassis_id.clone(),
system_name: l.system_name.clone(),
system_description: l.system_description.clone(),
management_ip: match &l.management_addrs {
Some(a) if !a.is_empty() => Some(a[0]),
_ => None,
},
},
};
let link = LinkConfigCreate {
mtu: 1500, //TODO https://github.com/oxidecomputer/omicron/issues/2274
fec: uplink_config.uplink_port_fec.into(),
speed: uplink_config.uplink_port_speed.into(),
autoneg: uplink_config.autoneg,
lldp,
};

port_settings_params.links.insert("phy".to_string(), link);
Expand Down
4 changes: 2 additions & 2 deletions nexus/types/src/external_api/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ pub struct LinkConfigCreate {
}

/// The LLDP configuration associated with a port.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema)]
pub struct LldpLinkConfigCreate {
/// Whether or not LLDP is enabled.
pub enabled: bool,
Expand All @@ -1582,7 +1582,7 @@ pub struct LldpLinkConfigCreate {
pub system_description: Option<String>,

/// The LLDP management IP TLV.
pub management_ip: Option<oxnet::IpNet>,
pub management_ip: Option<IpAddr>,
}

/// A layer-3 switch interface configuration. When IPv6 is enabled, a link local
Expand Down
7 changes: 2 additions & 5 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -16252,11 +16252,8 @@
"management_ip": {
"nullable": true,
"description": "The LLDP management IP TLV.",
"allOf": [
{
"$ref": "#/components/schemas/IpNet"
}
]
"type": "string",
"format": "ip"
},
"system_description": {
"nullable": true,
Expand Down
3 changes: 2 additions & 1 deletion sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3778,6 +3778,7 @@ impl ServiceManager {
if let Some(lldp_config) = &port_config.lldp {
let group_name = format!("port_{}", port_config.port);
info!(self.inner.log, "setting up {group_name}");
usmfh.delpropgroup(&group_name)?;
lsmfh.addpropgroup(&group_name, "application")?;
apv(
&lsmfh,
Expand All @@ -3802,7 +3803,7 @@ impl ServiceManager {
apv(
&lsmfh,
&format!("{group_name}/port_description"),
&lldp_config.port_id,
&lldp_config.port_description,
)?;
apv(
&lsmfh,
Expand Down

0 comments on commit f73e472

Please sign in to comment.