summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2025-11-04 17:53:11 +0200
committerGitHub <noreply@github.com>2025-11-04 17:53:11 +0200
commitcc60275ab0db2c45f2ad7387d6a91a96fa9d6337 (patch)
treea59baa904529193481c12fb112a2de29b9d08608 /python
parent6d0324506a5b0419eb0ae001d8d006a414030405 (diff)
parentae6d3437dc3247c396444b7f65eb49a98b0dd800 (diff)
downloadvyos-1x-cc60275ab0db2c45f2ad7387d6a91a96fa9d6337.tar.gz
vyos-1x-cc60275ab0db2c45f2ad7387d6a91a96fa9d6337.zip
Merge pull request #4828 from c-po/restart-container-vrf
container: T7305: fix VRF loss when restarting pods
Diffstat (limited to 'python')
-rw-r--r--python/vyos/container.py41
-rw-r--r--python/vyos/ifconfig/interface.py2
2 files changed, 42 insertions, 1 deletions
diff --git a/python/vyos/container.py b/python/vyos/container.py
new file mode 100644
index 000000000..475d796f2
--- /dev/null
+++ b/python/vyos/container.py
@@ -0,0 +1,41 @@
+# 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/>.
+
+from vyos.config import Config
+from vyos.ifconfig import Interface
+from vyos.utils.dict import dict_search
+from vyos.utils.network import interface_exists
+
+def restart_network(config: Config) -> None:
+ """
+ Start network and assign it to given VRF if requested.
+
+ This can only be done after the containers got started as the podman network
+ interface will only be enabled by the first container and yet I do not know
+ how to enable the network interface in advance.
+ """
+ if 'network' in config:
+ for network, network_config in config['network'].items():
+ type_config = dict_search('type', network_config)
+ if not dict_search('macvlan', type_config):
+ network_name = f'pod-{network}'
+ # T5147: Networks are started only as soon as there is a consumer.
+ # If only a network is created in the first place, no need to assign
+ # it to a VRF as there's no consumer, yet.
+ if interface_exists(network_name):
+ tmp = Interface(network_name)
+ tmp.set_vrf(network_config.get('vrf', ''))
+ tmp.add_ipv6_eui64_address('fe80::/64')
+
+ return None
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 761ba1799..ad634c4d7 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -619,7 +619,7 @@ class Interface(Control):
if 'netns' in self.config:
return False
- tmp = self.get_interface('vrf')
+ tmp = self.get_vrf()
if tmp == vrf:
return False