Line data Source code
1 : /*
2 : * Copyright (C) 2018 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 113 : import cockpit from "cockpit";
7 113 : import React from "react";
8 :
9 : import { StackItem } from "@patternfly/react-core/dist/esm/layouts/Stack/index.js";
10 : import { Alert, AlertActionLink } from "@patternfly/react-core/dist/esm/components/Alert/index.js";
11 :
12 : import { get_multipathd_service } from "./utils.js";
13 : import { dialog_open } from "./dialog.jsx";
14 :
15 113 : const _ = cockpit.gettext;
16 :
17 113 : export class MultipathAlert extends React.Component {
18 112 : constructor() {
19 112 : super();
20 112 : this.multipathd_service = get_multipathd_service();
21 110 : this.on_multipathd_changed = () => { this.setState({}) };
22 112 : }
23 :
24 112 : componentDidMount() {
25 112 : this.multipathd_service.addEventListener("changed", this.on_multipathd_changed);
26 112 : }
27 :
28 0 : componentWillUnmount() {
29 0 : this.multipathd_service.removeEventListener("changed", this.on_multipathd_changed);
30 0 : }
31 :
32 112 : render() {
33 112 : const { client } = this.props;
34 :
35 : // When in doubt, assume everything is alright
36 111 : const multipathd_running = !this.multipathd_service.state || this.multipathd_service.state === "running";
37 112 : const multipath_broken = client.broken_multipath_present === true;
38 :
39 1 : function activate(event) {
40 1 : if (!event || event.button !== 0)
41 1 : return;
42 1 : cockpit.spawn(["mpathconf", "--enable", "--with_multipathd", "y"],
43 1 : { superuser: "try" })
44 0 : .catch(function (error) {
45 0 : dialog_open({
46 0 : Title: _("Error"),
47 0 : Body: error.toString()
48 0 : });
49 0 : });
50 1 : }
51 :
52 18 : if (multipath_broken && !multipathd_running)
53 112 : return (
54 18 : <StackItem>
55 18 : <Alert isInline variant='danger'
56 18 : actionClose={<AlertActionLink variant='secondary' onClick={activate}>{_("Start multipath")}</AlertActionLink>}
57 18 : title={_("There are devices with multiple paths on the system, but the multipath service is not running.")}
58 18 : />
59 18 : </StackItem>
60 : );
61 112 : return null;
62 112 : }
63 113 : }
|