Skip to content

feat: filter out used networks in network selector WD-34762#1885

Open
omarelkashef wants to merge 1 commit intocanonical:mainfrom
omarelkashef:WD-34762-filter-out-used-networks-in-network-selector
Open

feat: filter out used networks in network selector WD-34762#1885
omarelkashef wants to merge 1 commit intocanonical:mainfrom
omarelkashef:WD-34762-filter-out-used-networks-in-network-selector

Conversation

@omarelkashef
Copy link
Contributor

@omarelkashef omarelkashef commented Mar 20, 2026

Done

  • Filter out used networks from network selector
  1. Run the LXD-UI:
  2. Perform the following QA steps:
    • Go to Instance
    • Create or edit instance
    • Go to Configuration -> Devices -> Networks
    • Attach or edit network
    • Ensure any network already attached to the instance does not show in the network selector unless dns.mode = "none" on the network or you are currently editing that network.
      NOTE: it is possible now to create a profile attached to a network twice. This will cause an error when starting an instance with that profile. This can be fixed in another PR.

Signed-off-by: Omar Elkashef <omarelkashef01@gmail.com>
@webteam-app
Copy link

@omarelkashef omarelkashef changed the title feat: filter out used networks in network selector feat: filter out used networks in network selector WD-34762 Mar 20, 2026
Comment on lines +191 to +196
const appliedProfiles = getAppliedProfiles(values, profiles);
for (const profile of appliedProfiles) {
Object.values(profile.devices).map((item) => {
existingNetworksNames.push((item as LxdNicDevice).network);
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be more careful here. Some of those inherited devices can be overridden by other profiles or by instance networks. Maybe better to use the getInheritedNetworks helper. Which we actually already call in NetworkDevicePanel, so perhaps we can pass those into this function instead of calculating them afresh.

Comment on lines +88 to +104
const isEditing = panelParams.panel === panels.editNetworkDevice;
const isEditingNetwork = (network: LxdNetwork) => {
return isEditing && device?.network === network.name;
};
const canAttachNetworkAgain = (network: LxdNetwork) => {
return (
parentFormik.values.entityType === "profile" ||
!existingNetworks.includes(network.name) ||
network.config["dns.mode"] === "none"
);
};

const managedNetworks = networks.filter((network) => network.managed);
const managedNetworks = networks.filter(
(network) =>
network.managed &&
(isEditingNetwork(network) || canAttachNetworkAgain(network)),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isEditing = panelParams.panel === panels.editNetworkDevice;
const isEditingNetwork = (network: LxdNetwork) => {
return isEditing && device?.network === network.name;
};
const canAttachNetworkAgain = (network: LxdNetwork) => {
return (
parentFormik.values.entityType === "profile" ||
!existingNetworks.includes(network.name) ||
network.config["dns.mode"] === "none"
);
};
const managedNetworks = networks.filter((network) => network.managed);
const managedNetworks = networks.filter(
(network) =>
network.managed &&
(isEditingNetwork(network) || canAttachNetworkAgain(network)),
);
const isAvailable = (network: LxdNetwork) => {
if (network.managed) {
return false;
}
const isSelectedNetwork = isEditing && device?.network === network.name;
const isUnused = !existingNetworks.includes(network.name);
const allowsDuplicateAttachment = network.config["dns.mode"] === "none";
return isSelectedNetwork || isUnused || allowsDuplicateAttachment;
};
const networkOptions = networks.filter(isAvailable);

Suggesting to slightly restructure the filter logic here. Wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants