| 1 |
/* |
| 2 |
* Copyright (C) 2023 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
import React from "react"; |
| 8 |
import client from "../client"; |
| 9 |
|
| 10 |
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js"; |
| 11 |
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; |
| 12 |
|
| 13 |
import { NetworkIcon } from "../icons/gnome-icons.jsx"; |
| 14 |
import { |
| 15 |
new_page, new_card, PAGE_CATEGORY_NETWORK, |
| 16 |
StorageDescription, ChildrenTable, StorageCard |
| 17 |
} from "../pages.jsx"; |
| 18 |
|
| 19 |
import { make_drive_page } from "../drive/drive.jsx"; |
| 20 |
|
| 21 |
const _ = cockpit.gettext; |
| 22 |
|
| 23 |
async function disconnect(session, goto_page) { |
| 24 |
const loc = cockpit.location; |
| 25 |
await session.Logout({ 'node.startup': { t: 's', v: "manual" } }); |
| 26 |
loc.go(goto_page.location); |
| 27 |
} |
| 28 |
|
| 29 |
export function make_iscsi_session_page(parent, session) { |
| 30 |
const session_card = new_card({ |
| 31 |
title: _("iSCSI portal"), |
| 32 |
next: null, |
| 33 |
page_location: ["iscsi", session.data.target_name], |
| 34 |
page_name: session.data.target_name, |
| 35 |
page_icon: NetworkIcon, |
| 36 |
page_category: PAGE_CATEGORY_NETWORK, |
| 37 |
component: ISCSISessionCard, |
| 38 |
props: { session }, |
| 39 |
actions: [ |
| 40 |
{ |
| 41 |
title: _("Disconnect"), |
| 42 |
action: () => disconnect(session, parent), |
| 43 |
danger: true |
| 44 |
}, |
| 45 |
] |
| 46 |
}); |
| 47 |
|
| 48 |
const drives_card = new_card({ |
| 49 |
title: _("iSCSI drives"), |
| 50 |
next: session_card, |
| 51 |
component: ISCSIDrivesCard, |
| 52 |
props: { session }, |
| 53 |
}); |
| 54 |
|
| 55 |
const p = new_page(parent, drives_card); |
| 56 |
|
| 57 |
if (client.iscsi_sessions_drives[session.path]) |
| 58 |
client.iscsi_sessions_drives[session.path].forEach(d => make_drive_page(p, d)); |
| 59 |
} |
| 60 |
|
| 61 |
const ISCSIDrivesCard = ({ card, session }) => { |
| 62 |
return ( |
| 63 |
<StorageCard card={card}> |
| 64 |
<ChildrenTable |
| 65 |
emptyCaption={_("No drives found")} |
| 66 |
aria-label={_("iSCSI drives")} |
| 67 |
page={card.page} /> |
| 68 |
</StorageCard> |
| 69 |
); |
| 70 |
}; |
| 71 |
|
| 72 |
const ISCSISessionCard = ({ card, session }) => { |
| 73 |
return ( |
| 74 |
<StorageCard card={card}> |
| 75 |
<CardBody> |
| 76 |
<DescriptionList className="pf-m-horizontal-on-sm"> |
| 77 |
<StorageDescription title={_("Address")} value={session.data.address} /> |
| 78 |
<StorageDescription title={_("Target")} value={session.data.target_name} /> |
| 79 |
</DescriptionList> |
| 80 |
</CardBody> |
| 81 |
</StorageCard> |
| 82 |
); |
| 83 |
}; |