#!/usr/bin/env python

# Copyright C 2002-2008 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 sys
import os
import getopt
import isi.sys.update.util as util

PROGNAME = os.path.basename(sys.argv[0])
REVISION = '$Revision: 1 $'

forceresume = False

def error(str):
    print >> sys.stderr, PROGNAME + ':', str
    sys.exit(1)

def get_options():
    global forceresume
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'hf',
            ['help', 'force'])
        for o, a in opts:
            if o in ['-h', '--help']:
                usage(0)
            elif o in ['-f', '--force']:
                forceresume = True
            else:
                usage(1)

    except getopt.GetoptError, e:
        error(str(e.msg))
        usage(1)

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

Check to see if this node is in the SmartConnect auto suspend list.
If it is, and we're not in the middle of a rolling update, remove it
from the list.

Options:
  -h                  Print this message and exit.
  -f                  Force auto resume even if we are mid-update
""" % PROGNAME)
    sys.exit(exitCode)

def version():
    print '%s version: %s' % (PROGNAME, REVISION)
    sys.exit(0)

if __name__ == "__main__":
    if get_options():
        usage(1)
    drainer = util.Drainer()
    drainer.auto_resume_node(force=forceresume)
