Revision 2e26966f snf-common/synnefo/lib/services.py

b/snf-common/synnefo/lib/services.py
56 56
        if service.get('public', False):
57 57
            public_services[name] = deepcopy(service)
58 58
    return public_services
59

  
60

  
61
def get_public_endpoint(services, service_type, version=None):
62
    found_endpoints = {}
63
    for service_name, service in services.iteritems():
64
        if service_type != service['type']:
65
            continue
66

  
67
        for endpoint in service['endpoints']:
68
            endpoint_version = endpoint['versionId']
69
            if version is not None:
70
                if version != endpoint_version:
71
                    continue
72
            found_endpoints[endpoint_version] = endpoint
73

  
74
    if not found_endpoints:
75
        m = "No endpoint found for service type '{0}'".format(service_type)
76
        if version is not None:
77
            m += " and version '{0}'".format(version)
78
        raise ValueError(m)
79

  
80
    selected = sorted(found_endpoints.keys())[-1]
81
    return found_endpoints[selected]['publicURL']

Also available in: Unified diff