Skip to content

Commit bf69cf6

Browse files
authored
[RSS] Change uplink_ip to uplink_cidr in rack network config (#3755)
This is necessary (but not sufficient) to address #3588 - tfport needs the netmask/prefix for each uplink, which means we need to collect it at RSS time. Most of this PR is various openapi plumbing changes. There are a couple spots that warrant a closer look (although they are small); I'll call them out in comments below.
1 parent f926a97 commit bf69cf6

File tree

20 files changed

+102
-48
lines changed

20 files changed

+102
-48
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ installinator-artifact-client = { path = "installinator-artifact-client" }
206206
installinator-common = { path = "installinator-common" }
207207
internal-dns = { path = "internal-dns" }
208208
ipcc-key-value = { path = "ipcc-key-value" }
209-
ipnetwork = "0.20"
209+
ipnetwork = { version = "0.20", features = ["schemars"] }
210210
itertools = "0.10.5"
211211
key-manager = { path = "key-manager" }
212212
lazy_static = "1.4.0"

bootstrap-agent-client/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ progenitor::generate_api!(
1818
slog::debug!(log, "client response"; "result" => ?result);
1919
}),
2020
derives = [schemars::JsonSchema],
21+
replace = {
22+
Ipv4Network = ipnetwork::Ipv4Network,
23+
}
2124
);
2225

2326
impl omicron_common::api::external::ClientError for types::Error {

common/src/api/internal/shared.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! Types shared between Nexus and Sled Agent.
66
77
use crate::api::external::{self, Name};
8+
use ipnetwork::Ipv4Network;
89
use schemars::JsonSchema;
910
use serde::{Deserialize, Serialize};
1011
use std::{
@@ -91,8 +92,9 @@ pub struct UplinkConfig {
9192
pub uplink_port_speed: PortSpeed,
9293
/// Forward Error Correction setting for the uplink port
9394
pub uplink_port_fec: PortFec,
94-
/// IP Address to apply to switchport (must be in infra_ip pool)
95-
pub uplink_ip: Ipv4Addr,
95+
/// IP Address and prefix (e.g., `192.168.0.1/16`) to apply to switchport
96+
/// (must be in infra_ip pool)
97+
pub uplink_cidr: Ipv4Network,
9698
/// VLAN id to use for uplink
9799
pub uplink_vid: Option<u16>,
98100
}

nexus-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MPL-2.0"
77
[dependencies]
88
chrono.workspace = true
99
futures.workspace = true
10+
ipnetwork.workspace = true
1011
omicron-common.workspace = true
1112
omicron-passwords.workspace = true
1213
progenitor.workspace = true

nexus-client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ progenitor::generate_api!(
2222
slog::debug!(log, "client response"; "result" => ?result);
2323
}),
2424
replace = {
25+
Ipv4Network = ipnetwork::Ipv4Network,
2526
MacAddr = omicron_common::api::external::MacAddr,
2627
Name = omicron_common::api::external::Name,
2728
NewPasswordHash = omicron_passwords::NewPasswordHash,

nexus/src/app/rack.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use omicron_common::api::external::DataPageParams;
3434
use omicron_common::api::external::Error;
3535
use omicron_common::api::external::IdentityMetadataCreateParams;
3636
use omicron_common::api::external::IpNet;
37+
use omicron_common::api::external::Ipv4Net;
3738
use omicron_common::api::external::ListResultVec;
3839
use omicron_common::api::external::LookupResult;
3940
use omicron_common::api::external::Name;
@@ -458,11 +459,8 @@ impl super::Nexus {
458459
addresses: HashMap::new(),
459460
};
460461

461-
let uplink_address = IpNet::from_str(&format!("{}/32", uplink_config.uplink_ip))
462-
.map_err(|e| Error::internal_error(&format!(
463-
"failed to parse value provided for `rack_network_config.uplink_ip` as `IpNet`: {e}"
464-
)))?;
465-
462+
let uplink_address =
463+
IpNet::V4(Ipv4Net(uplink_config.uplink_cidr));
466464
let address = Address {
467465
address_lot: NameOrId::Name(address_lot_name.clone()),
468466
address: uplink_address,

openapi/bootstrap-agent.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@
353353
}
354354
]
355355
},
356+
"Ipv4Network": {
357+
"type": "string",
358+
"pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(3[0-2]|[0-2]?[0-9])$"
359+
},
356360
"Ipv4Range": {
357361
"description": "A non-decreasing IPv4 address range, inclusive of both ends.\n\nThe first address must be less than or equal to the last address.",
358362
"type": "object",
@@ -782,10 +786,13 @@
782786
}
783787
]
784788
},
785-
"uplink_ip": {
786-
"description": "IP Address to apply to switchport (must be in infra_ip pool)",
787-
"type": "string",
788-
"format": "ipv4"
789+
"uplink_cidr": {
790+
"description": "IP Address and prefix (e.g., `192.168.0.1/16`) to apply to switchport (must be in infra_ip pool)",
791+
"allOf": [
792+
{
793+
"$ref": "#/components/schemas/Ipv4Network"
794+
}
795+
]
789796
},
790797
"uplink_port": {
791798
"description": "Switchport to use for external connectivity",
@@ -818,7 +825,7 @@
818825
"required": [
819826
"gateway_ip",
820827
"switch",
821-
"uplink_ip",
828+
"uplink_cidr",
822829
"uplink_port",
823830
"uplink_port_fec",
824831
"uplink_port_speed"

openapi/nexus-internal.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,10 @@
20402040
}
20412041
]
20422042
},
2043+
"Ipv4Network": {
2044+
"type": "string",
2045+
"pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(3[0-2]|[0-2]?[0-9])$"
2046+
},
20432047
"Ipv4Range": {
20442048
"description": "A non-decreasing IPv4 address range, inclusive of both ends.\n\nThe first address must be less than or equal to the last address.",
20452049
"type": "object",
@@ -3227,10 +3231,13 @@
32273231
}
32283232
]
32293233
},
3230-
"uplink_ip": {
3231-
"description": "IP Address to apply to switchport (must be in infra_ip pool)",
3232-
"type": "string",
3233-
"format": "ipv4"
3234+
"uplink_cidr": {
3235+
"description": "IP Address and prefix (e.g., `192.168.0.1/16`) to apply to switchport (must be in infra_ip pool)",
3236+
"allOf": [
3237+
{
3238+
"$ref": "#/components/schemas/Ipv4Network"
3239+
}
3240+
]
32343241
},
32353242
"uplink_port": {
32363243
"description": "Switchport to use for external connectivity",
@@ -3263,7 +3270,7 @@
32633270
"required": [
32643271
"gateway_ip",
32653272
"switch",
3266-
"uplink_ip",
3273+
"uplink_cidr",
32673274
"uplink_port",
32683275
"uplink_port_fec",
32693276
"uplink_port_speed"

openapi/wicketd.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,10 @@
11671167
}
11681168
]
11691169
},
1170+
"Ipv4Network": {
1171+
"type": "string",
1172+
"pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(3[0-2]|[0-2]?[0-9])$"
1173+
},
11701174
"Ipv4Range": {
11711175
"description": "A non-decreasing IPv4 address range, inclusive of both ends.\n\nThe first address must be less than or equal to the last address.",
11721176
"type": "object",
@@ -4213,10 +4217,13 @@
42134217
}
42144218
]
42154219
},
4216-
"uplink_ip": {
4217-
"description": "IP Address to apply to switchport (must be in infra_ip pool)",
4218-
"type": "string",
4219-
"format": "ipv4"
4220+
"uplink_cidr": {
4221+
"description": "IP Address and prefix (e.g., `192.168.0.1/16`) to apply to switchport (must be in infra_ip pool)",
4222+
"allOf": [
4223+
{
4224+
"$ref": "#/components/schemas/Ipv4Network"
4225+
}
4226+
]
42204227
},
42214228
"uplink_port": {
42224229
"description": "Switchport to use for external connectivity",
@@ -4249,7 +4256,7 @@
42494256
"required": [
42504257
"gateway_ip",
42514258
"switch",
4252-
"uplink_ip",
4259+
"uplink_cidr",
42534260
"uplink_port",
42544261
"uplink_port_fec",
42554262
"uplink_port_speed"

0 commit comments

Comments
 (0)