Extend contrail_health for api_status function

Related-Bug: PROD-26298

Change-Id: I8696e896b109e401c35183b1c72ee0c1d7f93680
(cherry picked from commit ec6e7a75f49c88c8acc318bd2153a1c305387040)
diff --git a/_modules/contrail_health.py b/_modules/contrail_health.py
index 750cd8c..0b539c9 100644
--- a/_modules/contrail_health.py
+++ b/_modules/contrail_health.py
@@ -15,6 +15,10 @@
 import logging
 import os
 import subprocess
+import time
+
+# Import Salt Libs
+import salt.utils.http
 
 
 MODULE_NAME = 'contrail_health'
@@ -78,3 +82,36 @@
                   'by {0} module.'.format(MODULE_NAME))
 
     return status_map
+
+'''
+    Check status of Contail API service on Virtual IP which is defined by pillars.
+
+    CLI Example:
+
+    .. code-block:: bash
+
+        salt 'ntw01*' contrail_health.get_api_status [wait_for=300] \\
+                [tries=20]
+
+    wait_for
+        Number of seconds how long to wait for API response.
+
+    tries
+        Number of tries. After each unsuccessful try will sleep for \\
+        (wait_for/tries).
+'''
+
+
+def get_api_status(wait_for=180, tries=20):
+    api_host = __pillar__['opencontrail'].get('client', {}).get('api', {}).get('host', {})
+    api_port = __pillar__['opencontrail']['client']['api']['port']
+    for t in range(0, tries):
+        try:
+            data = salt.utils.http.query("http://{0}:{1}".format(api_host, api_port), status=True)
+        except:
+            time.sleep(int(wait_for / tries))
+            continue
+        if data['status'] == 200:
+            return True
+
+    return False