summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxudan <xudan16@huawei.com>2018-09-04 00:18:58 -0400
committerxudan <xudan16@huawei.com>2018-09-05 02:56:03 -0400
commit3f92680059a8371ec6002e1d909cd89cc4bab96d (patch)
tree2a674f175e7e6d131581e712878a247b6adb3eea
parent16ec1f400882a80c2762c2b1667af81089555591 (diff)
Enable the web portal to show all endpoints
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>
-rw-r--r--dovetail/utils/dovetail_utils.py25
-rw-r--r--dovetail/utils/openstack_utils.py15
2 files changed, 29 insertions, 11 deletions
diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py
index aceb36d5..4a8b45ff 100644
--- a/dovetail/utils/dovetail_utils.py
+++ b/dovetail/utils/dovetail_utils.py
@@ -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
diff --git a/dovetail/utils/openstack_utils.py b/dovetail/utils/openstack_utils.py
index 2c57b7c8..2ce2df9d 100644
--- a/dovetail/utils/openstack_utils.py
+++ b/dovetail/utils/openstack_utils.py
@@ -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