Skip to content

Commit

Permalink
Merge pull request #656 from openSUSE/plane
Browse files Browse the repository at this point in the history
New storage proposal settings
  • Loading branch information
joseivanlopez authored Aug 29, 2023
2 parents 96d4423 + 2205da8 commit bd46949
Show file tree
Hide file tree
Showing 85 changed files with 5,755 additions and 1,969 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/weblate-merge-po.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Validate the PO files
working-directory: ./agama
run: msgfmt --check-format -o /dev/null web/po/*.po
run: ls web/po/*.po | xargs -n1 msgfmt --check-format -o /dev/null

# any changes besides the timestamps in the PO files?
- name: Check changes
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ if ENV["YUPDATE_FORCE"] == "1" || File.exist?("/.packages.initrd") || live_iso?
sh "cp share/dbus.conf /usr/share/dbus-1/agama.conf"

# update the systemd service file
source_file = "share/systemd.service"
source_file = "share/agama.service"
target_file = "/usr/lib/systemd/system/agama.service"

unless FileUtils.identical?(source_file, target_file)
Expand Down
40 changes: 40 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Storage1.Proposal.bus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Storage1/Proposal">
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="value" direction="out" type="v"/>
</method>
<method name="Set">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="val" direction="in" type="v"/>
</method>
<method name="GetAll">
<arg name="interface_name" direction="in" type="s"/>
<arg name="value" direction="out" type="a{sv}"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
<interface name="org.opensuse.Agama.Storage1.Proposal">
<property type="s" name="BootDevice" access="read"/>
<property type="b" name="LVM" access="read"/>
<property type="aas" name="SystemVGDevices" access="read"/>
<property type="s" name="EncryptionPassword" access="read"/>
<property type="s" name="EncryptionMethod" access="read"/>
<property type="s" name="EncryptionPBKDFunction" access="read"/>
<property type="s" name="SpacePolicy" access="read"/>
<property type="aa{sv}" name="Volumes" access="read"/>
<property type="aa{sv}" name="Actions" access="read"/>
</interface>
</node>
6 changes: 5 additions & 1 deletion doc/dbus/bus/org.opensuse.Agama.Storage1.bus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@
<property type="b" name="IBFT" access="read"/>
</interface>
<interface name="org.opensuse.Agama.Storage1.Proposal.Calculator">
<method name="DefaultVolume">
<arg name="mount_path" direction="in" type="s"/>
<arg name="volume" direction="out" type="a{sv}"/>
</method>
<method name="Calculate">
<arg name="settings" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="u"/>
</method>
<property type="ao" name="AvailableDevices" access="read"/>
<property type="aa{sv}" name="VolumeTemplates" access="read"/>
<property type="as" name="ProductMountPoints" access="read"/>
<property type="o" name="Result" access="read"/>
</interface>
<interface name="org.opensuse.Agama.Storage1.ZFCP.Manager">
Expand Down
67 changes: 67 additions & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.Proposal.Calculator.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1">
<node name="zfcp_controllers" />
<node name="zfcp_disks" />
<!--
Interface for calculating a new storage proposal.
-->
<interface name="org.opensuse.Agama.Storage1.Proposal.Calculator">
<!--
Gets the default values for a volume with the given mount path.
-->
<method name="DefaultVolume">
<!--
E.g., /home
-->
<arg name="mount_path" direction="in" type="s"/>
<!--
MountPath s
MountOptions as
TargetDevice s
TargetVG s
FsType s
MinSize t (bytes)
MaxSize t (bytes. Optional, max size is considered as unlimited if omitted)
AutoSize b
Snapshots b
Outline a{sv}
Required b
FsTypes as
SupportAutoSize b
SnapshotsConfigurable b
SnapshotsAffectSizes b
SizeRelevantVolumes as
-->
<arg name="volume" direction="out" type="a{sv}"/>
</method>
<!--
Calculates a new proposal.
-->
<method name="Calculate">
<!--
BootDevice s
LVM b
SystemVGDevices as
EncryptionPassword s
EncryptionMethod s
EncryptionPBKDFunction s
SpacePolicy s
SpaceActions a{ss}
Volumes aa{sv}
List of volumes to create. The values for each volume are the same as the values returned
by DefaultVolume method. The Outline (if given) would be ignored.
-->
<arg name="settings" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="u"/>
</method>
<property type="ao" name="AvailableDevices" access="read"/>
<!--
Relevant mount points for the selected product. Normally, the product defines some specific
values for these mount points (e.g., min and max sizes, file system type, etc).
-->
<property type="as" name="ProductMountPoints" access="read"/>
<property type="o" name="Result" access="read"/>
</interface>

</node>
44 changes: 44 additions & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.Proposal.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Storage1/Proposal">
<!--
Interfaces with the properties of the calculated proposal.
-->
<interface name="org.opensuse.Agama.Storage1.Proposal">
<property type="s" name="BootDevice" access="read"/>
<property type="b" name="LVM" access="read"/>
<property type="aas" name="SystemVGDevices" access="read"/>
<property type="s" name="EncryptionPassword" access="read"/>
<property type="s" name="EncryptionMethod" access="read"/>
<property type="s" name="EncryptionPBKDFunction" access="read"/>
<property type="s" name="SpacePolicy" access="read"/>
<!--
List of volumes used for calculating the proposal.
Each volume has the following properties:
MountPath s
MountOptions as
TargetDevice s
TargetVG s
FsType s
MinSize t (bytes)
MaxSize t (bytes. Optional, max size is considered as unlimited if omitted)
AutoSize b
Snapshots b
Outline a{sv}
Required b
FsTypes as
SupportAutoSize b
SnapshotsConfigurable b
SnapshotsAffectSizes b
SizeRelevantVolumes as
-->
<property type="aa{sv}" name="Volumes" access="read"/>
<!--
Actions to perform in the system in order to create the volumes.
Each action has the following properties:
Text s
Subvol b
Delete b
-->
<property type="aa{sv}" name="Actions" access="read"/>
</interface>
</node>
4 changes: 2 additions & 2 deletions rust/agama-dbus-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use agama_dbus_server::{locale, network::NetworkService, questions};
use agama_dbus_server::{locale, network, questions};

use log::LevelFilter;
use std::future::pending;
Expand Down Expand Up @@ -28,7 +28,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
log::info!("Started questions interface");
let _conn = locale::start_service(ADDRESS).await?;
log::info!("Started locale interface");
NetworkService::start(ADDRESS).await?;
network::start_service(ADDRESS).await?;
log::info!("Started network interface");

// Do other things or go to wait forever
Expand Down
8 changes: 8 additions & 0 deletions rust/agama-dbus-server/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ pub use action::Action;
pub use adapter::Adapter;
pub use dbus::NetworkService;
pub use model::NetworkState;
pub use nm::NetworkManagerAdapter;
pub use system::NetworkSystem;

pub async fn start_service(address: &str) -> Result<(), Box<dyn std::error::Error>> {
let adapter = NetworkManagerAdapter::from_system()
.await
.expect("Could not connect to NetworkManager to read the configuration.");
NetworkService::start(address, adapter).await
}
10 changes: 9 additions & 1 deletion rust/agama-dbus-server/src/network/dbus/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::net::{AddrParseError, Ipv4Addr};
use zbus::{
dbus_interface,
zvariant::{ObjectPath, OwnedObjectPath},
SignalContext,
};

/// D-Bus interface for the network devices collection
Expand Down Expand Up @@ -126,7 +127,7 @@ impl Connections {
pub async fn add_connection(&mut self, id: String, ty: u8) -> zbus::fdo::Result<()> {
let actions = self.actions.lock().await;
actions
.send(Action::AddConnection(id, ty.try_into()?))
.send(Action::AddConnection(id.clone(), ty.try_into()?))
.await
.unwrap();
Ok(())
Expand Down Expand Up @@ -163,6 +164,13 @@ impl Connections {
actions.send(Action::Apply).await.unwrap();
Ok(())
}

#[dbus_interface(signal)]
pub async fn connection_added(
ctxt: &SignalContext<'_>,
id: &str,
path: &str,
) -> zbus::Result<()>;
}

/// D-Bus interface for a network connection
Expand Down
11 changes: 6 additions & 5 deletions rust/agama-dbus-server/src/network/dbus/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Network D-Bus service.
//!
//! This module defines a D-Bus service which exposes Agama's network configuration.
use crate::network::NetworkSystem;
use crate::network::{Adapter, NetworkSystem};
use agama_lib::connection_to;
use std::error::Error;

Expand All @@ -12,13 +12,14 @@ pub struct NetworkService;

impl NetworkService {
/// Starts listening and dispatching events on the D-Bus connection.
pub async fn start(address: &str) -> Result<(), Box<dyn Error>> {
pub async fn start<T: Adapter + std::marker::Send + 'static>(
address: &str,
adapter: T,
) -> Result<(), Box<dyn Error>> {
const SERVICE_NAME: &str = "org.opensuse.Agama.Network1";

let connection = connection_to(address).await?;
let mut network = NetworkSystem::from_network_manager(connection.clone())
.await
.expect("Could not read network state");
let mut network = NetworkSystem::new(connection.clone(), adapter);

async_std::task::spawn(async move {
network
Expand Down
25 changes: 22 additions & 3 deletions rust/agama-dbus-server/src/network/dbus/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ impl Tree {
/// Adds a connection to the D-Bus tree.
///
/// * `connection`: connection to add.
pub async fn add_connection(&self, conn: &mut Connection) -> Result<(), ServiceError> {
/// * `notify`: whether to notify the added connection
pub async fn add_connection(
&self,
conn: &mut Connection,
notify: bool,
) -> Result<(), ServiceError> {
let mut objects = self.objects.lock().await;

let orig_id = conn.id().to_owned();
let (id, path) = objects.register_connection(conn);
if id != conn.id() {
conn.set_id(&id)
Expand All @@ -106,6 +112,10 @@ impl Tree {
.await?;
}

if notify {
self.notify_connection_added(&orig_id, &path).await?;
}

Ok(())
}

Expand All @@ -115,7 +125,7 @@ impl Tree {
pub async fn remove_connection(&mut self, id: &str) -> Result<(), ServiceError> {
let mut objects = self.objects.lock().await;
let Some(path) = objects.connection_path(id) else {
return Ok(())
return Ok(());
};
self.remove_connection_on(path.as_str()).await?;
objects.deregister_connection(id).unwrap();
Expand All @@ -127,7 +137,7 @@ impl Tree {
/// * `connections`: list of connections.
async fn add_connections(&self, connections: &mut [Connection]) -> Result<(), ServiceError> {
for conn in connections.iter_mut() {
self.add_connection(conn).await?;
self.add_connection(conn, false).await?;
}

self.add_interface(
Expand Down Expand Up @@ -182,6 +192,15 @@ impl Tree {
let object_server = self.connection.object_server();
Ok(object_server.at(path, iface).await?)
}

/// Notify that a new connection has been added
async fn notify_connection_added(&self, id: &str, path: &str) -> Result<(), ServiceError> {
let object_server = self.connection.object_server();
let iface_ref = object_server
.interface::<_, interfaces::Connections>(CONNECTIONS_PATH)
.await?;
Ok(interfaces::Connections::connection_added(iface_ref.signal_context(), id, path).await?)
}
}

/// Objects paths for known devices and connections
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
};
use thiserror::Error;

#[derive(Default)]
#[derive(Default, Clone)]
pub struct NetworkState {
pub devices: Vec<Device>,
pub connections: Vec<Connection>,
Expand Down
Loading

0 comments on commit bd46949

Please sign in to comment.