Skip to content

Commit

Permalink
refractor: Add nm_support_version_cmp() utility function
Browse files Browse the repository at this point in the history
When configuring certain property using nm provider, we need to
know if the running nm client version is not less than the earliest
supported version of the property, otherwise, the role need to fail
earlier and gracefully.

Signed-off-by: Wen Liang <[email protected]>
  • Loading branch information
liangwen12year committed Jan 10, 2024
1 parent e4d4997 commit 8847135
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions module_utils/network_lsr/nm/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ def get_client_version(self):
nm_client = client.get_client()
return nm_client.get_version()

def nm_support_version_cmp(self, nm_support_version):
v = self.get_client_version().split(".")
major = int(v[0])
minor = int(v[1])
micro = int(v[2])
nm_support_v = nm_support_version.split(".")
nm_major = int(nm_support_v[0])
nm_minor = int(nm_support_v[1])
nm_micro = int(nm_support_v[2])
# emulate the behavior of `nm_client_get_version_info()` to encode NM daemon
# version as "(major << 16 | minor << 8 | micro)", but
# `nm_client_get_version_info()` is only supported to use since NM 1.42
return (major << 16 | minor << 8 | micro) >= (
nm_major << 16 | nm_minor << 8 | nm_micro
)

def reload_configuration(self):
timeout = 10
nm_client = client.get_client()
Expand Down

0 comments on commit 8847135

Please sign in to comment.