Bug 1938 fixed: : added a random suffix to the end of the Juju app name, in order...
[osm/N2VC.git] / n2vc / utils.py
index 0dbd71e..5ac0e2c 100644 (file)
@@ -16,6 +16,8 @@ import base64
 import re
 import binascii
 import yaml
+import string
+import secrets
 from enum import Enum
 from juju.machine import Machine
 from juju.application import Application
@@ -147,3 +149,15 @@ def obj_to_dict(obj: object) -> dict:
     yaml_text = obj_to_yaml(obj)
     # parse to dict
     return yaml.load(yaml_text, Loader=yaml.Loader)
+
+
+def generate_random_alfanum_string(size: int) -> str:
+    """
+    Generate random alfa-numeric string with a size given by argument
+    :param size:
+    :return: random generated string
+    """
+
+    return "".join(
+        secrets.choice(string.ascii_letters + string.digits) for i in range(size)
+    )