Skip to content

Commit

Permalink
webui: Add support using ISCSI disks for the installation
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed Oct 31, 2023
1 parent 9217b9d commit 721c79f
Show file tree
Hide file tree
Showing 12 changed files with 817 additions and 38 deletions.
10 changes: 8 additions & 2 deletions ui/webui/src/apis/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ export class StorageClient {
* @param {string} task DBus path to a task
* @param {string} onSuccess Callback to run after Succeeded signal is received
* @param {string} onFail Callback to run as an error handler
* @param {Boolean} getResult True if the result should be fetched, False otherwise
*
* @returns {Promise} Resolves a DBus path to a task
*/
export const runStorageTask = ({ task, onSuccess, onFail }) => {
export const runStorageTask = ({ task, onSuccess, onFail, getResult = false }) => {
// FIXME: This is a workaround for 'Succeeded' signal being emited twice
let succeededEmitted = false;
const taskProxy = new StorageClient().client.proxy(
Expand All @@ -78,7 +79,12 @@ export const runStorageTask = ({ task, onSuccess, onFail }) => {
return;
}
succeededEmitted = true;
onSuccess();

const promise = getResult ? taskProxy.GetResult() : Promise.resolve();

return promise
.then(res => onSuccess(res?.v))
.catch(onFail);
});
};
taskProxy.wait(() => {
Expand Down
103 changes: 103 additions & 0 deletions ui/webui/src/apis/storage_iscsi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2023 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with This program; If not, see <http://www.gnu.org/licenses/>.
*/
import cockpit from "cockpit";
import { StorageClient, runStorageTask } from "./storage.js";
import { objectToDBus } from "../helpers/utils.js";
import { _callClient, _getProperty, _setProperty } from "./helpers.js";

const INTERFACE_NAME = "org.fedoraproject.Anaconda.Modules.Storage.iSCSI";
const OBJECT_PATH = "/org/fedoraproject/Anaconda/Modules/Storage/iSCSI";

const callClient = (...args) => {
return _callClient(StorageClient, OBJECT_PATH, INTERFACE_NAME, ...args);
};
const getProperty = (...args) => {
return _getProperty(StorageClient, OBJECT_PATH, INTERFACE_NAME, ...args);
};
const setProperty = (...args) => {
return _setProperty(StorageClient, OBJECT_PATH, INTERFACE_NAME, ...args);
};

/**
* @returns {Promise} Module supported
*/
export const getIsSupported = () => {
return callClient("IsSupported", []);
};

/**
* @returns {Promise} Can set initiator
*/
export const getCanSetInitiator = () => {
return callClient("CanSetInitiator", []);
};

/**
* @returns {Promise} iSCSI initiator name
*/
export const getInitiator = () => {
return getProperty("Initiator");
};

/**
* @param {string} initiator iSCSI initiator name
*/
export const setInitiator = ({ initiator }) => {
return setProperty("Initiator", cockpit.variant("s", initiator));
};

/**
* @param {object} portal The portal information
* @param {object} credentials The iSCSI credentials
* @param {object} interfacesMode
*/
export const runDiscover = async ({ portal, credentials, interfacesMode = "default", onSuccess, onFail }) => {
const args = [
{ ...objectToDBus(portal) },
{ ...objectToDBus(credentials) },
interfacesMode,
];
try {
const discoverWithTask = () => callClient("DiscoverWithTask", args);
const task = await discoverWithTask();

return runStorageTask({ task, onFail, onSuccess, getResult: true });
} catch (error) {
onFail(error);
}
};

/**
* @param {object} portal The portal information
* @param {object} credentials The iSCSI credentials
* @param {object} node The iSCSI node
*/
export const runLogin = async ({ portal, credentials, node, onSuccess, onFail }) => {
const args = [
{ ...objectToDBus(portal) },
{ ...objectToDBus(credentials) },
{ ...objectToDBus(node) },
];
try {
const loginWithTask = () => callClient("LoginWithTask", args);
const task = await loginWithTask();

return runStorageTask({ task, onFail, onSuccess });
} catch (error) {
onFail(error);
}
};
Loading

0 comments on commit 721c79f

Please sign in to comment.