-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage adapt #1169
Storage adapt #1169
Changes from 6 commits
79b11a5
ed67ffa
251d0e4
e37c4ca
f4d20be
67a015c
fff5460
bb46e3b
2164ac6
36fdb6d
ba3d250
36ac90d
ca23a36
b4d9ae5
5b23d77
785dae7
fedf5e9
a598fb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consider putting these structs (and others in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Information about system device created by composition to reflect different devices on system | ||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Device { | ||
pub device_info: DeviceInfo, | ||
pub block_device: Option<BlockDevice>, | ||
pub component: Option<Component>, | ||
pub drive: Option<Drive>, | ||
pub filesystem: Option<Filesystem>, | ||
pub lvm_lv: Option<LvmLv>, | ||
pub lvm_vg: Option<LvmVg>, | ||
pub md: Option<MD>, | ||
pub multipath: Option<Multipath>, | ||
pub partition: Option<Partition>, | ||
pub partition_table: Option<PartitionTable>, | ||
pub raid: Option<Raid>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct DeviceInfo { | ||
pub sid: u32, | ||
pub name: String, | ||
pub description: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct BlockDevice {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Component {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Drive {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Filesystem {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct LvmLv {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct LvmVg {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct MD {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Multipath {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Partition {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct PartitionTable {} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)] | ||
pub struct Raid {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod web; | ||
pub use web::{storage_service, storage_streams}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! This module implements the web API for the storage service. | ||
//! | ||
//! The module offers two public functions: | ||
//! | ||
//! * `storage_service` which returns the Axum service. | ||
//! * `storage_stream` which offers an stream that emits the storage events coming from D-Bus. | ||
|
||
use agama_lib::{error::ServiceError, storage::StorageClient}; | ||
use axum::{extract::State, routing::get, Json, Router}; | ||
|
||
use crate::{ | ||
error::Error, | ||
web::{ | ||
common::{issues_router, progress_router, service_status_router, EventStreams}, | ||
Event, | ||
}, | ||
}; | ||
|
||
pub async fn storage_streams(dbus: zbus::Connection) -> Result<EventStreams, Error> { | ||
let result: EventStreams = vec![]; // TODO: | ||
Ok(result) | ||
} | ||
|
||
#[derive(Clone)] | ||
struct StorageState<'a> { | ||
client: StorageClient<'a>, | ||
} | ||
|
||
/// Sets up and returns the axum service for the software module. | ||
pub async fn storage_service(dbus: zbus::Connection) -> Result<Router, ServiceError> { | ||
const DBUS_SERVICE: &str = "org.opensuse.Agama.Storage1"; | ||
const DBUS_PATH: &str = "/org/opensuse/Agama/Storage1"; | ||
|
||
let status_router = service_status_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?; | ||
let progress_router = progress_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?; | ||
let issues_router = issues_router(&dbus, DBUS_SERVICE, DBUS_PATH).await?; | ||
|
||
let client = StorageClient::new(dbus.clone()).await?; | ||
let state = StorageState { client }; | ||
let router = Router::new() | ||
.route("/devices/dirty", get(devices_dirty)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether it might be useful to have a more generic endpoint which could have more "status-like" attributes (apart from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, more generic will be probably that proposal settings. Currently for devices I am aware only about this dirty flag that signal that re probe is needed. ( and staging can be no longer valid ) |
||
.merge(status_router) | ||
.merge(progress_router) | ||
.nest("/issues", issues_router) | ||
.with_state(state); | ||
Ok(router) | ||
} | ||
|
||
async fn devices_dirty(State(state): State<StorageState<'_>>) -> Result<Json<bool>, Error> { | ||
Ok(Json(state.client.devices_dirty_bit().await?)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could implement
Default
or, if not possible, have some kind of constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking that in the end I will add to
Device
struct methodtry_from
that will construct itself from that Object Manager struct. and here will be justOk(object.into())