#! /usr/local/bin/python

# Copyright C 2002-2003 by Isilon Systems, Inc. All rights not expressly
# granted herein are reserved.
# Created in the United States of America.
# 
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Isilon Systems,
# Inc.
# 
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Isilon
# Systems. 
#  
# Isilon and Isilon Systems are registered trademarks of Isilon Systems,
# Inc.  Legion is a trademark of Isilon Systems, Inc.  All other
# trademarks and registered trademarks are the property of their
# respective holders.

import os
import sys
import getopt

from isi.config import hdfs

def usage(exitCode):
    sys.stderr.write('''
Usage: %s [OPTION]...

Options:
  -H, --hadoop-versions		List hadoop versions
  -l, --log-levels			List log levels
  -n, --names				List all rack names
  -S, --hadoop-security		List hadoop security modes
''' % (os.path.basename(sys.argv[0])))
    sys.exit(exitCode)

def keys_iter(it):
    keys = []
    for k in it:
        keys.append(k)
    return keys

def main():
    print_names = False
    print_hadoops = False
    print_loglevels = False
    print_security = False

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'HlnS',
                ['hadoop-versions', 'log-levels', 'names', 'hadoop-security'])
        for o, a in opts:
            print_names = print_names or o in ['-n', '--names']
            print_hadoops = print_hadoops or o in ['-H', '--hadoop-versions']
            print_loglevels = print_loglevels or o in ['-l', '--log-levels']
            print_security = print_security or o in ['-S', '--hadoop-security']

    except getopt.GetoptError:
        usage(1)

    try:
        rack_ips, rack_pools = hdfs.get_raw_rack_info()
    except Exception, e:
        print >> sys.stderr, (str(e))
        sys.exit(1)

    if print_names:
        print "\n".join(keys_iter(rack_ips))

    if print_hadoops:
        print "\n".join(['AUTO', 'CLOUDERA_CDH3', 'APACHE_0_20_205', 'GREENPLUM_HD_1_1', 'APACHE_0_20_203'])

    if print_loglevels:
        print "\n".join(['EMERG', 'ALERT', 'CRIT', 'ERR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG'])

    if print_security:
        print "\n".join(['enforcing', 'permissive'])

if __name__ == '__main__':
    main()
