Enable the web portal to show all endpoints 91/61791/3
authorxudan <xudan16@huawei.com>
Tue, 4 Sep 2018 04:18:58 +0000 (00:18 -0400)
committerxudan <xudan16@huawei.com>
Wed, 5 Sep 2018 06:56:03 +0000 (02:56 -0400)
The endpoints info for the 2018.08 has been changed.

The web portal needs some adaptions for the new data format.

It keeps the same as 2018.01 and doesn't need to change dovetail-webportal.

JIRA: DOVETAIL-725

Change-Id: I74cde3aa6032c7afac4b6ce1d2146e09a0f99fe5
Signed-off-by: xudan <xudan16@huawei.com>
dovetail/utils/dovetail_utils.py
dovetail/utils/openstack_utils.py

index aceb36d..4a8b45f 100644 (file)
@@ -269,19 +269,32 @@ def get_openstack_endpoint(logger=None):
         os_utils = OS_Utils(verify=False)
     else:
         os_utils = OS_Utils()
-    res, msg = os_utils.list_endpoints()
-    if not res:
-        logger.error("Failed to get admin endpoints. Exception message, {}"
-                     .format(msg))
+    res_endpoints, msg_endpoints = os_utils.search_endpoints()
+    if not res_endpoints:
+        logger.error("Failed to list endpoints. Exception message, {}"
+                     .format(msg_endpoints))
         return None
+    endpoints_info = []
+    for item in msg_endpoints:
+        endpoint = {'URL': item['url'], 'Enabled': item['enabled']}
+        res_services, msg_services = os_utils.search_services(
+            service_id=item['service_id'])
+        if not res_services:
+            logger.error("Failed to list services. Exception message, {}"
+                         .format(msg_services))
+            return None
+        endpoint['Service Type'] = msg_services[0]['service_type']
+        endpoint['Service Name'] = msg_services[0]['name']
+        endpoints_info.append(endpoint)
+
     result_file = os.path.join(dt_cfg.dovetail_config['result_dir'],
                                'endpoint_info.json')
     try:
         with open(result_file, 'w') as f:
-            f.write(msg)
+            json.dump(endpoints_info, f)
             logger.debug("Record all endpoint info into file {}."
                          .format(result_file))
-            return msg
+            return endpoints_info
     except Exception:
         logger.exception("Failed to write endpoint info into file.")
         return None
index 2c57b7c..2ce2df9 100644 (file)
@@ -8,7 +8,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 
-import json
 import os_client_config
 import shade
 from shade import exc
@@ -21,10 +20,16 @@ class OS_Utils(object):
         self.images = []
         self.flavors = []
 
-    def list_endpoints(self):
+    def search_endpoints(self, interface='public'):
         try:
-            res = self.cloud.search_endpoints()
-            endpoints = json.dumps(res)
-            return True, endpoints
+            res = self.cloud.search_endpoints(filters={'interface': interface})
+            return True, res
+        except exc.OpenStackCloudException as o_exc:
+            return False, o_exc.orig_message
+
+    def search_services(self, service_id=None):
+        try:
+            res = self.cloud.search_services(name_or_id=service_id)
+            return True, res
         except exc.OpenStackCloudException as o_exc:
             return False, o_exc.orig_message