Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 20, 2023
1 parent b3f7212 commit 5bf55d4
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 3 deletions.
2 changes: 1 addition & 1 deletion service/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
agama (2.1.devel317)
agama (2.1.devel331)
cfa (~> 1.0.2)
cfa_grub2 (~> 2.0.0)
cheetah (~> 1.0.0)
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def initialize(backend, logger)
register_iscsi_callbacks
register_software_callbacks

add_s390_interfaces if Yast::Arch.s390
add_s390_interfaces #if Yast::Arch.s390
end

# List of issues, see {DBus::Interfaces::Issues}
Expand Down
147 changes: 147 additions & 0 deletions web/src/components/storage/ZFCPPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright (c) [2023] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* 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 General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/

import React, { useEffect, useReducer } from "react";
import { useNavigate } from "react-router-dom";
import { Button } from "@patternfly/react-core";
import { MainActions } from "~/components/layout";
import { Page } from "~/components/core";
import { useCancellablePromise } from "~/utils";
import { useInstallerClient } from "~/context/installer";

const reducer = (state, action) => {
const { type, payload } = action;

switch (type) {
case "START_LOADING": {
return { ...state, isLoading: true };
}

case "STOP_LOADING": {
return { ...state, isLoading: false };
}

case "SET_DEVICES": {
const { controllers, disks } = payload;
return { ...state, controllers, disks };
}

case "UPDATE_CONTROLLER": {
const { controller } = payload;
const index = state.controllers.findIndex(d => d.id === controller.id);
const controllers = [...state.controllers];
index !== -1 ? controllers[index] = controller : controllers.push(controller);

return { ...state, controllers };
}

case "ADD_DISK": {
const { disk } = payload;
if (state.disks.find(d => d.id === disk.id)) return state;

return { ...state, disks: [...state.disks, disk] };
}

case "UPDATE_DISK": {
const { disk } = payload;
const index = state.disks.findIndex(d => d.id === disk.id);
const disks = [...state.disks];
index !== -1 ? disks[index] = disk : disks.push(disk);

return { ...state, disks };
}

case "REMOVE_DISK": {
const { disk } = payload;

return { ...state, disks: state.disks.filter(d => d.id !== disk.id) };
}

default: {
return state;
}
}
};

const initialState = {
controllers: [],
disks: [],
isLoading: true
};

export default function ZFCPPage() {
const { storage: client } = useInstallerClient();
const navigate = useNavigate();
const { cancellablePromise } = useCancellablePromise();
const [state, dispatch] = useReducer(reducer, initialState);

useEffect(() => {
const loadDevices = async () => {
dispatch({ type: "START_LOADING" });
await cancellablePromise(client.zfcp.probe());
const controllers = await cancellablePromise(client.zfcp.getControllers());
const disks = await cancellablePromise(client.zfcp.getDisks());
dispatch({ type: "SET_DEVICES", payload: { controllers, disks } });
dispatch({ type: "STOP_LOADING" });
// console.log("add disk");
// await cancellablePromise(client.zfcp.activateDisk(controllers[1], "0x500507630703d3b3", "0x0000000000000000"));
// console.log("remove disk");
// await cancellablePromise(client.zfcp.deactivateDisk(controllers[1], "0x500507630703d3b3", "0x0000000000000000"));

console.log("disks");
await cancellablePromise(client.zfcp.getDisks());
};

loadDevices().catch(console.error);
}, [client.zfcp, cancellablePromise]);

console.log("state: ", state);

useEffect(() => {
const subscriptions = [];

const subscribe = async () => {
const action = (type, payload) => dispatch({ type, payload });

subscriptions.push(
await client.zfcp.onControllerChanged(c => action("UPDATE_CONTROLLER", { controller: c })),
await client.zfcp.onDiskAdded(d => action("ADD_DISK", { disk: d })),
await client.zfcp.onDiskChanged(d => action("UPDATE_DISK", { disk: d })),
await client.zfcp.onDiskRemoved(d => action("REMOVE_DISK", { disk: d }))
);
};

const unsubscribe = () => {
subscriptions.forEach(fn => fn());
};

subscribe();
return unsubscribe;
}, [client.zfcp]);

return (
<Page title="Storage ZFCP" icon="hard_drive">
<MainActions>
<Button isLarge variant="secondary" onClick={() => navigate("/storage")}>Back</Button>
</MainActions>
</Page>
);
}
1 change: 1 addition & 0 deletions web/src/components/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { default as ProposalVolumes } from "./ProposalVolumes";
export { default as DASDPage } from "./DASDPage";
export { default as DASDTable } from "./DASDTable";
export { default as DASDFormatProgress } from "./DASDFormatProgress";
export { default as ZFCPPage } from "./ZFCPPage";
export { default as ISCSIPage } from "./ISCSIPage";
export { default as DeviceSelector } from "./DeviceSelector";
export { default as VolumeForm } from "./VolumeForm";
3 changes: 2 additions & 1 deletion web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Main from "~/Main";
import DevServerWrapper from "~/DevServerWrapper";
import { Overview } from "~/components/overview";
import { ProductSelectionPage } from "~/components/software";
import { ProposalPage as StoragePage, DASDPage, ISCSIPage } from "~/components/storage";
import { ProposalPage as StoragePage, ISCSIPage, DASDPage, ZFCPPage } from "~/components/storage";
import { UsersPage } from "~/components/users";
import { L10nPage } from "~/components/l10n";
import { NetworkPage } from "~/components/network";
Expand Down Expand Up @@ -85,6 +85,7 @@ root.render(
<Route path="/storage" element={<StoragePage />} />
<Route path="/storage/iscsi" element={<ISCSIPage />} />
<Route path="/storage/dasd" element={<DASDPage />} />
<Route path="/storage/zfcp" element={<ZFCPPage />} />
<Route path="/network" element={<NetworkPage />} />
<Route path="/users" element={<UsersPage />} />
<Route path="/issues" element={<IssuesPage />} />
Expand Down

0 comments on commit 5bf55d4

Please sign in to comment.