-
Notifications
You must be signed in to change notification settings - Fork 180
/
quickstart_rmc.py
55 lines (42 loc) · 1.56 KB
/
quickstart_rmc.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
# Copyright Notice:
# Copyright 2016-2021 DMTF. All rights reserved.
# License: BSD 3-Clause License. For full text see link:
# https://github.com/DMTF/python-redfish-library/blob/main/LICENSE.md
import os
import sys
import json
import logging
from redfish import redfish_logger
from redfish.ris import RmcApp, JSONEncoder
# Config logger used by Restful library
LOGGERFILE = "RedfishApiExamples.log"
LOGGERFORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOGGER = redfish_logger(LOGGERFILE, LOGGERFORMAT, logging.ERROR)
LOGGER.info("Redfish API examples")
# When running remotely connect using the address, account name,
# and password to send https requests
login_host = "https://192.168.1.100"
login_account = "admin"
login_password = "password"
# Creating RMC object
RMCOBJ = RmcApp([])
# Create cache directory
config_dir = r'C:\DATA\redfish'
RMCOBJ.config.set_cachedir(os.path.join(config_dir, 'cache'))
cachedir = RMCOBJ.config.get_cachedir()
# If current cache exist try to log it out
if os.path.isdir(cachedir):
RMCOBJ.logout
# Login into the server and create a session
RMCOBJ.login(username=login_account, password=login_password, \
base_url=login_host)
# Select ComputerSystems
RMCOBJ.select(['ComputerSystem.'])
# Get selected type
response = RMCOBJ.get()
# Print out the response
for item in response:
sys.stdout.write(json.dumps(item, indent=2, cls=JSONEncoder))
sys.stdout.write('\n')
# Logout of the current session
RMCOBJ.logout()