def main(): argument_spec = dict(credentials=dict(type="dict", options=dict( username=dict(type="str"), base_url=dict(type="str"), password=dict(type="str", no_log=True))), port=dict(type="int", default=623), enabled=dict(type="bool")) module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) REDFISHOBJ = redfish.RedfishClient(**module.params['credentials']) REDFISHOBJ.login() networkservice = REDFISHOBJ.get("/rest/v1/managers/1/NetworkService") ipmiservice = networkservice.obj.IPMI changed = ipmiservice.Port != module.params[ 'port'] or ipmiservice.ProtocolEnabled != module.params['enabled'] result = {'changed': changed} if not module.check_mode: REDFISHOBJ.patch( "/rest/v1/managers/1/NetworkService", { "IPMI": { "Port": module.params['port'], "ProtocolEnabled": module.params['enabled'] } }) module.exit_json(**result)
def connect_to_ilo(system_url, login_account, login_password): try: redfish_obj = redfish.RedfishClient(base_url=system_url, username=login_account, password=login_password) redfish_obj.login(auth="basic") except ServerDownOrUnreachableError: sys.stderr.write( "ERROR: server not reachable or does not support RedFish.\n") sys.exit() return redfish_obj
def login(un, pw, url): """ Login to Redfish API un: (str) User name pw: (str) User password url: (str) HTTPS RedFish API URL Return: Redfish object """ try: rfo = redfish.RedfishClient(base_url=url, username=un, password=pw) rfo.login() return rfo except ServerDownOrUnreachableError as excp: raise Exception( "ERROR: server not reachable or doesn't support RedFish.") except Exception as excp: raise excp
import sys import redfish # When running on the server locally use the following commented values # HOST = "blobstore://." # LOGIN_ACCOUNT = "None" # LOGIN_PASSWORD = "******" # When running remotely connect using the iLO address, iLO account name, # and password to send https requests SYSTEM_URL = "https://10.0.0.100" LOGIN_ACCOUNT = "admin" LOGIN_PASSWORD = "******" ## Create a REDFISH object REDFISH_OBJ = redfish.RedfishClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT,\ password=LOGIN_PASSWORD) # Login into the server and create a session REDFISH_OBJ.login() # Do a GET on a given path RESPONSE = REDFISH_OBJ.get("/redfish/v1/systems/1") # Print out the response sys.stdout.write("%s\n" % RESPONSE) # Logout of the current session REDFISH_OBJ.logout()
# -*- coding: utf-8 -*- import sys import redfish # When running on the server locally use the following commented values # iLO_host = "blobstore://." # LOGIN_ACCOUNT = "None" # LOGIN_PASSWORD = "******" # When running remotely connect using the iLO address, iLO account name, # and password to send https requests iLO_host = "https://10.0.0.100" login_account = "admin" login_password = "******" ## Create a REDFISH object REDFISH_OBJ = redfish.RedfishClient(base_url=iLO_host,username=login_account, \ password=login_password) # Login into the server and create a session REDFISH_OBJ.login() # Do a GET on a given path response = REDFISH_OBJ.get("/redfish/v1/systems/1") # Print out the response sys.stdout.write("%s\n" % response) # Logout of the current session REDFISH_OBJ.logout()
from rf.config import * import redfish # from rf._redfishobject import RedfishObject # from redfish import RedfishClient # from redfish.rest.v1 import ServerDownOrUnreachableError import dpath.util # Set configuration variables iLO_https_url = iLO_https_url iLO_account = iLO_account iLO_password = iLO_password # Create a REDFISH object try: rf = redfish.RedfishClient(base_url=iLO_https_url, username=iLO_account, password=iLO_password) rf.login() except ServerDownOrUnreachableError as excp: raise Exception( "ERROR: server not reachable or doesn't support RedFish.\n") except Exception as excp: raise excp # Helper function to traverse API def drill(path, keys, indent=2, output=True): urls = ['/'] terms = path.split('*') if terms[-1] == '':