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
27 changes: 12 additions & 15 deletions rust/agama-bootloader/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) [2024] SUSE LLC
// Copyright (c) [2025-2026] SUSE LLC
//
// All Rights Reserved.
//
Expand All @@ -20,24 +20,21 @@

//! Implements a client to access Agama's D-Bus API related to Bootloader management.

use std::collections::HashMap;

use agama_storage_client::message;
use crate::storage_client::{self, message};
use agama_utils::{actor::Handler, api::bootloader::Config};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Errors that can occur when using the Bootloader client.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// Error originating from the D-Bus communication.
#[error("D-Bus service error: {0}")]
#[error(transparent)]
DBus(#[from] zbus::Error),
/// Error parsing or generating JSON data.
#[error("Passed json data is not correct: {0}")]
#[error(transparent)]
InvalidJson(#[from] serde_json::Error),
#[error("Storage D-Bus server error: {0}")]
DBusClient(#[from] agama_storage_client::Error),
#[error(transparent)]
StorageClient(#[from] storage_client::Error),
}

/// Trait defining the interface for the Bootloader client.
Expand Down Expand Up @@ -72,14 +69,14 @@ pub type ClientResult<T> = Result<T, Error>;
/// Client to connect to Agama's D-Bus API for Bootloader management.
#[derive(Clone)]
pub struct Client {
storage_dbus: Handler<agama_storage_client::Service>,
storage_client: Handler<storage_client::Service>,
kernel_args: HashMap<String, String>,
}

impl Client {
pub async fn new(storage_dbus: Handler<agama_storage_client::Service>) -> ClientResult<Client> {
pub async fn new(storage_client: Handler<storage_client::Service>) -> ClientResult<Client> {
Ok(Self {
storage_dbus,
storage_client,
kernel_args: HashMap::new(),
})
}
Expand All @@ -89,7 +86,7 @@ impl Client {
impl BootloaderClient for Client {
async fn get_config(&self) -> ClientResult<Config> {
Ok(self
.storage_dbus
.storage_client
.call(message::bootloader::GetConfig)
.await?)
}
Expand All @@ -103,7 +100,7 @@ impl BootloaderClient for Client {
// ignore return value as currently it does not fail and who knows what future brings
// but it should not be part of result and instead transformed to Issue
let value = serde_json::to_value(&full_config)?;
self.storage_dbus
self.storage_client
.call(message::bootloader::SetConfig::new(value))
.await?;
Ok(())
Expand Down
4 changes: 3 additions & 1 deletion rust/agama-bootloader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) [2025] SUSE LLC
// Copyright (c) [2025-2026] SUSE LLC
//
// All Rights Reserved.
//
Expand Down Expand Up @@ -41,3 +41,5 @@ pub use service::{Service, Starter};
pub mod client;
pub mod message;
pub mod test_utils;

use agama_storage_client as storage_client;
24 changes: 11 additions & 13 deletions rust/agama-bootloader/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) [2025] SUSE LLC
// Copyright (c) [2025-2026] SUSE LLC
//
// All Rights Reserved.
//
Expand All @@ -18,25 +18,24 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use crate::{
client::{self, Client},
message, storage_client,
};
use agama_utils::{
actor::{self, Actor, Handler, MessageHandler},
api::bootloader::Config,
};
use async_trait::async_trait;

use crate::{
client::{self, Client},
message,
};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Actor(#[from] actor::Error),
#[error(transparent)]
Client(#[from] client::Error),
#[error("Storage D-Bus server error: {0}")]
DBusClient(#[from] agama_storage_client::Error),
#[error(transparent)]
StorageClient(#[from] storage_client::Error),
}

/// Builds and spawns the bootloader service.
Expand Down Expand Up @@ -70,11 +69,10 @@ impl Starter {
let client = match self.client {
Some(client) => client,
None => {
let storage_dbus =
agama_storage_client::service::Starter::new(self.connection.clone())
.start()
.await?;
Box::new(Client::new(storage_dbus).await?)
let storage_client = storage_client::service::Starter::new(self.connection.clone())
.start()
.await?;
Box::new(Client::new(storage_client).await?)
}
};
let service = Service { client };
Expand Down
22 changes: 10 additions & 12 deletions rust/agama-iscsi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

//! Implements a client to access Agama's D-Bus API related to iSCSI management.

use agama_storage_client::message;
use crate::storage_client::{self, message};
use agama_utils::actor::Handler;
use agama_utils::api::iscsi::Config;
use agama_utils::api::iscsi::DiscoverConfig;
Expand All @@ -33,8 +33,8 @@ pub enum Error {
DBus(#[from] zbus::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error("Storage D-Bus server error: {0}")]
DBusClient(#[from] agama_storage_client::Error),
#[error(transparent)]
StorageClient(#[from] storage_client::Error),
}

pub enum DiscoverResult {
Expand All @@ -52,22 +52,20 @@ pub trait ISCSIClient {

#[derive(Clone)]
pub struct Client {
storage_dbus: Handler<agama_storage_client::Service>,
storage_client: Handler<storage_client::Service>,
}

impl Client {
pub async fn new(
storage_dbus: Handler<agama_storage_client::Service>,
) -> Result<Client, Error> {
Ok(Self { storage_dbus })
pub async fn new(storage_client: Handler<storage_client::Service>) -> Result<Client, Error> {
Ok(Self { storage_client })
}
}

#[async_trait]
impl ISCSIClient for Client {
async fn discover(&self, config: DiscoverConfig) -> Result<DiscoverResult, Error> {
let result = self
.storage_dbus
.storage_client
.call(message::iscsi::Discover::new(config))
.await?;
match result {
Expand All @@ -77,15 +75,15 @@ impl ISCSIClient for Client {
}

async fn get_system(&self) -> Result<Option<Value>, Error> {
Ok(self.storage_dbus.call(message::iscsi::GetSystem).await?)
Ok(self.storage_client.call(message::iscsi::GetSystem).await?)
}

async fn get_config(&self) -> Result<Option<Config>, Error> {
Ok(self.storage_dbus.call(message::iscsi::GetConfig).await?)
Ok(self.storage_client.call(message::iscsi::GetConfig).await?)
}

async fn set_config(&self, config: Option<Config>) -> Result<(), Error> {
self.storage_dbus
self.storage_client
.call(message::iscsi::SetConfig::new(config))
.await?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions rust/agama-iscsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod test_utils;
mod monitor;

use agama_storage as storage;
use agama_storage_client as storage_client;

#[cfg(test)]
mod tests {
Expand Down
6 changes: 4 additions & 2 deletions rust/agama-iscsi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use crate::storage;
use agama_storage_client::proxies::{ISCSIProxy, ProgressChanged, ProgressFinished, SystemChanged};
use crate::{
storage,
storage_client::proxies::{ISCSIProxy, ProgressChanged, ProgressFinished, SystemChanged},
};
use agama_utils::{
actor::Handler,
api::{
Expand Down
15 changes: 7 additions & 8 deletions rust/agama-iscsi/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
client::{self, Client, DiscoverResult},
message,
monitor::{self, Monitor},
storage,
storage, storage_client,
};
use agama_utils::{
actor::{self, Actor, Handler, MessageHandler},
Expand All @@ -40,8 +40,8 @@ pub enum Error {
Client(#[from] client::Error),
#[error(transparent)]
Monitor(#[from] monitor::Error),
#[error("Storage D-Bus server error: {0}")]
DBusClient(#[from] agama_storage_client::Error),
#[error(transparent)]
StorageClient(#[from] storage_client::Error),
}

pub struct Starter {
Expand Down Expand Up @@ -77,11 +77,10 @@ impl Starter {
let client = match self.client {
Some(client) => client,
None => {
let storage_dbus =
agama_storage_client::service::Starter::new(self.connection.clone())
.start()
.await?;
Box::new(Client::new(storage_dbus).await?)
let storage_client = storage_client::service::Starter::new(self.connection.clone())
.start()
.await?;
Box::new(Client::new(storage_client).await?)
}
};
let service = Service { client };
Expand Down
1 change: 1 addition & 0 deletions rust/agama-manager/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl Starter {
storage.clone(),
self.events.clone(),
progress.clone(),
issues.clone(),
self.dbus.clone(),
)
.start()
Expand Down
1 change: 1 addition & 0 deletions rust/agama-manager/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub async fn start_service(events: event::Sender, dbus: zbus::Connection) -> Han
storage.clone(),
events.clone(),
progress.clone(),
issues.clone(),
dbus.clone(),
)
.await;
Expand Down
22 changes: 10 additions & 12 deletions rust/agama-s390/src/dasd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

//! Implements a client to access Agama's D-Bus API related to DASD management.

use agama_storage_client::message;
use crate::storage_client::{self, message};
use agama_utils::actor::Handler;
use agama_utils::api::RawConfig;
use async_trait::async_trait;
Expand All @@ -32,8 +32,8 @@ pub enum Error {
DBus(#[from] zbus::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error("Storage D-Bus server error: {0}")]
DBusClient(#[from] agama_storage_client::Error),
#[error(transparent)]
StorageClient(#[from] storage_client::Error),
}

#[async_trait]
Expand All @@ -46,33 +46,31 @@ pub trait DASDClient {

#[derive(Clone)]
pub struct Client {
storage_dbus: Handler<agama_storage_client::Service>,
storage_client: Handler<storage_client::Service>,
}

impl Client {
pub async fn new(
storage_dbus: Handler<agama_storage_client::Service>,
) -> Result<Client, Error> {
Ok(Self { storage_dbus })
pub fn new(storage_client: Handler<storage_client::Service>) -> Self {
Self { storage_client }
}
}

#[async_trait]
impl DASDClient for Client {
async fn probe(&self) -> Result<(), Error> {
Ok(self.storage_dbus.call(message::dasd::Probe).await?)
Ok(self.storage_client.call(message::dasd::Probe).await?)
}

async fn get_system(&self) -> Result<Option<Value>, Error> {
Ok(self.storage_dbus.call(message::dasd::GetSystem).await?)
Ok(self.storage_client.call(message::dasd::GetSystem).await?)
}

async fn get_config(&self) -> Result<Option<RawConfig>, Error> {
Ok(self.storage_dbus.call(message::dasd::GetConfig).await?)
Ok(self.storage_client.call(message::dasd::GetConfig).await?)
}

async fn set_config(&self, config: Option<RawConfig>) -> Result<(), Error> {
self.storage_dbus
self.storage_client
.call(message::dasd::SetConfig::new(config))
.await?;
Ok(())
Expand Down
Loading
Loading