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
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 @@ -355,6 +355,29 @@
"type": "object",
"additionalProperties": false,
"properties": {
"state": {
"title": "Network general settings",
"type": "object",
"properties": {
"connectivity": {
"title": "Whether the user is able to access the Internet",
"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-software = { path = "../agama-software" }
agama-storage = { path = "../agama-storage" }
thiserror = "2.0.12"
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,5 +27,6 @@ pub use service::Service;
pub mod message;

pub use agama_l10n as l10n;
pub use agama_network as network;
pub use agama_software as software;
pub use agama_storage as storage;
46 changes: 42 additions & 4 deletions rust/agama-manager/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use std::sync::Arc;

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

Expand Down Expand Up @@ -61,11 +62,14 @@ pub enum Error {
License(#[from] LicenseError),
#[error(transparent)]
Progress(#[from] progress::service::Error),
#[error(transparent)]
Network(#[from] network::NetworkSystemError),
}

pub struct Service {
l10n: Handler<l10n::service::Service>,
software: Handler<software::service::Service>,
l10n: Handler<l10n::Service>,
software: Handler<software::Service>,
network: NetworkSystemClient,
storage: Handler<storage::Service>,
issues: Handler<issue::Service>,
progress: Handler<progress::Service>,
Expand All @@ -82,6 +86,7 @@ pub struct Service {
impl Service {
pub fn new(
l10n: Handler<l10n::Service>,
network: NetworkSystemClient,
software: Handler<software::Service>,
storage: Handler<storage::Service>,
issues: Handler<issue::Service>,
Expand All @@ -91,6 +96,7 @@ impl Service {
) -> Self {
Self {
l10n,
network,
software,
storage,
issues,
Expand Down Expand Up @@ -230,9 +236,11 @@ impl MessageHandler<message::GetSystem> for Service {
let l10n = self.l10n.call(l10n::message::GetSystem).await?;
let manager = self.system.clone();
let storage = self.storage.call(storage::message::GetSystem).await?;
let network = self.network.get_system().await?;
Ok(SystemInfo {
l10n,
manager,
network,
storage,
})
}
Expand All @@ -247,10 +255,13 @@ impl MessageHandler<message::GetExtendedConfig> for Service {
let l10n = self.l10n.call(l10n::message::GetConfig).await?;
let software = self.software.call(software::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),
software: Some(software),
storage,
})
Expand Down Expand Up @@ -297,11 +308,29 @@ 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.update_issues();
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 @@ -310,6 +339,8 @@ 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);

self.set_product_from_config(&config);

if let Some(l10n) = &config.l10n {
Expand Down Expand Up @@ -341,6 +372,10 @@ impl MessageHandler<message::UpdateConfig> for Service {
}
}

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

self.config = config;
self.update_issues();
Ok(())
Expand All @@ -354,8 +389,11 @@ impl MessageHandler<message::GetProposal> for Service {
let l10n = self.l10n.call(l10n::message::GetProposal).await?;
let software = self.software.call(software::message::GetProposal).await?;
let storage = self.storage.call(storage::message::GetProposal).await?;
let network = self.network.get_proposal().await?;

Ok(Some(Proposal {
l10n,
network,
software,
storage,
}))
Expand Down
7 changes: 6 additions & 1 deletion 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, software, storage};
use crate::{l10n, network, service::Service, software, storage};
use agama_utils::{
actor::{self, Handler},
api::event,
Expand All @@ -34,6 +34,8 @@ pub enum Error {
#[error(transparent)]
Manager(#[from] crate::service::Error),
#[error(transparent)]
Network(#[from] network::start::Error),
#[error(transparent)]
Software(#[from] software::start::Error),
#[error(transparent)]
Storage(#[from] storage::start::Error),
Expand All @@ -54,11 +56,13 @@ pub async fn start(
let issues = issue::start(events.clone(), dbus.clone()).await?;
let progress = progress::start(events.clone()).await?;
let l10n = l10n::start(issues.clone(), events.clone()).await?;
let network = network::start().await?;
let software = software::start(issues.clone(), progress.clone(), events.clone()).await?;
let storage = storage::start(progress.clone(), issues.clone(), events.clone(), dbus).await?;

let mut service = Service::new(
l10n,
network,
software,
storage,
issues,
Expand All @@ -67,6 +71,7 @@ pub async fn start(
events.clone(),
);
service.setup().await?;

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 the internal state of the network configuration applying the changes to the system
UpdateConfig(Box<Config>, Responder<Result<(), NetworkStateError>>),
/// Gets the current network system configuration containing connections, devices, access_points and
/// also the general state
GetSystem(Responder<SystemInfo>),
/// 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
3 changes: 2 additions & 1 deletion rust/agama-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub mod adapter;
pub mod error;
pub mod model;
mod nm;
pub mod settings;
pub mod start;
pub use start::start;
mod system;
pub mod types;

Expand Down
Loading
Loading