Skip to content

Commit b340529

Browse files
committed
Move network to use the new actor service based model
1 parent 8cc79e7 commit b340529

File tree

10 files changed

+653
-529
lines changed

10 files changed

+653
-529
lines changed

rust/agama-manager/src/actions.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use std::{process::Command, sync::Arc};
2222

23-
use agama_network::NetworkSystemClient;
2423
use agama_utils::{
2524
actor::Handler,
2625
api::{files::scripts::ScriptsGroup, status::Stage, Config, FinishMethod, Scope},
@@ -32,8 +31,8 @@ use gettextrs::gettext;
3231
use tokio::sync::RwLock;
3332

3433
use crate::{
35-
bootloader, checks, files, hostname, iscsi, l10n, proxy, s390, security, service, software,
36-
storage, users,
34+
bootloader, checks, files, hostname, iscsi, l10n, network, proxy, s390, security, service,
35+
software, storage, users,
3736
};
3837

3938
/// Implements the installation process.
@@ -43,7 +42,7 @@ pub struct InstallAction {
4342
pub hostname: Handler<hostname::Service>,
4443
pub issues: Handler<issue::Service>,
4544
pub l10n: Handler<l10n::Service>,
46-
pub network: NetworkSystemClient,
45+
pub network: Handler<network::Service>,
4746
pub proxy: Handler<proxy::Service>,
4847
pub software: Handler<software::Service>,
4948
pub storage: Handler<storage::Service>,
@@ -114,7 +113,7 @@ impl InstallAction {
114113
self.l10n.call(l10n::message::Install).await?;
115114
self.software.call(software::message::Finish).await?;
116115
self.files.call(files::message::Finish).await?;
117-
self.network.install().await?;
116+
self.network.call(network::message::Install).await?;
118117
self.proxy.call(proxy::message::Finish).await?;
119118
self.hostname.call(hostname::message::Install).await?;
120119
self.users.call(users::message::Install).await?;
@@ -160,7 +159,7 @@ pub struct SetConfigAction {
160159
pub hostname: Handler<hostname::Service>,
161160
pub iscsi: Handler<iscsi::Service>,
162161
pub l10n: Handler<l10n::Service>,
163-
pub network: NetworkSystemClient,
162+
pub network: Handler<network::Service>,
164163
pub proxy: Handler<proxy::Service>,
165164
pub progress: Handler<progress::Service>,
166165
pub questions: Handler<question::Service>,
@@ -353,8 +352,11 @@ impl SetConfigAction {
353352
self.progress
354353
.call(progress::message::Next::new(Scope::Manager))
355354
.await?;
356-
self.network.update_config(network).await?;
357-
self.network.apply().await?;
355+
self.network
356+
.call(network::message::SetConfig {
357+
config: Box::new(network),
358+
})
359+
.await?;
358360

359361
Ok(())
360362
}

rust/agama-manager/src/service.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use agama_utils::{
3838
};
3939
use async_trait::async_trait;
4040
use merge::Merge;
41-
use network::NetworkSystemClient;
4241
use serde_json::Value;
4342
use std::{collections::HashMap, sync::Arc};
4443
use tokio::sync::{broadcast, RwLock};
@@ -107,7 +106,7 @@ pub struct Starter {
107106
hostname: Option<Handler<hostname::Service>>,
108107
iscsi: Option<Handler<iscsi::Service>>,
109108
l10n: Option<Handler<l10n::Service>>,
110-
network: Option<NetworkSystemClient>,
109+
network: Option<Handler<network::Service>>,
111110
proxy: Option<Handler<proxy::Service>>,
112111
security: Option<Handler<security::Service>>,
113112
software: Option<Handler<software::Service>>,
@@ -163,7 +162,7 @@ impl Starter {
163162
self
164163
}
165164

166-
pub fn with_network(mut self, network: NetworkSystemClient) -> Self {
165+
pub fn with_network(mut self, network: Handler<network::Service>) -> Self {
167166
self.network = Some(network);
168167
self
169168
}
@@ -421,7 +420,7 @@ pub struct Service {
421420
proxy: Handler<proxy::Service>,
422421
l10n: Handler<l10n::Service>,
423422
software: Handler<software::Service>,
424-
network: NetworkSystemClient,
423+
network: Handler<network::Service>,
425424
storage: Handler<storage::Service>,
426425
issues: Handler<issue::Service>,
427426
progress: Handler<progress::Service>,
@@ -465,8 +464,8 @@ impl Service {
465464

466465
// Configure the network according to defaults
467466
async fn network_default(&mut self) -> Result<(), Error> {
468-
self.network.propose_default().await?;
469-
self.network.apply().await?;
467+
self.network.call(network::message::ProposeDefault).await?;
468+
self.network.call(network::message::Apply).await?;
470469
Ok(())
471470
}
472471

@@ -630,7 +629,7 @@ impl MessageHandler<message::GetSystem> for Service {
630629
let manager = self.system.clone();
631630
let storage = self.storage.call(storage::message::GetSystem).await?;
632631
let iscsi = self.iscsi.call(iscsi::message::GetSystem).await?;
633-
let network = self.network.get_system().await?;
632+
let network = self.network.call(network::message::GetSystem).await?;
634633

635634
let s390 = if let Some(s390) = &self.s390 {
636635
Some(s390.call(s390::message::GetSystem).await?)
@@ -679,7 +678,7 @@ impl MessageHandler<message::GetExtendedConfig> for Service {
679678
let security = self.config.security.clone();
680679
let proxy = self.proxy.call(proxy::message::GetConfig).await?;
681680
let questions = self.questions.call(question::message::GetConfig).await?;
682-
let network = self.network.get_config().await?;
681+
let network = self.network.call(network::message::GetConfig).await?;
683682
let storage = self.storage.call(storage::message::GetConfig).await?;
684683
let users = self.users.call(users::message::GetConfig).await?;
685684

@@ -749,7 +748,7 @@ impl MessageHandler<message::GetProposal> for Service {
749748
let hostname = self.hostname.call(hostname::message::GetProposal).await?;
750749
let l10n = self.l10n.call(l10n::message::GetProposal).await?;
751750
let storage = self.storage.call(storage::message::GetProposal).await?;
752-
let network = self.network.get_proposal().await?;
751+
let network = self.network.call(network::message::GetProposal).await?;
753752
let users = self.users.call(users::message::GetProposal).await?;
754753

755754
// If the software service is busy, it will not answer.

rust/agama-manager/src/tasks/runner.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020

2121
use crate::{
2222
actions::{FinishAction, InstallAction, SetConfigAction},
23-
bootloader, files, hostname, iscsi, l10n, proxy, s390, security, service, software, storage,
23+
bootloader, files, hostname, iscsi, l10n, network, proxy, s390, security, service, software, storage,
2424
tasks::message,
2525
users,
2626
};
27-
use agama_network::NetworkSystemClient;
2827
use agama_utils::{
2928
actor::{Actor, Handler, MessageHandler},
3029
api::{FinishMethod, Scope},
@@ -45,7 +44,7 @@ pub struct TasksRunner {
4544
pub iscsi: Handler<iscsi::Service>,
4645
pub issues: Handler<issue::Service>,
4746
pub l10n: Handler<l10n::Service>,
48-
pub network: NetworkSystemClient,
47+
pub network: Handler<network::Service>,
4948
pub progress: Handler<progress::Service>,
5049
pub proxy: Handler<proxy::Service>,
5150
pub questions: Handler<question::Service>,

rust/agama-network/src/action.rs

Lines changed: 0 additions & 90 deletions
This file was deleted.

rust/agama-network/src/adapter.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
// To contact SUSE LLC about this file by physical or electronic mail, you may
1919
// find current contact information at www.suse.com.
2020

21-
use crate::{model::StateConfig, Action, NetworkState};
22-
use agama_utils::{api::event::Event, issue, progress};
21+
use crate::{model::StateConfig, NetworkState, Service};
22+
use agama_utils::{actor::Handler, api::event::Event, issue, progress};
2323
use async_trait::async_trait;
2424
use thiserror::Error;
25-
use tokio::sync::{broadcast, mpsc::UnboundedSender};
25+
use tokio::sync::broadcast;
2626

2727
#[derive(Error, Debug)]
2828
pub enum NetworkAdapterError {
@@ -68,9 +68,6 @@ impl From<NetworkAdapterError> for zbus::fdo::Error {
6868
pub trait Watcher {
6969
/// Listens for network changes and emit actions to update the state.
7070
///
71-
/// * `actions`: channel to emit the actions.
72-
async fn run(
73-
self: Box<Self>,
74-
actions: UnboundedSender<Action>,
75-
) -> Result<(), NetworkAdapterError>;
71+
/// * `handler`: handler to the service to emit the actions.
72+
async fn run(self: Box<Self>, handler: Handler<Service>) -> Result<(), NetworkAdapterError>;
7673
}

rust/agama-network/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@
2222
//!
2323
//! This library implements the network configuration service for Agama.
2424
25-
pub mod action;
2625
pub mod adapter;
2726
pub mod error;
27+
pub mod message;
2828
pub mod model;
2929
mod nm;
3030
mod service;
3131
pub mod types;
3232

33-
pub use action::Action;
3433
pub use adapter::{Adapter, NetworkAdapterError};
3534
pub use model::NetworkState;
3635
pub use nm::NetworkManagerAdapter;
37-
pub use service::{NetworkSystemClient, NetworkSystemError, Service, Starter};
36+
pub use service::{NetworkSystemError, Service, Starter};
3837

3938
pub mod test_utils;

0 commit comments

Comments
 (0)