You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmstate/SOURCES/RHEL_11660-ip-Support-treat...

74 lines
2.6 KiB

From 4c1c741d4dd4d68e12c6e27478f1c320820dd003 Mon Sep 17 00:00:00 2001
From: Wen Liang <liangwen12year@gmail.com>
Date: Fri, 29 Sep 2023 14:31:34 -0400
Subject: [PATCH 1/1] ip: Support treating string as int for `prefix-length`
When the network role user is using the `network_state` variable to
configure the network, and if they are using Jinja2 template to
define the `prefix-length`, the type conversion
`prefix-length: "{{ __str_val | int }}"` does not work as expected, the
type for `prefix-length` in the end is still string. Therefore, nmstate
need to support treating string as int for `prefix-length` in order to
make the apply succeed.
Signed-off-by: Wen Liang <liangwen12year@gmail.com>
---
libnmstate/ifaces/base_iface.py | 7 +++++++
libnmstate/schemas/operational-state.yaml | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/libnmstate/ifaces/base_iface.py b/libnmstate/ifaces/base_iface.py
index c1a4c04b..b1e4c811 100644
--- a/libnmstate/ifaces/base_iface.py
+++ b/libnmstate/ifaces/base_iface.py
@@ -48,6 +48,7 @@ class IPState:
self._info = info
self._remove_stack_if_disabled()
self._canonicalize_ip_addr()
+ self._canonicalize_ip_prefix()
self._canonicalize_dynamic()
def _canonicalize_dynamic(self):
@@ -71,6 +72,12 @@ class IPState:
addr[InterfaceIP.ADDRESS_IP]
)
+ def _canonicalize_ip_prefix(self):
+ for addr in self.addresses:
+ addr[InterfaceIP.ADDRESS_PREFIX_LENGTH] = int(
+ addr[InterfaceIP.ADDRESS_PREFIX_LENGTH]
+ )
+
def sort_addresses(self):
self.addresses.sort(key=itemgetter(InterfaceIP.ADDRESS_IP))
diff --git a/libnmstate/schemas/operational-state.yaml b/libnmstate/schemas/operational-state.yaml
index 92bd6bd6..8526a0ab 100644
--- a/libnmstate/schemas/operational-state.yaml
+++ b/libnmstate/schemas/operational-state.yaml
@@ -615,7 +615,9 @@ definitions:
ip:
type: string
prefix-length:
- type: integer
+ type:
+ - integer
+ - string
netmask:
type: string
neighbor:
@@ -654,7 +656,9 @@ definitions:
ip:
type: string
prefix-length:
- type: integer
+ type:
+ - integer
+ - string
neighbor:
type: array
items:
--
2.41.0