Skip to content

Commit

Permalink
Bond schema and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 20, 2023
1 parent 9c2a4de commit b9e789f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
36 changes: 31 additions & 5 deletions rust/agama-dbus-server/src/network/dbus/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! This module contains the set of D-Bus interfaces that are exposed by [D-Bus network
//! service](crate::NetworkService).
use std::collections::HashMap;

use super::ObjectsRegistry;
use crate::network::{
action::Action,
Expand Down Expand Up @@ -318,23 +320,48 @@ impl Bond {
async fn update_controller_connection<'a>(
&self,
connection: MappedMutexGuard<'a, NetworkConnection, BondConnection>,
ports: Vec<String>,
settings: HashMap<String, BondSettings>,
) -> zbus::fdo::Result<()> {
let actions = self.actions.lock().await;
let connection = NetworkConnection::Bond(connection.clone());
actions
.send(Action::UpdateControllerConnection(
connection.clone(),
ports.clone(),
settings,
))
.await
.unwrap();
Ok(())
}
}

enum BondSettings {
Ports(Vec<String>),
Options(String),
}

#[dbus_interface(name = "org.opensuse.Agama1.Network.Connection.Bond")]
impl Bond {
/// List of bond ports.
#[dbus_interface(property)]
pub async fn options(&self) -> String {
let connection = self.get_bond().await;
let mut opts = vec![];
for (key, value) in &connection.bond.options {
opts.push(format!("{key}={value}"));
}

opts.join(" ")
}

#[dbus_interface(property)]
pub async fn set_options(&self, opts: String) -> zbus::fdo::Result<()> {
let connection = self.get_bond().await;

self.update_controller_connection(connection, HashMap::from(["options", opts.clone()]))
.await
}

/// List of bond ports.
#[dbus_interface(property)]
pub async fn ports(&self) -> Vec<String> {
Expand All @@ -350,7 +377,7 @@ impl Bond {
#[dbus_interface(property)]
pub async fn set_ports(&mut self, ports: Vec<String>) -> zbus::fdo::Result<()> {
let connection = self.get_bond().await;
self.update_controller_connection(connection, ports.clone())
self.update_controller_connection(connection, HashMap::from(["ports", ports.clone()]))
.await
}
}
Expand Down Expand Up @@ -536,7 +563,6 @@ impl Wireless {
connection.wireless.security = security
.try_into()
.map_err(|_| NetworkStateError::InvalidSecurityProtocol(security.to_string()))?;
self.update_connection(connection).await?;
Ok(())
self.update_connection(connection).await
}
}
8 changes: 8 additions & 0 deletions rust/agama-lib/share/examples/profile.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ local findBiggestDisk(disks) =
match: {
path: ["pci-0000:00:19.0"]
}
},
{
id: 'bond0',
bond: {
ports: ['eth0', 'eth1'],
options: "mode=active-backup primary=eth1"

}
}
]
}
Expand Down
18 changes: 18 additions & 0 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@
}
}
},
"bond": {
"type": "object",
"description": "Bonding configuration",
"additionalProperties": false,
"properties": {
"options": {
"type": "string"
},
"ports": {
"type": "array",
"items": {
"description": "A list of the ports to be bonded",
"type": "string",
"additionalProperties": false
}
}
}
},
"match": {
"type": "object",
"description": "Match settings",
Expand Down
27 changes: 25 additions & 2 deletions rust/agama-lib/src/network/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::proxies::{
ConnectionProxy, ConnectionsProxy, DeviceProxy, DevicesProxy, IPProxy, MatchProxy,
BondProxy, ConnectionProxy, ConnectionsProxy, DeviceProxy, DevicesProxy, IPProxy, MatchProxy,
WirelessProxy,
};
use super::settings::{MatchSettings, NetworkConnection, WirelessSettings};
use super::settings::{BondSettings, MatchSettings, NetworkConnection, WirelessSettings};
use super::types::{Device, DeviceType, SSID};
use crate::error::ServiceError;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -226,6 +226,10 @@ impl<'a> NetworkClient<'a> {

self.update_ip_settings(path, conn).await?;

if let Some(ref bond) = conn.bond {
self.update_bond_settings(path, bond).await?;
}

if let Some(ref wireless) = conn.wireless {
self.update_wireless_settings(path, wireless).await?;
}
Expand Down Expand Up @@ -276,6 +280,25 @@ impl<'a> NetworkClient<'a> {
Ok(())
}

/// Updates the bond settings for network connection.
///
/// * `path`: connection D-Bus path.
/// * `bond`: bond settings of the network connection.
async fn update_bond_settings(
&self,
path: &OwnedObjectPath,
bond: &BondSettings,
) -> Result<(), ServiceError> {
let proxy = BondProxy::builder(&self.connection)
.path(path)?
.build()
.await?;

let ports: Vec<_> = bond.ports.iter().map(String::as_ref).collect();
proxy.set_ports(ports.as_slice()).await?;
proxy.set_options(bond.options.to_string().as_str()).await?;
Ok(())
}
/// Updates the wireless settings for network connection.
///
/// * `path`: connection D-Bus path.
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/network/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ trait Bond {

/// ports property
#[dbus_proxy(property)]
fn options(&self) -> zbus::Result<Vec<String>>;
fn options(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn set_options(&self, value: &[&str]) -> zbus::Result<()>;
fn set_options(&self, value: &str) -> zbus::Result<()>;

/// ports property
#[dbus_proxy(property)]
Expand Down

0 comments on commit b9e789f

Please sign in to comment.