-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredfish_cmd.py
89 lines (72 loc) · 2.04 KB
/
redfish_cmd.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
86
87
88
89
#!/usr/bin/env python
r"""
Command line tool to process redfish related operations.
"""
import argparse
from redfish_connect import *
from redfish_resource_model_crawler import *
parser = argparse.ArgumentParser(
usage='%(prog)s [OPTIONS]',
description='Process redfish request.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prefix_chars='-+')
parser.add_argument(
'--target_ip',
help='BMC target IP.'
)
parser.add_argument(
'--username',
default='root',
help='BMC target user name.'
)
parser.add_argument(
'--password',
default='myPassword',
help='BMC target password.'
)
parser.add_argument(
'--request',
help='GET, PUT, POST, PATCH, DELETE.'
)
parser.add_argument(
'--url',
help='URL path /redfish/v1/<meta-data>'
)
parser.add_argument(
'--op',
help='list, enumerate RESTful like'
)
args = parser.parse_args()
def main():
r"""
Command line tool entry point main() function.
"""
print ("IP: %s" % (args.target_ip))
con = redfish_connect(args.target_ip, args.username, args.password)
if args.request == "GET":
resp = con.get_method(args.url)
print json.dumps(resp, sort_keys=True, indent=4)
# Do the RESTful list.
if args.op=="list":
list_path = '/redfish/v1/' + args.url + '/list'
print("\n%s\n" % list_path)
resp = con.get_method(args.url)
list_resp = get_url_list(resp)
print('\n'.join(map(str, list_resp)))
# Do the RESTful enumerate.
if args.op=="enumerate":
list_path = '/redfish/v1/' + args.url + '/enumerate'
print("\n%s\n" % list_path)
resp = con.get_method(args.url)
list_resp = get_url_list(resp)
for enum in list_resp:
print("\n%s" % enum)
try:
resp = con.get_method(enum.replace("/redfish/v1/",""))
print json.dumps(resp, sort_keys=True, indent=4)
except:
# pass and continue with next resource.
continue
# Main
if not main():
exit(1)