Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: add support for ISCSI storage for installation destination #5283

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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