async def _services_with_assets(storage_client, south_services): sr_list = list() try: try: services_from_registry = ServiceRegistry.get(s_type="Southbound") except DoesNotExist: services_from_registry = [] def is_svc_in_service_registry(name): return next( (svc for svc in services_from_registry if svc._name == name), None) for s_record in services_from_registry: sr_list.append({ 'name': s_record._name, 'address': s_record._address, 'management_port': s_record._management_port, 'service_port': s_record._port, 'protocol': s_record._protocol, 'status': ServiceRecord.Status(int(s_record._status)).name.lower(), 'assets': await _get_tracked_assets_and_readings(storage_client, s_record._name), 'schedule_enabled': await _get_schedule_status(storage_client, s_record._name) }) for s_name in south_services: south_svc = is_svc_in_service_registry(s_name) if not south_svc: sr_list.append({ 'name': s_name, 'address': '', 'management_port': '', 'service_port': '', 'protocol': '', 'status': '', 'assets': await _get_tracked_assets_and_readings(storage_client, s_name), 'schedule_enabled': await _get_schedule_status(storage_client, s_name) }) except: raise else: return sr_list
def services_health_litmus_test(): all_svc_status = [ ServiceRecord.Status(int(service_record._status)).name.upper() for service_record in ServiceRegistry.all() ] if 'FAILED' in all_svc_status: return 'red' elif 'UNRESPONSIVE' in all_svc_status: return 'amber' return 'green'
async def get_service(cls, request): """ Returns a list of all services or as per name &|| type filter :Example: curl -X GET http://localhost:<core mgt port>/foglamp/service curl -X GET http://localhost:<core mgt port>/foglamp/service?name=X&type=Storage """ service_name = request.query[ 'name'] if 'name' in request.query else None service_type = request.query[ 'type'] if 'type' in request.query else None try: if not service_name and not service_type: services_list = ServiceRegistry.all() elif service_name and not service_type: services_list = ServiceRegistry.get(name=service_name) elif not service_name and service_type: services_list = ServiceRegistry.get(s_type=service_type) else: services_list = ServiceRegistry.filter_by_name_and_type( name=service_name, s_type=service_type) except service_registry_exceptions.DoesNotExist as ex: if not service_name and not service_type: msg = 'No service found' elif service_name and not service_type: msg = 'Service with name {} does not exist'.format( service_name) elif not service_name and service_type: msg = 'Service with type {} does not exist'.format( service_type) else: msg = 'Service with name {} and type {} does not exist'.format( service_name, service_type) raise web.HTTPNotFound(reason=msg) services = [] for service in services_list: svc = dict() svc["id"] = service._id svc["name"] = service._name svc["type"] = service._type svc["address"] = service._address svc["management_port"] = service._management_port svc["protocol"] = service._protocol svc["status"] = ServiceRecord.Status(int( service._status)).name.lower() if service._port: svc["service_port"] = service._port services.append(svc) return web.json_response({"services": services})
def get_service_records(): sr_list = list() for service_record in ServiceRegistry.all(): sr_list.append( { 'name': service_record._name, 'type': service_record._type, 'address': service_record._address, 'management_port': service_record._management_port, 'service_port': service_record._port, 'protocol': service_record._protocol, 'status': ServiceRecord.Status(int(service_record._status)).name.lower() }) recs = {'services': sr_list} return recs