Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 7, 2024
1 parent fd4d7d2 commit 95d9a92
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 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 @@ -338,6 +343,13 @@ class ProposalManager {
const systemDevices = await this.system.getDevices();

const buildResult = (proxy) => {
const buildSpaceAction = dbusSpaceAction => {
return {
device: dbusSpaceAction.Device.v,
action: dbusSpaceAction.Action.v
};
};

const buildAction = dbusAction => {
return {
text: dbusAction.Text.v,
Expand Down Expand Up @@ -365,6 +377,7 @@ class ProposalManager {
bootDevice: proxy.BootDevice,
lvm: proxy.LVM,
spacePolicy: proxy.SpacePolicy,
spaceActions: proxy.SpaceActions.map(buildSpaceAction),
systemVGDevices: proxy.SystemVGDevices,
encryptionPassword: proxy.EncryptionPassword,
encryptionMethod: proxy.EncryptionMethod,
Expand All @@ -388,7 +401,31 @@ 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 dbusSpaceActions = () => {
const dbusSpaceAction = (spaceAction) => {
return {
Device: { t: "s", v: spaceAction.device },
Action: { t: "s", v: spaceAction.action }
};
};

if (spacePolicy !== "custom") return [];

return spaceActions?.map(dbusSpaceAction);
};

const dbusVolume = (volume) => {
return removeUndefinedCockpitProperties({
MountPath: { t: "s", v: volume.mountPath },
Expand All @@ -401,18 +438,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{sv}", v: dbusSpaceActions() },
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 95d9a92

Please sign in to comment.