summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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