#!/usr/bin/env python3
###
# (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
###
import sys
if sys.version_info < (3, 4):
    raise Exception("Must use Python 3.4 or later")

import hpOneView as hpov
from pprint import pprint


def acceptEULA(con):
    # See if we need to accept the EULA before we try to log in
    con.get_eula_status()
    try:
        if con.get_eula_status() is True:
            print("EULA display needed")
            con.set_eula('no')
    except Exception as e:
        print('EXCEPTION:')
        print(e)


def login(con, credential):
    # Login with givin credentials
    try:
        con.login(credential)
    except:
        print('Login failed')


def shutdown(sts, mode):
    print(mode + 'ing Appliance')
    ret = sts.shutdown(mode)
    pprint(ret)


def main():
    parser = argparse.ArgumentParser(add_help=True, description='Usage')
    parser.add_argument('-a', '--appliance', dest='host', required=True,
                        help='HP OneView Appliance hostname or IP')
    parser.add_argument('-u', '--user', dest='user', required=False,
                        default='Administrator', help='HP OneView Username')
    parser.add_argument('-p', '--pass', dest='passwd', required=False,
                        help='HP OneView Password')
    parser.add_argument('-c', '--certificate', dest='cert', required=False,
                        help='Trusted SSL Certificate Bundle in PEM '
                        '(Base64 Encoded DER) Format')
    parser.add_argument('-y', dest='proxy', required=False,
                        help='Proxy (host:port format')
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument('-b', dest='reboot', action='store_true',
                       help='Shutdown and reboot the appliance')
    group.add_argument('-s', dest='halt', action='store_true',
                       help='Shutdown and hatl the appliance')

    args = parser.parse_args()
    credential = {'userName': args.user, 'password': args.passwd}

    con = hpov.connection(args.host)
    sts = hpov.settings(con)

    if args.proxy:
        con.set_proxy(args.proxy.split(':')[0], args.proxy.split(':')[1])
    if args.cert:
        con.set_trusted_ssl_bundle(args.cert)

    login(con, credential)
    acceptEULA(con)

    if args.reboot:
        shutdown(sts, 'REBOOT')
    elif args.halt:
        shutdown(sts, 'HALT')


if __name__ == '__main__':
    import sys
    import argparse
    sys.exit(main())

# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

@@ -1918,27 +1918,195 @@
 rue,
- description='
+%0A                        formatter_class=argparse.RawTextHelpFormatter,%0A                                     description='''%0A    Shutdown or Reboot the HP OneView Appliance%0A%0A    
 Usage
+: ''
 ')%0A 
@@ -2137,23 +2137,8 @@
 -a',
- '--appliance',
  des
@@ -2184,32 +2184,39 @@
           help='
+''%0A    
 HP OneView Appli
@@ -2234,16 +2234,26 @@
 me or IP
+ address''
 ')%0A    p
@@ -2280,18 +2280,8 @@
 -u',
- '--user',
  des
@@ -2354,23 +2354,54 @@
 trator',
- help='
+%0A                        help='''%0A    
 HP OneVi
@@ -2412,16 +2412,18 @@
 sername'
+''
 )%0A    pa
@@ -2449,18 +2449,8 @@
 -p',
- '--pass',
  des
@@ -2507,16 +2507,23 @@
   help='
+''%0A    
 HP OneVi
@@ -2534,16 +2534,18 @@
 assword'
+''
 )%0A    pa
@@ -2571,25 +2571,8 @@
 -c',
- '--certificate',
  des
@@ -2627,16 +2627,23 @@
   help='
+''%0A    
 Trusted 
@@ -2676,35 +2676,8 @@
 PEM 
-'%0A                        '
 (Bas
@@ -2696,24 +2696,26 @@
 DER) Format'
+''
 )%0A    parser
@@ -2794,16 +2794,23 @@
   help='
+''%0A    
 Proxy (h
@@ -2825,16 +2825,18 @@
  format'
+''
 )%0A    gr
@@ -2917,17 +2917,17 @@
 ument('-
-b
+r
 ', dest=
@@ -2978,32 +2978,39 @@
           help='
+''%0A    
 Shutdown and reb
@@ -3006,16 +3006,24 @@
 own and 
+restart/
 reboot t
@@ -3031,24 +3031,26 @@
 e appliance'
+''
 )%0A    group.
@@ -3131,16 +3131,23 @@
   help='
+''%0A    
 Shutdown
@@ -3157,10 +3157,10 @@
 d ha
-t
 l
+t
  the
@@ -3170,16 +3170,18 @@
 pliance'
+''
 )%0A%0A    a

Update shutdown.py to use raWTextHelpFormatter and to use the -r argument for reboot