Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 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
4 changes: 4 additions & 0 deletions rust/Cargo.lock

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

23 changes: 23 additions & 0 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,29 @@
"type": "object",
"additionalProperties": false,
"properties": {
"generalState": {
"title": "Network general state settings",
Comment thread
teclator marked this conversation as resolved.
Outdated
"type": "object",
"properties": {
"connectivity": {
"title": "Determines whether the user is able to access the Internet",
Comment thread
teclator marked this conversation as resolved.
Outdated
"type": "boolean",
"readOnly": true
},
"copyNetwork": {
"title": "Whether the network configuration should be copied to the target system",
"type": "boolean"
},
"networkingEnabled": {
"title": "Whether the network should be enabled",
"type": "boolean"
},
"wirelessEnabled": {
"title": "Whether the wireless should be enabled",
"type": "boolean"
}
}
},
"connections": {
"title": "Network connections to be defined",
"type": "array",
Expand Down
4 changes: 2 additions & 2 deletions rust/agama-lib/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ mod client;
mod store;

pub use agama_network::{
error, model, settings, types, Action, Adapter, NetworkAdapterError, NetworkManagerAdapter,
error, model, types, Action, Adapter, NetworkAdapterError, NetworkManagerAdapter,
NetworkSystem, NetworkSystemClient, NetworkSystemError,
};
pub use agama_utils::api::network::*;
pub use client::{NetworkClient, NetworkClientError};
pub use settings::NetworkSettings;
pub use store::{NetworkStore, NetworkStoreError};
2 changes: 1 addition & 1 deletion rust/agama-lib/src/network/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use super::{settings::NetworkConnection, types::Device};
use crate::http::{BaseHTTPClient, BaseHTTPClientError};
use crate::network::{Device, NetworkConnection};
use crate::utils::url::encode;

#[derive(Debug, thiserror::Error)]
Expand Down
19 changes: 13 additions & 6 deletions rust/agama-lib/src/network/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use super::{settings::NetworkConnection, NetworkClientError};
use super::NetworkClientError;
use crate::{
http::BaseHTTPClient,
network::{NetworkClient, NetworkSettings},
};
use agama_network::types::NetworkConnectionsCollection;
use agama_utils::api::network::NetworkConnection;

#[derive(Debug, thiserror::Error)]
#[error("Error processing network settings: {0}")]
Expand All @@ -44,15 +46,20 @@ impl NetworkStore {

// TODO: read the settings from the service
pub async fn load(&self) -> NetworkStoreResult<NetworkSettings> {
let connections = self.network_client.connections().await?;
Ok(NetworkSettings { connections })
let connections = NetworkConnectionsCollection(self.network_client.connections().await?);

Ok(NetworkSettings {
connections,
..Default::default()
})
}

pub async fn store(&self, settings: &NetworkSettings) -> NetworkStoreResult<()> {
for id in ordered_connections(&settings.connections) {
let connections = &settings.connections.0;
for id in ordered_connections(connections) {
let id = id.as_str();
let fallback = default_connection(id);
let conn = find_connection(id, &settings.connections).unwrap_or(&fallback);
let conn = find_connection(id, connections).unwrap_or(&fallback);
self.network_client
.add_or_update_connection(conn.clone())
.await?;
Expand Down Expand Up @@ -129,7 +136,7 @@ fn default_connection(id: &str) -> NetworkConnection {
#[cfg(test)]
mod tests {
use super::ordered_connections;
use crate::network::settings::{BondSettings, BridgeSettings, NetworkConnection};
use crate::network::{BondSettings, BridgeSettings, NetworkConnection};

#[test]
fn test_ordered_connections() {
Expand Down
1 change: 1 addition & 0 deletions rust/agama-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
[dependencies]
agama-utils = { path = "../agama-utils" }
agama-l10n = { path = "../agama-l10n" }
agama-network = { path = "../agama-network" }
agama-storage = { path = "../agama-storage" }
thiserror = "2.0.12"
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread", "sync"] }
Expand Down
1 change: 1 addition & 0 deletions rust/agama-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pub use service::Service;
pub mod message;

pub use agama_l10n as l10n;
pub use agama_network as network;
pub use agama_storage as storage;
50 changes: 46 additions & 4 deletions rust/agama-manager/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use crate::{l10n, message, storage};
use crate::{l10n, message, network, storage};
use agama_utils::{
actor::{self, Actor, Handler, MessageHandler},
api::{
Expand All @@ -29,6 +29,7 @@ use agama_utils::{
};
use async_trait::async_trait;
use merge_struct::merge;
use network::{NetworkSystemClient, NetworkSystemError};
use serde_json::Value;
use tokio::sync::broadcast;

Expand All @@ -50,10 +51,13 @@ pub enum Error {
Questions(#[from] question::service::Error),
#[error(transparent)]
Progress(#[from] progress::service::Error),
#[error(transparent)]
NetworkSystemError(#[from] NetworkSystemError),
}

pub struct Service {
l10n: Handler<l10n::Service>,
network: NetworkSystemClient,
storage: Handler<storage::Service>,
issues: Handler<issue::Service>,
progress: Handler<progress::Service>,
Expand All @@ -66,6 +70,7 @@ pub struct Service {
impl Service {
pub fn new(
l10n: Handler<l10n::Service>,
network: NetworkSystemClient,
storage: Handler<storage::Service>,
issues: Handler<issue::Service>,
progress: Handler<progress::Service>,
Expand All @@ -74,6 +79,7 @@ impl Service {
) -> Self {
Self {
l10n,
network,
storage,
issues,
progress,
Expand Down Expand Up @@ -147,7 +153,12 @@ impl MessageHandler<message::GetSystem> for Service {
async fn handle(&mut self, _message: message::GetSystem) -> Result<SystemInfo, Error> {
let l10n = self.l10n.call(l10n::message::GetSystem).await?;
let storage = self.storage.call(storage::message::GetSystem).await?;
Ok(SystemInfo { l10n, storage })
let network = self.network.get_system_config().await?;
Ok(SystemInfo {
l10n,
network,
storage,
})
}
}

Expand All @@ -159,10 +170,13 @@ impl MessageHandler<message::GetExtendedConfig> for Service {
async fn handle(&mut self, _message: message::GetExtendedConfig) -> Result<Config, Error> {
let l10n = self.l10n.call(l10n::message::GetConfig).await?;
let questions = self.questions.call(question::message::GetConfig).await?;
let network = self.network.get_config().await?;
let storage = self.storage.call(storage::message::GetConfig).await?;

Ok(Config {
l10n: Some(l10n),
questions,
questions: questions,
network: Some(network),
storage,
})
}
Expand Down Expand Up @@ -196,11 +210,28 @@ impl MessageHandler<message::SetConfig> for Service {
.call(storage::message::SetConfig::new(config.storage.clone()))
.await?;

if let Some(network) = config.network.clone() {
self.network.update_config(network).await?;
self.network.apply().await?;
}

self.config = config;
Ok(())
}
}

fn merge_network(mut config: Config, update_config: Config) -> Config {
if let Some(network) = &update_config.network {
if let Some(connections) = &network.connections {
if let Some(ref mut config_network) = config.network {
config_network.connections = Some(connections.clone());
}
}
}

config
}

#[async_trait]
impl MessageHandler<message::UpdateConfig> for Service {
/// Patches the config.
Expand All @@ -209,6 +240,7 @@ impl MessageHandler<message::UpdateConfig> for Service {
/// config, then it keeps the values from the current config.
async fn handle(&mut self, message: message::UpdateConfig) -> Result<(), Error> {
let config = merge(&self.config, &message.config).map_err(|_| Error::MergeConfig)?;
let config = merge_network(config, message.config);

if let Some(l10n) = &config.l10n {
self.l10n
Expand All @@ -228,6 +260,10 @@ impl MessageHandler<message::UpdateConfig> for Service {
.await?;
}

if let Some(network) = &config.network {
self.network.update_config(network.clone()).await?;
}

self.config = config;
Ok(())
}
Expand All @@ -239,7 +275,13 @@ impl MessageHandler<message::GetProposal> for Service {
async fn handle(&mut self, _message: message::GetProposal) -> Result<Option<Proposal>, Error> {
let l10n = self.l10n.call(l10n::message::GetProposal).await?;
let storage = self.storage.call(storage::message::GetProposal).await?;
Ok(Some(Proposal { l10n, storage }))
let network = self.network.get_proposal().await?;

Ok(Some(Proposal {
l10n,
network,
storage,
}))
}
}

Expand Down
10 changes: 8 additions & 2 deletions rust/agama-manager/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use crate::{l10n, service::Service, storage};
use crate::{l10n, network, service::Service, storage};
use agama_utils::{
actor::{self, Handler},
api::event,
Expand All @@ -35,6 +35,8 @@ pub enum Error {
L10n(#[from] l10n::start::Error),
#[error(transparent)]
Storage(#[from] storage::start::Error),
#[error(transparent)]
NetworkSystem(#[from] network::NetworkSystemError),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NetworkSystem(#[from] network::NetworkSystemError),
Network(#[from] network::NetworkSystemError),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, why are you using NetworkSystemError? Just mentioning because you already have a agama_network::error:Error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to move it to agama_network::error::Error instead of NetworkSystemError or NetworkAdapterError but probably defined it but didn't moved it yet.

}

/// Starts the manager service.
Expand All @@ -51,8 +53,12 @@ pub async fn start(
let progress = progress::start(events.clone()).await?;
let l10n = l10n::start(issues.clone(), events.clone()).await?;
let storage = storage::start(progress.clone(), issues.clone(), events.clone(), dbus).await?;
let network_adapter = network::NetworkManagerAdapter::from_system()
.await
.expect("Could not connect to NetworkManager");
let network = network::NetworkSystem::new(network_adapter).start().await?;
Comment thread
teclator marked this conversation as resolved.
Outdated

let service = Service::new(l10n, storage, issues, progress, questions, events);
let service = Service::new(l10n, network, storage, issues, progress, questions, events);
let handler = actor::spawn(service);
Ok(handler)
}
Expand Down
16 changes: 13 additions & 3 deletions rust/agama-network/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use crate::model::{AccessPoint, Connection, Device};
use crate::types::{ConnectionState, DeviceType};
use crate::model::{Connection, GeneralState};
use crate::types::{AccessPoint, ConnectionState, Device, DeviceType, Proposal, SystemInfo};
use agama_utils::api::network::Config;
use tokio::sync::oneshot;
use uuid::Uuid;

use super::{error::NetworkStateError, model::GeneralState, NetworkAdapterError};
use super::{error::NetworkStateError, NetworkAdapterError};

pub type Responder<T> = oneshot::Sender<T>;
pub type ControllerConnection = (Connection, Vec<String>);
Expand All @@ -42,6 +43,15 @@ pub enum Action {
GetConnection(String, Responder<Option<Connection>>),
/// Gets a connection by its Uuid
GetConnectionByUuid(Uuid, Responder<Option<Connection>>),
/// Gets the internal state of the network configuration
GetConfig(Responder<Config>),
/// Gets the internal state of the network configuration proposal
GetProposal(Responder<Proposal>),
/// Updates th internal state of the network configuration
Comment thread
teclator marked this conversation as resolved.
Outdated
UpdateConfig(Box<Config>, Responder<Result<(), NetworkStateError>>),
/// Gets the current network configuration containing connections, devices, access_points and
/// also the general state
GetSystemConfig(Responder<SystemInfo>),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the config, but the system itself. The name could be misleading.

/// Gets a connection
GetConnections(Responder<Vec<Connection>>),
/// Gets a controller connection
Expand Down
10 changes: 10 additions & 0 deletions rust/agama-network/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
//! Error types.
use thiserror::Error;

use crate::NetworkSystemError;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
NetworkStateError(#[from] NetworkStateError),
#[error(transparent)]
NetworkSystemError(#[from] NetworkSystemError),
}

/// Errors that are related to the network configuration.
#[derive(Error, Debug)]
pub enum NetworkStateError {
Expand Down
1 change: 0 additions & 1 deletion rust/agama-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub mod adapter;
pub mod error;
pub mod model;
mod nm;
pub mod settings;
mod system;
pub mod types;

Expand Down
Loading
Loading