summaryrefslogtreecommitdiff
path: root/src/migration-scripts/interfaces/34-to-35
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-10-31 11:51:09 +0100
committerGitHub <noreply@github.com>2026-10-31 11:51:09 +0100
commitdfd2b46ff41af4edf2fd4a2a1b9fae1efe48c145 (patch)
tree9c5538ea145c2a869bdf379398219aa74730bd86 /src/migration-scripts/interfaces/34-to-35
parentc15665309e2991e6de5f99bf375de83d167c4248 (diff)
parent6bef88ed9c11210855689bd78a39ee032fb27731 (diff)
downloadvyos-1x-dfd2b46ff41af4edf2fd4a2a1b9fae1efe48c145.tar.gz
vyos-1x-dfd2b46ff41af4edf2fd4a2a1b9fae1efe48c145.zip
Merge pull request #5479 from c-po/T3871-ifname-store
T3871: bind interface names to hardware slots instead of hw-id
Diffstat (limited to 'src/migration-scripts/interfaces/34-to-35')
-rwxr-xr-xsrc/migration-scripts/interfaces/34-to-3569
1 files changed, 69 insertions, 0 deletions
diff --git a/src/migration-scripts/interfaces/34-to-35 b/src/migration-scripts/interfaces/34-to-35
new file mode 100755
index 000000000..a09dc8cd8
--- /dev/null
+++ b/src/migration-scripts/interfaces/34-to-35
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+#
+# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# T3871: interface names are no longer derived from 'hw-id'. Carry the existing
+# bindings over to the mapping store - anchored to the slot the MAC sits in, so
+# nothing is renamed - then drop the node. Hardware which is not present is
+# skipped: the configuration may well originate from another machine.
+
+from vyos.configtree import ConfigTree
+from vyos.ifconfig.ifname_store import discover_devices
+from vyos.ifconfig.ifname_store import load_store
+from vyos.ifconfig.ifname_store import save_store
+from vyos.ifconfig.ifname_store import sync_link_files
+
+bases = (['interfaces', 'ethernet'], ['interfaces', 'wireless'])
+
+
+def migrate(config: ConfigTree) -> None:
+ bindings = {}
+ for base in bases:
+ if not config.exists(base):
+ continue
+ for intf in config.list_nodes(base):
+ path = base + [intf, 'hw-id']
+ if config.exists(path):
+ bindings[intf] = config.return_value(path).lower()
+ config.delete(path)
+
+ if not bindings:
+ return
+
+ devices = {device['mac']: device for device in discover_devices()}
+ store = load_store()
+ entries = store['interfaces']
+ added = False
+
+ taken = set(entries.values())
+
+ for name, hwid in bindings.items():
+ device = devices.get(hwid)
+ if device is None or not device['key']:
+ continue
+ # an entry already in the store is authoritative, and a slot already
+ # spoken for must not gain a second name - only one of them could
+ # ever be filled
+ if name in entries or device['key'] in taken:
+ continue
+ entries[name] = device['key']
+ taken.add(device['key'])
+ added = True
+
+ if added and save_store(store):
+ try:
+ sync_link_files(store, devices=list(devices.values()))
+ except OSError:
+ pass