diff options
author | Dan Klein <danklei@cisco.com> | 2015-08-24 17:28:17 +0300 |
---|---|---|
committer | Dan Klein <danklei@cisco.com> | 2015-08-24 17:28:17 +0300 |
commit | 7d3be8c612e295820649779335288c197b80ccb2 (patch) | |
tree | 78e9636bc8780dedc919c30378a621f425e1cbfc /scripts/automation/trex_control_plane/client_utils/general_utils.py | |
parent | dab741a80699f86e86c91718872a052cca9bbb25 (diff) |
Changes location of console and fixed dependencies
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils/general_utils.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/client_utils/general_utils.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/general_utils.py b/scripts/automation/trex_control_plane/client_utils/general_utils.py index 5544eabc..b5912628 100755 --- a/scripts/automation/trex_control_plane/client_utils/general_utils.py +++ b/scripts/automation/trex_control_plane/client_utils/general_utils.py @@ -1,6 +1,9 @@ #!/router/bin/python -import sys,site +import sys +import site +import string +import random import os try: @@ -50,7 +53,27 @@ def find_path_to_pardir (pardir, base_path = os.getcwd() ): """ components = base_path.split(os.sep) return str.join(os.sep, components[:components.index(pardir)+1]) - + + +def random_id_gen(length=8): + """ + A generator for creating a random chars id of specific length + + :parameters: + length : int + the desired length of the generated id + + default: 8 + + :return: + a random id with each next() request. + """ + id_chars = string.ascii_lowercase + string.digits + while True: + return_id = '' + for i in range(length): + return_id += random.choice(id_chars) + yield return_id if __name__ == "__main__": |