-
-def get_non_used_vim_name(datacenter_name, datacenter_id, tenant_name, tenant_id):
- name = datacenter_name[:16]
- if name not in vim_threads["names"]:
- vim_threads["names"].append(name)
- return name
- if tenant_name:
- name = datacenter_name[:16] + "." + tenant_name[:16]
- if name not in vim_threads["names"]:
- vim_threads["names"].append(name)
- return name
- name = datacenter_id
- vim_threads["names"].append(name)
- return name
+def get_process_id():
+ """
+ Obtain a unique ID for this process. If running from inside docker, it will get docker ID. If not it
+ will provide a random one
+ :return: Obtained ID
+ """
+ # Try getting docker id. If fails, get pid
+ try:
+ with open("/proc/self/cgroup", "r") as f:
+ text_id_ = f.readline()
+ _, _, text_id = text_id_.rpartition("/")
+ text_id = text_id.replace("\n", "")[:12]
+ if text_id:
+ return text_id
+ except Exception:
+ pass
+ # Return a random id
+ return "".join(random_choice("0123456789abcdef") for _ in range(12))
+
+def get_non_used_vim_name(datacenter_name, datacenter_id):
+ return "{}:{}:{}".format(
+ worker_id[:12], datacenter_id.replace("-", "")[:32], datacenter_name[:16]
+ )