X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fplugins%2FOpenStack%2Fcommon.py;h=09c911dc02f69c6fbf2707a37af286417183e3c0;hb=6eda48bf7489c00fee4e1f276404ab82db23fd1d;hp=64cbf7f493f6ebab11a31439414309a096bd3fac;hpb=9608081aa7b0ff8823ddbcd1144948ee0369160e;p=osm%2FMON.git diff --git a/osm_mon/plugins/OpenStack/common.py b/osm_mon/plugins/OpenStack/common.py index 64cbf7f..09c911d 100644 --- a/osm_mon/plugins/OpenStack/common.py +++ b/osm_mon/plugins/OpenStack/common.py @@ -61,7 +61,15 @@ class Common(object): @staticmethod def get_endpoint(service_type, vim_uuid, verify_ssl=True): - """Get the endpoint for Gnocchi/Aodh.""" + """ + Gets the public endpoint for an OpenStack service in the configured region (default: RegionOne). + :param service_type: Service type name (eg. metric or alarming) + :param vim_uuid: VIM UUID generated by OSM + :param verify_ssl: If False, disables SSL validation. Useful when using self signed certs. + :return: Endpoint url string. + + :raises ValueError If it can't find services, or if it can find services but no endpoint for specified region. + """ auth_manager = AuthManager() creds = auth_manager.get_credentials(vim_uuid) auth = v3.Password(auth_url=creds.url, @@ -72,7 +80,10 @@ class Common(object): user_domain_id='default') sess = session.Session(auth=auth, verify=verify_ssl) ks = client.Client(session=sess, interface='public') - service = ks.services.list(type=service_type)[0] + services = ks.services.list(type=service_type) + if not services: + raise ValueError("No services found for {}. Is the corresponding service enabled?".format(service_type)) + service = services[0] endpoints = ks.endpoints.list(service) endpoint_type = 'publicURL' region_name = 'RegionOne' @@ -88,6 +99,7 @@ class Common(object): for endpoint in endpoints: if endpoint.interface in endpoint_type and endpoint.region == region_name: return endpoint.url + raise ValueError("No endpoints found for service {} in region {}".format(service_type, region_name)) @staticmethod def perform_request(url, auth_token,