From a4bad24c6a368cdfc556f6cd3421ef7835b2670c Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 30 Apr 2024 09:21:11 -0400 Subject: [PATCH] mgr/smb: add rand_name function This will be used later to create resources that are not directly named by a user. Signed-off-by: John Mulligan --- src/pybind/mgr/smb/handler.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pybind/mgr/smb/handler.py b/src/pybind/mgr/smb/handler.py index f6ef431b04b..ab97bc1248f 100644 --- a/src/pybind/mgr/smb/handler.py +++ b/src/pybind/mgr/smb/handler.py @@ -1173,3 +1173,11 @@ def _cephx_data_entity(cluster_id: str) -> str: use for data access. """ return f'client.smb.fs.cluster.{cluster_id}' + + +def rand_name(prefix: str, max_len: int = 18, suffix_len: int = 8) -> str: + trunc = prefix[: (max_len - suffix_len)] + suffix = ''.join( + random.choice(string.ascii_lowercase) for _ in range(suffix_len) + ) + return f'{trunc}{suffix}' -- 2.39.5