Multi env support and Kube client integration

Kube friendly Beta

Package versions supports Kube env

Added:
  - Env type detection
  - New option: --use-env, for selecting env
    when function supports multiple detected envs
  - Updated config loading
  - Each module and command type has supported env check
    and stops execution if it is on unsupported env
  - Functions can support multiple envs
  - Kubernetes dependency
  - Kubenernetes API detection: local and remote
  - Package checking class hierachy for using Salt or Kube
  - Remote pod execution routine
  - Flexible SSH/SSH Forwarder classes: with, ssh,do(), etc
  - Multithreaded SSH script execution
  - Number of workers parameter, default 5

Fixed:
  - Config dependency
  - Command loading with supported envs list
  - Unittests structure and execution flow updated
  - Unittests fixes
  - Fixed debug mode handling
  - Unified command type/support routine
  - Nested attrs getter/setter

Change-Id: I3ade693ac21536e2b5dcee4b24d511749dc72759
Related-PROD: PROD-35811
diff --git a/cfg_checker/common/file_utils.py b/cfg_checker/common/file_utils.py
index 398ea66..6fbb675 100644
--- a/cfg_checker/common/file_utils.py
+++ b/cfg_checker/common/file_utils.py
@@ -1,11 +1,12 @@
+import atexit
 import grp
 import os
 import pwd
 import time
+import tempfile
 
-from cfg_checker.common import config
-
-_default_time_format = config.date_format
+_default_time_format = "%Y-%m-%d %H:%M:%S.%f%z"
+_temp_files = {}
 
 
 def remove_file(filename):
@@ -110,3 +111,35 @@
         return "... folder '{}' removed".format(_folder)
     else:
         return "... folder '{}' not exists".format(_folder)
+
+
+def _cleanup_temp_files():
+    global _temp_files
+    for temp_file in _temp_files.values():
+        try:
+            os.remove(temp_file)
+        except OSError:
+            pass
+    _temp_files = {}
+
+
+def create_temp_file_with_content(content, mode=None):
+    if len(_temp_files) == 0:
+        atexit.register(_cleanup_temp_files)
+    # Because we may change context several times, try to remember files we
+    # created and reuse them at a small memory cost.
+    content_key = hash(content)
+    if content_key in _temp_files:
+        return _temp_files[content_key]
+
+    # new file, create it
+    _, name = tempfile.mkstemp()
+    _temp_files[content_key] = name
+    with open(name, 'wb') as fd:
+        fd.write(content.encode() if isinstance(content, str) else content)
+
+    # set mode for the file
+    if mode:
+        os.chmod(name, mode)
+
+    return name