Skip to content

Commit

Permalink
Migrate more uses of ipnetwork types to oxnet types (#5817)
Browse files Browse the repository at this point in the history
- moves uses of IpNetwork, Ipv4Network, and Ipv6Network to IpNet,
Ipv4Net, and Ipv6Net
- adds the `crates` imperative to relevant `generate_api!` invocations
to automatically use `oxnet` types
- cleans up `generate_api!` uses by removing unneeded derives and
sorting types
- removes the ipnetwork dep from Cargo.toml files where possible and
sorts deps
  • Loading branch information
ahl committed May 25, 2024
1 parent ec69e00 commit 8822168
Show file tree
Hide file tree
Showing 34 changed files with 179 additions and 499 deletions.
9 changes: 2 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/bootstrap-agent-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ workspace = true
[dependencies]
omicron-common.workspace = true
progenitor.workspace = true
ipnetwork.workspace = true
regress.workspace = true
reqwest = { workspace = true, features = [ "json", "rustls-tls", "stream" ] }
schemars.workspace = true
Expand All @@ -20,3 +19,4 @@ sled-hardware-types.workspace = true
slog.workspace = true
uuid.workspace = true
omicron-workspace-hack.workspace = true
oxnet.workspace = true
12 changes: 4 additions & 8 deletions clients/bootstrap-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ progenitor::generate_api!(
slog::debug!(log, "client response"; "result" => ?result);
}),
derives = [schemars::JsonSchema],
crates = {
"oxnet" = "0.1.0",
},
replace = {
ImportExportPolicy = omicron_common::api::external::ImportExportPolicy,
Ipv4Network = ipnetwork::Ipv4Network,
Ipv6Network = ipnetwork::Ipv6Network,
IpNetwork = ipnetwork::IpNetwork,
IpNet = omicron_common::api::external::IpNet,
Ipv4Net = omicron_common::api::external::Ipv4Net,
Ipv6Net = omicron_common::api::external::Ipv6Net,
IpAllowList = omicron_common::api::external::IpAllowList,
AllowedSourceIps = omicron_common::api::external::AllowedSourceIps,
ImportExportPolicy = omicron_common::api::external::ImportExportPolicy,
}
);

Expand Down
18 changes: 9 additions & 9 deletions clients/gateway-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ progenitor::generate_api!(
}),
derives = [schemars::JsonSchema],
patch = {
SpIdentifier = { derives = [Copy, PartialEq, Hash, Eq, Serialize, Deserialize] },
SpIgnition = { derives = [PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
SpIgnitionSystemType = { derives = [Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
SpState = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
RotState = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
RotImageDetails = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
RotSlot = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
ImageVersion = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
HostPhase2RecoveryImageId = { derives = [ PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize] },
HostPhase2RecoveryImageId = { derives = [PartialEq, Eq, PartialOrd, Ord] },
ImageVersion = { derives = [PartialEq, Eq, PartialOrd, Ord] },
RotImageDetails = { derives = [PartialEq, Eq, PartialOrd, Ord] },
RotSlot = { derives = [PartialEq, Eq, PartialOrd, Ord] },
RotState = { derives = [PartialEq, Eq, PartialOrd, Ord] },
SpIdentifier = { derives = [Copy, PartialEq, Hash, Eq] },
SpIgnition = { derives = [PartialEq, Eq, PartialOrd, Ord] },
SpIgnitionSystemType = { derives = [Copy, PartialEq, Eq, PartialOrd, Ord] },
SpState = { derives = [PartialEq, Eq, PartialOrd, Ord] },
},
);

Expand Down
8 changes: 4 additions & 4 deletions clients/installinator-artifact-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ progenitor::generate_api!(
}),
derives = [schemars::JsonSchema],
replace = {
Duration = std::time::Duration,
EventReportForInstallinatorSpec = installinator_common::EventReport,
StepEventForInstallinatorSpec = installinator_common::StepEvent,
M2Slot = installinator_common::M2Slot,
ProgressEventForGenericSpec = installinator_common::ProgressEvent<update_engine::NestedSpec>,
ProgressEventForInstallinatorSpec = installinator_common::ProgressEvent,
StepEventForGenericSpec = installinator_common::StepEvent<update_engine::NestedSpec>,
ProgressEventForGenericSpec = installinator_common::ProgressEvent<update_engine::NestedSpec>,
M2Slot = installinator_common::M2Slot,
Duration = std::time::Duration,
StepEventForInstallinatorSpec = installinator_common::StepEvent,
}
);

Expand Down
1 change: 0 additions & 1 deletion clients/nexus-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ workspace = true
[dependencies]
chrono.workspace = true
futures.workspace = true
ipnetwork.workspace = true
nexus-types.workspace = true
omicron-common.workspace = true
omicron-passwords.workspace = true
Expand Down
54 changes: 10 additions & 44 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ progenitor::generate_api!(
post_hook = (|log: &slog::Logger, result: &Result<_, _>| {
slog::debug!(log, "client response"; "result" => ?result);
}),
crates = {
"oxnet" = "0.1.0",
},
replace = {
// It's kind of unfortunate to pull in such a complex and unstable type
// as "blueprint" this way, but we have really useful functionality
// (e.g., diff'ing) that's implemented on our local type.
Blueprint = nexus_types::deployment::Blueprint,
Generation = omicron_common::api::external::Generation,
ImportExportPolicy = omicron_common::api::external::ImportExportPolicy,
Ipv4Network = ipnetwork::Ipv4Network,
Ipv6Network = ipnetwork::Ipv6Network,
IpNetwork = ipnetwork::IpNetwork,
MacAddr = omicron_common::api::external::MacAddr,
Name = omicron_common::api::external::Name,
NewPasswordHash = omicron_passwords::NewPasswordHash,
NetworkInterface = omicron_common::api::internal::shared::NetworkInterface,
NetworkInterfaceKind = omicron_common::api::internal::shared::NetworkInterfaceKind,
NewPasswordHash = omicron_passwords::NewPasswordHash,
TypedUuidForCollectionKind = omicron_uuid_kinds::CollectionUuid,
TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DownstairsKind>,
TypedUuidForSledKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::SledKind>,
Expand Down Expand Up @@ -419,50 +419,16 @@ impl TryFrom<types::ProducerEndpoint>
}
}

impl TryFrom<&oxnet::Ipv4Net> for types::Ipv4Net {
type Error = String;

fn try_from(net: &oxnet::Ipv4Net) -> Result<Self, Self::Error> {
types::Ipv4Net::try_from(net.to_string()).map_err(|e| e.to_string())
}
}

impl TryFrom<&oxnet::Ipv6Net> for types::Ipv6Net {
type Error = String;

fn try_from(net: &oxnet::Ipv6Net) -> Result<Self, Self::Error> {
types::Ipv6Net::try_from(net.to_string()).map_err(|e| e.to_string())
}
}

impl TryFrom<&oxnet::IpNet> for types::IpNet {
type Error = String;

fn try_from(net: &oxnet::IpNet) -> Result<Self, Self::Error> {
use oxnet::IpNet;
match net {
IpNet::V4(v4) => types::Ipv4Net::try_from(v4).map(types::IpNet::V4),
IpNet::V6(v6) => types::Ipv6Net::try_from(v6).map(types::IpNet::V6),
}
}
}

impl TryFrom<&omicron_common::api::external::AllowedSourceIps>
impl From<&omicron_common::api::external::AllowedSourceIps>
for types::AllowedSourceIps
{
type Error = String;

fn try_from(
ips: &omicron_common::api::external::AllowedSourceIps,
) -> Result<Self, Self::Error> {
fn from(ips: &omicron_common::api::external::AllowedSourceIps) -> Self {
use omicron_common::api::external::AllowedSourceIps;
match ips {
AllowedSourceIps::Any => Ok(types::AllowedSourceIps::Any),
AllowedSourceIps::List(list) => list
.iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()
.map(types::AllowedSourceIps::List),
AllowedSourceIps::Any => types::AllowedSourceIps::Any,
AllowedSourceIps::List(list) => {
types::AllowedSourceIps::List(list.iter().cloned().collect())
}
}
}
}
9 changes: 4 additions & 5 deletions clients/sled-agent-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ anyhow.workspace = true
async-trait.workspace = true
chrono.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.workspace = true
omicron-workspace-hack.workspace = true
oxnet.workspace = true
progenitor.workspace = true
ipnetwork.workspace = true
regress.workspace = true
reqwest = { workspace = true, features = [ "json", "rustls-tls", "stream" ] }
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true
slog.workspace = true
uuid.workspace = true
omicron-workspace-hack.workspace = true
omicron-uuid-kinds.workspace = true
oxnet.workspace = true
serde_json.workspace = true
Loading

0 comments on commit 8822168

Please sign in to comment.