#!/usr/bin/env python

# Copyright C 2008-2012 by Isilon Systems LLC. 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, sys

import isi.hw.bay as bay
import isi.hw.hal as hal
import isi.hw.version as hwver

ISI_VIT_UTIL_CMD = "/usr/bin/isi_hwtools/isi_vitutil "

#
# This utility was created to support the isi_gather_info and isi_hw_bug_info
# commands due to the paradigm shift from a single expander per chassis to 
# multiple expanders per chassis.
#
# This program obtains the number of expanders in a given chassis then 
# iterates through each expander on a chassis executing the "isi_vitutil" 
# command with the options passed.
#
def main(args):
    if len(args) <= 2:
        print "isi_gather_vitutil_info <arg_opts> <chasn> "
        sys.exit(1)
    else:
        opt = args[1] 
        chasn = args[2]
    cmd = ISI_VIT_UTIL_CMD + opt + " " + chasn + " e" 
    chas_num_str = chasn[-1]
    chasnum = int(chas_num_str)
    if chasnum >= hal.getActiveChassisCount():
        print "chassis %d not up or does not exist" % chasnum
        sys.exit(0)
    numexp = hal.getActiveExpanderCount(chasnum) 
    if numexp <= 0:
        print "No SAS expanders found"
        sys.exit(0)
    for exp in range(numexp):
        if exp > 0:
            print "\n"
        tcmd = cmd + "%d" % exp
        os.system(tcmd)
    sys.exit(0)

if __name__ == '__main__':
	main(sys.argv)


