#!/usr/bin/python2.7 -E # # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. # ''' Return a list AI Services ''' import logging import os import simplejson import sys from operator import itemgetter from solaris_install import SCRIPT_LOGGER_NAME from solaris_install.ai.server import Server def get_services_list(): '''Return a listof AI services''' output_list = [] services = Server.get_instance().get_services() for svc in services: svc_wiz_dir = os.path.join(svc.image_path, 'auto_install/wizard') if os.path.isdir(svc_wiz_dir): service = {} # save the fields we want service['name'] = svc.name service['aliasof'] = svc.alias_of_str if svc.alias_of else "-" service['status'] = svc.status service['arch'] = svc.arch_str service['path'] = svc.image_path output_list.append(service) return sorted(output_list, key=itemgetter('name')) def main(): '''Main listservices method''' # Configure script logger to output to stderr so logging gets stored # in apache error_log logging.basicConfig(stream=sys.stderr, level=logging.INFO, format="%(message)s") logging.getLogger(SCRIPT_LOGGER_NAME) # Ensure default handlers created are at the level we want here. for handler in logging.getLogger().handlers: handler.setLevel(logging.INFO) print simplejson.dumps(get_services_list()) if __name__ == "__main__": print "Content-Type: text/json\n" # Ensure we always make a valid response by catching # any exceptions that occur try: main() except: pass