Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions rust/migrate-wicked/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use agama_dbus_server::network::model::{self, IpConfig, IpRoute, Ipv4Method, Ipv6Method};
use agama_dbus_server::network::model::{
self, IpConfig, IpRoute, Ipv4Method, Ipv6Method, MacAddress,
};
use cidr::IpInet;
use serde::{Deserialize, Serialize};
use serde_with::{
Expand All @@ -24,6 +26,8 @@ pub struct Interface {
pub ipv6_dhcp: Option<Ipv6Dhcp>,
#[serde(rename = "ipv6-auto", skip_serializing_if = "Option::is_none")]
pub ipv6_auto: Option<Ipv6Auto>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dummy: Option<Dummy>,
#[serde(rename = "@origin")]
pub origin: String,
}
Expand Down Expand Up @@ -110,6 +114,12 @@ pub struct Ipv6Auto {
pub update: Vec<String>,
}

#[skip_serializing_none]
#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Dummy {
pub address: Option<String>,
}

#[derive(Debug, PartialEq, SerializeDisplay, DeserializeFromStr, EnumString, Display)]
#[strum(serialize_all = "kebab_case")]
pub enum FailOverMac {
Expand Down Expand Up @@ -145,15 +155,27 @@ pub struct IpConfigResult {
impl Interface {
pub fn to_connection(&self) -> Result<ConnectionResult, anyhow::Error> {
let ip_config = self.to_ip_config()?;
let base = model::BaseConnection {
let mut base = model::BaseConnection {
id: self.name.clone(),
interface: self.name.clone(),
ip_config: ip_config.ip_config,
..Default::default()
};

if let Some(dummy) = &self.dummy {
if let Some(address) = &dummy.address {
base.mac_address = MacAddress::from_str(address)?;
}
}

let connection = if self.dummy.is_some() {
model::Connection::Dummy(model::DummyConnection { base })
} else {
model::Connection::Ethernet(model::EthernetConnection { base })
};

Ok(ConnectionResult {
connection: model::Connection::Ethernet(model::EthernetConnection { base }),
connection,
warnings: ip_config.warnings,
})
}
Expand Down Expand Up @@ -417,4 +439,21 @@ mod tests {
assert_eq!(static_connection.base().ip_config.method6, Ipv6Method::Auto);
assert_eq!(static_connection.base().ip_config.addresses.len(), 0);
}

#[test]
fn test_dummy_interface_to_connection() {
let dummy_interface = Interface {
dummy: Some(Dummy {
address: Some("12:34:56:78:9A:BC".to_string()),
}),
..Default::default()
};

let connection: model::Connection = dummy_interface.to_connection().unwrap().connection;
assert!(matches!(connection, model::Connection::Dummy(_)));
assert_eq!(
connection.base().mac_address.to_string(),
"12:34:56:78:9A:BC"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[connection]
id=dummy0
uuid=d5c90a99-bde4-4c92-884c-d8208d8fb6da
type=dummy
interface-name=dummy0

[ethernet]
cloned-mac-address=12:34:56:78:9A:BC

[dummy]

[match]

[ipv4]
address1=10.0.0.100/24
method=manual

[ipv6]
addr-gen-mode=default
address1=2001:db8:1::1/64
method=manual

[proxy]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[connection]
id=dummy1
uuid=b551cd5a-d139-4297-a79f-d7dd33a97879
type=dummy
interface-name=dummy1

[ethernet]

[dummy]

[match]

[ipv4]
address1=10.0.0.101/24
method=manual

[ipv6]
addr-gen-mode=default
address1=2001:db8:1::2/64
method=manual

[proxy]
56 changes: 56 additions & 0 deletions rust/migrate-wicked/tests/dummy/wicked_xml/dummy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-dummy0">
<name>dummy0</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<dummy>
<address>12:34:56:78:9A:BC</address>
</dummy>
<link/>
<ipv4>
<enabled>true</enabled>
</ipv4>
<ipv4:static>
<address>
<local>10.0.0.100/24</local>
</address>
</ipv4:static>
<ipv6>
<enabled>true</enabled>
<privacy>prefer-public</privacy>
<accept-redirects>false</accept-redirects>
</ipv6>
<ipv6:static>
<address>
<local>2001:db8:1::1/64</local>
</address>
</ipv6:static>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-dummy1">
<name>dummy1</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<dummy/>
<link/>
<ipv4>
<enabled>true</enabled>
</ipv4>
<ipv4:static>
<address>
<local>10.0.0.101/24</local>
</address>
</ipv4:static>
<ipv6>
<enabled>true</enabled>
<privacy>prefer-public</privacy>
<accept-redirects>false</accept-redirects>
</ipv6>
<ipv6:static>
<address>
<local>2001:db8:1::2/64</local>
</address>
</ipv6:static>
</interface>