Skip to content

Commit 1d0f9e3

Browse files
committed
nics: Improve dialogs with new framework components
- Use DialogRadioSelect, use it for "Type" and "Mode" - Change TypeAndSource to disable types without sources instead of disabling the sources selector. - When editing a interface, always include the current source in the choices, even if it doesn't actually exist. - When adding, re-create "default" network when none other exists to always have a path through the dialog.
1 parent e0f0483 commit 1d0f9e3

File tree

7 files changed

+237
-252
lines changed

7 files changed

+237
-252
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
# See https://wiki.libvirt.org/Networking.html#host-configuration-nat
6+
7+
f=/usr/share/libvirt/networks/default.xml
8+
if test -f "$f"; then
9+
virsh -c qemu:///system net-define "$f"
10+
else
11+
cat <<EOF | virsh -c qemu:///system net-define /dev/stdin
12+
<network>
13+
<name>default</name>
14+
<bridge name='virbr0'/>
15+
<forward/>
16+
<ip address='192.168.122.1' netmask='255.255.255.0'>
17+
<dhcp>
18+
<range start='192.168.122.2' end='192.168.122.254'/>
19+
</dhcp>
20+
</ip>
21+
</network>
22+
EOF
23+
fi
24+
25+
virsh -c qemu:///system net-autostart default
26+
virsh -c qemu:///system net-start default
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const content: string;
2+
export default content;

src/components/vm/nics/nicAdd.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { useDialogs } from 'dialogs';
2323
import type { VM } from '../../../types';
2424
import type { AvailableSources } from './vmNicsCard';
2525

26-
import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox";
2726
import { Form, FormGroup } from "@patternfly/react-core/dist/esm/components/Form";
2827
import {
2928
Modal, ModalBody, ModalFooter, ModalHeader
@@ -32,8 +31,7 @@ import { Radio } from "@patternfly/react-core/dist/esm/components/Radio";
3231
import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput";
3332

3433
import {
35-
NetworkTypeAndSourceValue, NetworkTypeAndSourceRow,
36-
init_NetworkTypeAndSourceRow, validate_NetworkTypeAndSourceRow,
34+
NetworkTypeAndSourceValue, NetworkTypeAndSourceRow, init_NetworkTypeAndSourceRow,
3735
NetworkModelRow,
3836
PortForwardsValue, NetworkPortForwardsRow, validate_PortForwards,
3937
dialogPortForwardsToInterface,
@@ -44,9 +42,12 @@ import { AppState } from '../../../app';
4442
import {
4543
useDialogState, DialogValue, DialogError,
4644
DialogErrorMessage, DialogHelperText,
47-
DialogActionButton, DialogCancelButton
45+
DialogActionButton, DialogCancelButton,
46+
DialogCheckbox,
4847
} from '../../common/dialog';
4948

49+
import create_default_network_sh from "./create-default-network.sh";
50+
5051
import './nic.css';
5152

5253
const _ = cockpit.gettext;
@@ -143,18 +144,11 @@ const PermanentChange = ({
143144
// down only. Enable permanent change of the domain.xml
144145

145146
return (
146-
<FormGroup
147-
fieldId={value.id()}
148-
label={_("Persistence")}
149-
hasNoPaddingTop
150-
>
151-
<Checkbox
152-
id={value.id()}
153-
isChecked={value.get()}
154-
label={_("Always attach")}
155-
onChange={(_event, checked) => value.set(checked)}
156-
/>
157-
</FormGroup>
147+
<DialogCheckbox
148+
field_label={_("Persistence")}
149+
checkbox_label={_("Always attach")}
150+
value={value}
151+
/>
158152
);
159153
};
160154

@@ -191,7 +185,6 @@ export const AddNIC = ({
191185

192186
function validate() {
193187
validate_NetworkMacRow(dlg.value("mac"));
194-
validate_NetworkTypeAndSourceRow(dlg.value("type_and_source"));
195188
if (dlg.values.type_and_source.type == "user")
196189
validate_PortForwards(dlg.value("portForwards"));
197190
}
@@ -217,6 +210,10 @@ export const AddNIC = ({
217210
let backend = null;
218211
if (tas.type == "user" && vm.capabilities.interfaceBackends.includes("passt"))
219212
backend = "passt";
213+
if (source == "$create") {
214+
await cockpit.script(create_default_network_sh, [], { err: "message", superuser: "try" });
215+
source = "default";
216+
}
220217
await virtXmlHotAdd(
221218
vm,
222219
"network",

0 commit comments

Comments
 (0)