Skip to content

Commit

Permalink
networkmanager: fix primary bond option
Browse files Browse the repository at this point in the history
- allow setting also for balance-tlb / balance-alb modes
- read the current value
- remove when not set (it can't be set to an empty string)
- remove when switching to a non compatible mode
  • Loading branch information
champtar committed Jan 17, 2025
1 parent 67b2f5a commit 37134fc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions pkg/networkmanager/bond.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const bond_monitoring_choices =
{ choice: 'arp', title: _("ARP") }
];

const modes_with_primary = [
'active-backup',
'balance-tlb',
'balance-alb'
];

export const BondDialog = ({ connection, dev, settings }) => {
const Dialogs = useDialogs();
const idPrefix = "network-bond-settings";
Expand All @@ -77,9 +83,12 @@ export const BondDialog = ({ connection, dev, settings }) => {
const [memberChoices, setMemberChoices] = useState(memberChoicesInit);
const [mode, setMode] = useState(options.mode);
const [monitoringTargets, setMonitoringTargets] = useState(options.arp_ip_target);
const [primary, setPrimary] = useState(undefined);
const [primary, setPrimary] = useState(options.primary);

const onSubmit = (ev) => {
const options = settings.bond.options;
delete options['primary'];

const createSettingsObj = () => ({
...settings,
connection: {
Expand All @@ -94,7 +103,7 @@ export const BondDialog = ({ connection, dev, settings }) => {
...settings.bond,
interface_name: iface,
options: {
...settings.bond.options,
...options,
mode,
...(linkMonitoring == 'mii' && {
miimon: linkMonitoringInterval,
Expand All @@ -105,7 +114,7 @@ export const BondDialog = ({ connection, dev, settings }) => {
arp_interval: linkMonitoringInterval,
arp_ip_target: monitoringTargets,
}),
...(mode == "active-backup" && { primary })
...(modes_with_primary.includes(mode) && primary && { primary })
}
}
});
Expand Down Expand Up @@ -174,11 +183,11 @@ export const BondDialog = ({ connection, dev, settings }) => {
{bond_mode_choices.map(choice => <FormSelectOption value={choice.choice} label={choice.title} key={choice.choice} />)}
</FormSelect>
</FormGroup>
{mode == "active-backup" && <FormGroup fieldId={idPrefix + "-primary-select"} label={_("Primary")}>
{modes_with_primary.includes(mode) && <FormGroup fieldId={idPrefix + "-primary-select"} label={_("Primary")}>
<FormSelect id={idPrefix + "-primary-select"} onChange={(_, val) => setPrimary(val)}
value={primary}>
<>
<FormSelectOption key='-' value={null} label='-' />
<FormSelectOption key='-' value='' label='-' />
{Object.keys(memberChoices)
.filter(iface => memberChoices[iface])
.map(iface => <FormSelectOption key={iface} label={iface} value={iface} />)}
Expand Down

0 comments on commit 37134fc

Please sign in to comment.