-
Notifications
You must be signed in to change notification settings - Fork 5
/
redfishAPI.py
85 lines (67 loc) · 3.04 KB
/
redfishAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#
# Do NOT modify or remove this copyright and license
#
# Copyright (c) 2019 Seagate Technology LLC and/or its Affiliates, All Rights Reserved
#
# This software is subject to the terms of the MIT License. If a copy of the license was
# not distributed with this file, you can obtain one at https://opensource.org/licenses/MIT.
#
# ******************************************************************************************
#
# redfishAPI.py - Module to run commands using the Systems Redfish API.
#
# ******************************************************************************************
#
from core.label import Label
from core.redfishCommand import RedfishCommand
from core.redfishConfig import RedfishConfig
from core.redfishScript import RedfishScript
from core.redfishInteractive import RedfishInteractive
from version import __version__
import argparse
import config
import sys
################################################################################
# main()
################################################################################
if __name__ == '__main__':
redfishCLIEpilog = '''Examples:
>> Run Redfish API commands interactively.
python redfishAPI.py
>> Run a Redfish API script file. The text script file can be a series of program configuration and API commands.
python redfishAPI.py -s <scriptfile>
>> Run a Redfish API script file with full debugging.
python redfishAPI.py -s <scriptfile> -t 6
'''
print('')
print('-' * 80)
print('[{}] Redfish API'.format(__version__))
print('-' * 80)
returncode = 0
parser = argparse.ArgumentParser(
description='Run the Seagate Systems Redfish API command processor.',
epilog=redfishCLIEpilog,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-c', '--config', help='Specify the Redfish API JSON configuration file.')
parser.add_argument('-s', '--scriptfile', help='Specify the Redfish API script file.')
parser.add_argument('-t', '--tracelevel', help='Set the trace level (4, 5, 6, or 7) INFO=4, VERBOSE=5, DEBUG=5, TRACE=6', nargs='?', const=1, type=int)
args = parser.parse_args()
# Load configuration settings, which can be overwritten at the command line or in a script file
redfishConfig = RedfishConfig(config.defaultConfigFile if args.config == None else args.config)
if (args.tracelevel != None):
redfishConfig.update('trace', args.tracelevel)
if (args.scriptfile == None):
# Run interactive mode
ri = RedfishInteractive()
ri.execute(redfishConfig)
else:
# Run script mode
returncode = RedfishScript.execute_script(redfishConfig, args.scriptfile)
# Before existing, stop the listener service if running
if redfishConfig.listener != None:
redfishConfig.listener.shutdown()
# Before existing, delete any current active session
sessionId = Label.decode(config.sessionIdVariable)
if sessionId is not None:
RedfishCommand.execute(redfishConfig, 'delete sessions ' + sessionId)
sys.exit(returncode)