Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 18, 2024
1 parent 5a07598 commit b21d752
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 16 deletions.
28 changes: 28 additions & 0 deletions rust/agama-lib/src/bootloader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

//! Implements support for handling the storage settings
pub mod client;
// pub mod http_client;
pub mod model;
pub mod proxies;
pub mod http_client;
pub mod store;
21 changes: 21 additions & 0 deletions rust/agama-lib/src/bootloader/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

pub mod bootloader;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use zbus::Connection;

use crate::{error::ServiceError, storage::{model::bootloader::Bootloader, proxies::BootloaderProxy}};
use crate::{error::ServiceError, bootloader::{model::bootloader::Bootloader, proxies::bootloader::BootloaderProxy}};

/// Client to connect to Agama's D-Bus API for Bootloader management.
#[derive(Clone)]
Expand Down
43 changes: 43 additions & 0 deletions rust/agama-lib/src/bootloader/http_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

//! Implements a client to access Agama's HTTP API related to Bootloader management.
use crate::base_http_client::BaseHTTPClient;
use crate::bootloader::model::bootloader::Bootloader;
use crate::ServiceError;

pub struct BootloaderHTTPClient {
client: BaseHTTPClient,
}

impl BootloaderHTTPClient {
pub fn new(base: BaseHTTPClient) -> Self {
Self { client: base }
}

pub async fn get_config(&self) -> Result<Bootloader, ServiceError> {
self.client.get("/bootloader/config").await
}

pub async fn set_config(&self, config: &Bootloader) -> Result<(), ServiceError> {
self.client.put_void("/bootloader/config", config).await
}
}
21 changes: 21 additions & 0 deletions rust/agama-lib/src/bootloader/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

pub mod bootloader;
21 changes: 21 additions & 0 deletions rust/agama-lib/src/bootloader/proxies.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

pub(crate) mod bootloader;
49 changes: 49 additions & 0 deletions rust/agama-lib/src/bootloader/store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

//! Implements the store for the storage settings.
use crate::base_http_client::BaseHTTPClient;
use crate::error::ServiceError;

use super::http_client::BootloaderHTTPClient;
use super::model::bootloader::Bootloader;

/// Loads and stores the storage settings from/to the HTTP service.
pub struct BootloaderStore {
bootloader_client: BootloaderHTTPClient,
}

impl BootloaderStore {
pub fn new(client: BaseHTTPClient) -> Result<Self, ServiceError> {
Ok(Self {
bootloader_client: BootloaderHTTPClient::new(client),
})
}

pub async fn load(&self) -> Result<Bootloader, ServiceError> {
self.bootloader_client.get_config().await
}

pub async fn store(&self, settings: &Bootloader) -> Result<(), ServiceError> {
self.bootloader_client.set_config(settings).await?;
Ok(())
}
}
3 changes: 3 additions & 0 deletions rust/agama-lib/src/install_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! Configuration settings handling
//!
//! This module implements the mechanisms to load and store the installation settings.
use crate::bootloader::model::bootloader::Bootloader;
use crate::{
localization::LocalizationSettings, network::NetworkSettings, product::ProductSettings,
scripts::ScriptsConfig, software::SoftwareSettings, users::UserSettings,
Expand All @@ -39,6 +40,8 @@ use std::path::Path;
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InstallSettings {
#[serde(default)]
pub bootloader: Option<Bootloader>,
#[serde(default, flatten)]
pub user: Option<UserSettings>,
#[serde(default)]
Expand Down
1 change: 1 addition & 0 deletions rust/agama-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
pub mod auth;
pub mod base_http_client;
pub mod bootloader;
pub mod error;
pub mod install_settings;
pub mod jobs;
Expand Down
1 change: 0 additions & 1 deletion rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use zbus::fdo::ObjectManagerProxy;
use zbus::names::{InterfaceName, OwnedInterfaceName};
use zbus::zvariant::{OwnedObjectPath, OwnedValue};
use zbus::Connection;
pub mod bootloader;
pub mod dasd;
pub mod iscsi;
pub mod zfcp;
Expand Down
1 change: 0 additions & 1 deletion rust/agama-lib/src/storage/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use crate::dbus::{get_optional_property, get_property};

pub mod dasd;
pub mod zfcp;
pub mod bootloader;

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
pub struct DeviceSid(u32);
Expand Down
3 changes: 0 additions & 3 deletions rust/agama-lib/src/storage/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
mod storage1;
pub use storage1::Storage1Proxy;

mod bootloader;
pub use bootloader::BootloaderProxy;

mod calculator;
pub use calculator::CalculatorProxy as ProposalCalculatorProxy;

Expand Down
7 changes: 7 additions & 0 deletions rust/agama-lib/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// TODO: quickly explain difference between FooSettings and FooStore, with an example

use crate::base_http_client::BaseHTTPClient;
use crate::bootloader::store::BootloaderStore;
use crate::error::ServiceError;
use crate::install_settings::InstallSettings;
use crate::manager::{InstallationPhase, ManagerHTTPClient};
Expand All @@ -38,6 +39,7 @@ use crate::{
///
/// This struct uses the default connection built by [connection function](super::connection).
pub struct Store {
bootloader: BootloaderStore,
users: UsersStore,
network: NetworkStore,
product: ProductStore,
Expand All @@ -52,6 +54,7 @@ pub struct Store {
impl Store {
pub async fn new(http_client: BaseHTTPClient) -> Result<Store, ServiceError> {
Ok(Self {
bootloader: BootloaderStore::new(http_client.clone())?,
localization: LocalizationStore::new(http_client.clone())?,
users: UsersStore::new(http_client.clone())?,
network: NetworkStore::new(http_client.clone()).await?,
Expand All @@ -67,6 +70,7 @@ impl Store {
/// Loads the installation settings from the HTTP interface.
pub async fn load(&self) -> Result<InstallSettings, ServiceError> {
let mut settings = InstallSettings {
bootloader: Some(self.bootloader.load().await?),
network: Some(self.network.load().await?),
software: Some(self.software.load().await?),
user: Some(self.users.load().await?),
Expand Down Expand Up @@ -121,6 +125,9 @@ impl Store {
if settings.storage.is_some() || settings.storage_autoyast.is_some() {
self.storage.store(&settings.into()).await?
}
if let Some(bootloader) = &settings.bootloader {
self.bootloader.store(bootloader).await?;
}

Ok(())
}
Expand Down
21 changes: 21 additions & 0 deletions rust/agama-server/src/bootloader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

pub mod web;
Loading

0 comments on commit b21d752

Please sign in to comment.