Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Oct 24, 2024
1 parent 2b421e4 commit 8431b05
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
13 changes: 13 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Storage1.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,25 @@
<interface name="org.opensuse.Agama.Storage1">
<method name="Probe">
</method>
<method name="SetConfig">
<arg name="serialized_config" direction="in" type="s"/>
<arg name="result" direction="out" type="u"/>
</method>
<method name="GetConfig">
<arg name="serialized_config" direction="out" type="s"/>
</method>
<method name="GetSolvedConfig">
<arg name="serialized_config" direction="out" type="s"/>
</method>
<method name="Install">
</method>
<method name="Finish">
</method>
<property type="b" name="DeprecatedSystem" access="read"/>
</interface>
<interface name="org.opensuse.Agama.Storage1.Devices">
<property type="aa{sv}" name="Actions" access="read"/>
</interface>
<interface name="org.opensuse.Agama.Storage1.DASD.Manager">
<method name="Probe">
</method>
Expand Down
72 changes: 72 additions & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,78 @@
<interface name="org.opensuse.Agama.Storage1">
<method name="Probe">
</method>
<!--
Sets the storage config.
-->
<method name="SetConfig">
<!--
E.g.,
{
"storage": {
"drives": [
"search": "/dev/vda",
"partitions": [
"generate": "default"
]
]
}
}
-->
<arg name="serialized_config" direction="in" type="s"/>
<!--
Whether the proposal was correctly calculated:
0: success
1: failure
-->
<arg name="result" direction="out" type="u"/>
</method>
<!--
Gets the unsolved storage config.
-->
<method name="GetConfig">
<!--
E.g.,
{
"storage": {
"drives": [
"search": "/dev/vda",
"partitions": [
"generate": "default"
]
]
}
}
-->
<arg name="serialized_config" direction="out" type="s"/>
</method>
<!--
Gets the solved storage config.
-->
<method name="GetSolvedConfig">
<!--
E.g.,
{
"storage": {
"drives": [
"search": "/dev/vda",
"partitions": [
{
"filesystem": {
"path": "/home",
"type": "xfs"
},
"size": {
"min": "10 GiB",
"max": "10 GiB"
}
}
]
]
}
}
-->
<arg name="serialized_config" direction="out" type="s"/>
</method>
<method name="Install">
</method>
<method name="Finish">
Expand Down
7 changes: 7 additions & 0 deletions rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ impl<'a> StorageClient<'a> {
Ok(settings)
}

/// Get the storage solved config according to the JSON schema
pub async fn get_solved_config(&self) -> Result<StorageSettings, ServiceError> {
let serialized_settings = self.storage_proxy.get_solved_config().await?;
let settings = serde_json::from_str(serialized_settings.as_str()).unwrap();
Ok(settings)
}

pub async fn calculate(&self, settings: ProposalSettingsPatch) -> Result<u32, ServiceError> {
Ok(self.calculator_proxy.calculate(settings.into()).await?)
}
Expand Down
3 changes: 3 additions & 0 deletions rust/agama-lib/src/storage/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ trait Storage1 {
/// Get the current storage config according to the JSON schema
fn get_config(&self) -> zbus::Result<String>;

/// Get the current storage solved config according to the JSON schema
fn get_solved_config(&self) -> zbus::Result<String>;

/// DeprecatedSystem property
#[dbus_proxy(property)]
fn deprecated_system(&self) -> zbus::Result<bool>;
Expand Down
20 changes: 20 additions & 0 deletions rust/agama-server/src/storage/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub async fn storage_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
let state = StorageState { client };
let router = Router::new()
.route("/config", put(set_config).get(get_config))
.route("/solved_config", get(get_solved_config))
.route("/probe", post(probe))
.route("/devices/dirty", get(devices_dirty))
.route("/devices/system", get(system_devices))
Expand Down Expand Up @@ -155,6 +156,25 @@ async fn get_config(State(state): State<StorageState<'_>>) -> Result<Json<Storag
Ok(Json(settings))
}

/// Returns the solved storage configuration.
///
/// * `state` : service state.
#[utoipa::path(
get,
path = "/solved_config",
context_path = "/api/storage",
operation_id = "get_storage_solved_config",
responses(
(status = 200, description = "storage solved configuration", body = StorageSettings),
(status = 400, description = "The D-Bus service could not perform the action")
)
)]
async fn get_solved_config(State(state): State<StorageState<'_>>) -> Result<Json<StorageSettings>, Error> {
// StorageSettings is just a wrapper over serde_json::value::RawValue
let settings = state.client.get_solved_config().await.map_err(Error::Service)?;
Ok(Json(settings))
}

/// Sets the storage configuration.
///
/// * `state`: service state.
Expand Down

0 comments on commit 8431b05

Please sign in to comment.