Skip to content

Commit

Permalink
Add space actions to D-Bus
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 6, 2024
1 parent f3aadda commit 185556c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
9 changes: 9 additions & 0 deletions service/lib/agama/dbus/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def initialize(backend, logger)

dbus_reader :space_policy, "s"

dbus_reader :space_actions, "aa{ss}"

dbus_reader :volumes, "aa{sv}"

dbus_reader :actions, "aa{sv}"
Expand Down Expand Up @@ -109,6 +111,13 @@ def space_policy
dbus_settings.fetch("SpacePolicy", "")
end

# Space actions
#
# @return [Array<Hash<String => String>]
def space_actions
dbus_settings.fetch("SpaceActions", [])
end

# Volumes used to calculate the storage proposal
#
# @return [Array<Hash>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def space_policy_conversion(target, value)
end

# @param target [Agama::Storage::ProposalSettings]
# @param value [Hash]
# @param value [Array<Hash<String => String>>]
def space_actions_conversion(target, value)
target.space.actions = value
target.space.actions = value.each_with_object({}) do |v, result|
result[v["device"]] = v["action"].to_sym
end
end

# @param target [Agama::Storage::ProposalSettings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def convert # rubocop:disable Metrics/AbcSize
"EncryptionMethod" => settings.encryption.method.id.to_s,
"EncryptionPBKDFunction" => settings.encryption.pbkd_function&.value || "",
"SpacePolicy" => settings.space.policy.to_s,
"SpaceActions" => settings.space.actions,
"SpaceActions" => space_actions_conversion(),
"Volumes" => settings.volumes.map { |v| VolumeConversion.to_dbus(v) }
}
end
Expand All @@ -53,6 +53,13 @@ def convert # rubocop:disable Metrics/AbcSize

# @return [Agama::Storage::ProposalSettings]
attr_reader :settings

# @return [Array<Hash<String => String>>]
def space_actions_conversion
settings.space.actions.each_with_object([]) do |(device, action), actions|
actions << { "device" => device, "action" => action.to_s }
end
end
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ def settings
config: config
).tap do |settings|
# FIXME: The conversion from Y2Storage cannot infer the space policy. Copying space
# settings from the original settings.
# policy from the original settings.
settings.space.policy = original_settings.space.policy
settings.space.actions = original_settings.space.actions
# FIXME: The conversion from Y2Storage cannot reliably infer the system VG devices in all
# cases. Copying system VG devices from the original settings.
settings.lvm.system_vg_devices = original_settings.lvm.system_vg_devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def encryption_conversion(target)

# @param target [Agama::Storage::ProposalSettings]
def space_settings_conversion(target)
# FIXME: No way to infer space settings from Y2Storage.
# NOTE: the space policy cannot be inferred from Y2Storage settings.
target.space.actions = settings.space_settings.actions
end

# @param target [Agama::Storage::ProposalSettings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def find_max_size_fallback(mount_path)

# All block devices affected by the space policy.
#
# This includes the partitions from the root device, the candidate devices and from the
# This includes the partitions from the boot device, the candidate devices and from the
# devices directly assigned to a volume as target device. If a device is not partitioned,
# then the device itself is included.
#
Expand Down
24 changes: 21 additions & 3 deletions web/src/client/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,15 @@ class ProposalManager {
* @property {string} encryptionMethod
* @property {boolean} lvm
* @property {string} spacePolicy
* @property {SpaceAction[]} spaceActions
* @property {string[]} systemVGDevices
* @property {Volume[]} volumes
* @property {StorageDevice[]} installationDevices
*
* @typedef {object} SpaceAction
* @property {string} device
* @property {string} action
*
* @typedef {object} Volume
* @property {string} mountPath
* @property {string} fsType
Expand Down Expand Up @@ -365,6 +370,7 @@ class ProposalManager {
bootDevice: proxy.BootDevice,
lvm: proxy.LVM,
spacePolicy: proxy.SpacePolicy,
spaceActions: proxy.SpaceActions,
systemVGDevices: proxy.SystemVGDevices,
encryptionPassword: proxy.EncryptionPassword,
encryptionMethod: proxy.EncryptionMethod,
Expand All @@ -388,7 +394,18 @@ class ProposalManager {
* @param {ProposalSettings} settings
* @returns {Promise<number>} 0 on success, 1 on failure
*/
async calculate({ bootDevice, encryptionPassword, encryptionMethod, lvm, spacePolicy, systemVGDevices, volumes }) {
async calculate(settings) {
const {
bootDevice,
encryptionPassword,
encryptionMethod,
lvm,
spacePolicy,
spaceActions,
systemVGDevices,
volumes
} = settings;

const dbusVolume = (volume) => {
return removeUndefinedCockpitProperties({
MountPath: { t: "s", v: volume.mountPath },
Expand All @@ -401,18 +418,19 @@ class ProposalManager {
});
};

const settings = removeUndefinedCockpitProperties({
const dbusSettings = removeUndefinedCockpitProperties({
BootDevice: { t: "s", v: bootDevice },
EncryptionPassword: { t: "s", v: encryptionPassword },
EncryptionMethod: { t: "s", v: encryptionMethod },
LVM: { t: "b", v: lvm },
SpacePolicy: { t: "s", v: spacePolicy },
SpaceActions: { t: "aa{ss}", v: spaceActions },
SystemVGDevices: { t: "as", v: systemVGDevices },
Volumes: { t: "aa{sv}", v: volumes?.map(dbusVolume) }
});

const proxy = await this.proxies.proposalCalculator;
return proxy.Calculate(settings);
return proxy.Calculate(dbusSettings);
}

/**
Expand Down

0 comments on commit 185556c

Please sign in to comment.