diff options
author | Jing Lu <lvjing5@huawei.com> | 2017-07-19 08:17:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-07-19 08:17:38 +0000 |
commit | 6febc2e33d6ced9b4182cf8d026e65fe983752fc (patch) | |
tree | 77c494bd03452cdc0ab3a620b493042b63af2eb8 /yardstick | |
parent | c59b4b03550abf847959b5575ba81acf72d6fe5c (diff) | |
parent | 146e193c209fe654c4aeb88e9a2564df9960a8e4 (diff) |
Merge "Add API(v2) to create influxdb"
Diffstat (limited to 'yardstick')
-rw-r--r-- | yardstick/common/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/yardstick/common/utils.py b/yardstick/common/utils.py index a4f7b30dc..92bb7b7d3 100644 --- a/yardstick/common/utils.py +++ b/yardstick/common/utils.py @@ -24,7 +24,10 @@ import os import subprocess import sys import collections +import socket +import random from functools import reduce +from contextlib import closing import yaml import six @@ -263,3 +266,11 @@ def set_dict_value(dic, keys, value): else: return_dic = return_dic[key] return dic + + +def get_free_port(ip): + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: + while True: + port = random.randint(5000, 10000) + if s.connect_ex((ip, port)) != 0: + return port |