Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jcronenberg/agama
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1a072cb2f27db02b948d2c0a4390a5dbb6daadea
Choose a base ref
..
head repository: jcronenberg/agama
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 04cef322c5b33987c3d594a875582fe546e70c84
Choose a head ref
Showing with 45 additions and 45 deletions.
  1. +40 −40 rust/agama-dbus-server/src/network/model.rs
  2. +5 −5 rust/agama-dbus-server/src/network/nm/dbus.rs
80 changes: 40 additions & 40 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
@@ -472,46 +472,6 @@ pub enum ConnectionConfig {
Infiniband(InfinibandConfig),
}

#[derive(Default, Debug, PartialEq, Clone)]
pub struct InfinibandConfig {
pub p_key: Option<i32>,
pub parent: Option<String>,
pub transport_mode: InfinibandTransportMode,
}

#[derive(Default, Debug, PartialEq, Clone)]
pub enum InfinibandTransportMode {
#[default]
Datagram,
Connected,
}

#[derive(Debug, Error)]
#[error("Invalid infiniband transport-mode: {0}")]
pub struct InvalidInfinibandTransportMode(String);

impl FromStr for InfinibandTransportMode {
type Err = InvalidInfinibandTransportMode;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"datagram" => Ok(Self::Datagram),
"connected" => Ok(Self::Connected),
_ => Err(InvalidInfinibandTransportMode(s.to_string())),
}
}
}

impl fmt::Display for InfinibandTransportMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match &self {
InfinibandTransportMode::Datagram => "datagram",
InfinibandTransportMode::Connected => "connected",
};
write!(f, "{}", name)
}
}

#[derive(Default, Debug, PartialEq, Clone)]
pub enum PortConfig {
#[default]
@@ -1040,3 +1000,43 @@ pub struct BridgePortConfig {
pub priority: Option<u32>,
pub path_cost: Option<u32>,
}

#[derive(Default, Debug, PartialEq, Clone)]
pub struct InfinibandConfig {
pub p_key: Option<i32>,
pub parent: Option<String>,
pub transport_mode: InfinibandTransportMode,
}

#[derive(Default, Debug, PartialEq, Clone)]
pub enum InfinibandTransportMode {
#[default]
Datagram,
Connected,
}

#[derive(Debug, Error)]
#[error("Invalid infiniband transport-mode: {0}")]
pub struct InvalidInfinibandTransportMode(String);

impl FromStr for InfinibandTransportMode {
type Err = InvalidInfinibandTransportMode;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"datagram" => Ok(Self::Datagram),
"connected" => Ok(Self::Connected),
_ => Err(InvalidInfinibandTransportMode(s.to_string())),
}
}
}

impl fmt::Display for InfinibandTransportMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = match &self {
InfinibandTransportMode::Datagram => "datagram",
InfinibandTransportMode::Connected => "connected",
};
write!(f, "{}", name)
}
}
10 changes: 5 additions & 5 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
@@ -502,22 +502,22 @@ fn infiniband_config_from_dbus(conn: &OwnedNestedHash) -> Option<InfinibandConfi
return None;
};

let mut config = InfinibandConfig::default();
let mut infiniband_config = InfinibandConfig::default();

if let Some(p_key) = infiniband.get("p-key") {
config.p_key = Some(*p_key.downcast_ref::<i32>()?);
infiniband_config.p_key = Some(*p_key.downcast_ref::<i32>()?);
}

if let Some(parent) = infiniband.get("parent") {
config.parent = Some(parent.downcast_ref::<str>()?.to_string());
infiniband_config.parent = Some(parent.downcast_ref::<str>()?.to_string());
}

if let Some(transport_mode) = infiniband.get("transport-mode") {
config.transport_mode =
infiniband_config.transport_mode =
InfinibandTransportMode::from_str(transport_mode.downcast_ref::<str>()?).ok()?;
}

Some(config)
Some(infiniband_config)
}

/// Converts a MatchConfig struct into a HashMap that can be sent over D-Bus.