<s> """<STR_LIT>""" <EOL> import sys <EOL> import json <EOL> import logging <EOL> import urlparse <EOL> import jsonpatch <EOL> from ilorest import AuthMethod , ilorest_logger , redfish_client <EOL> from ilorest . rest . v1_helper import ServerDownOrUnreachableError <EOL> LOGGERFILE = "<STR_LIT>" <EOL> LOGGERFORMAT = "<STR_LIT>" <EOL> LOGGER = ilorest_logger ( LOGGERFILE , LOGGERFORMAT , logging . INFO ) <EOL> LOGGER . info ( "<STR_LIT>" ) <EOL> def ex1_get_resource_directory ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" + "<STR_LIT:\n>" ) <EOL> response = redfishobj . redfish_get ( "<STR_LIT>" ) <EOL> resources = { } <EOL> if response . status == <NUM_LIT:200> : <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" + "<STR_LIT:\n>" ) <EOL> resources [ "<STR_LIT>" ] = response . dict [ "<STR_LIT>" ] <EOL> return resources <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" + "<STR_LIT:\n>" ) <EOL> def ex2_get_base_registry ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" + "<STR_LIT:\n>" ) <EOL> response = redfishobj . redfish_get ( "<STR_LIT>" ) <EOL> messages = { } <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> if not [ x for x in [ "<STR_LIT>" , "<STR_LIT>" ] if x in entry [ "<STR_LIT>" ] ] : <EOL> continue <EOL> else : <EOL> registry = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> for location in registry . dict [ "<STR_LIT>" ] : <EOL> reg_resp = redfishobj . redfish_get ( location [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if reg_resp . status == <NUM_LIT:200> : <EOL> sys . stdout . write ( "<STR_LIT>" + reg_resp . dict [ "<STR_LIT>" ] + "<STR_LIT>" + location [ "<STR_LIT>" ] [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> messages [ reg_resp . dict [ "<STR_LIT>" ] ] = reg_resp . dict [ "<STR_LIT>" ] <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT:\t>" + reg_resp . dict [ "<STR_LIT>" ] + "<STR_LIT>" + location [ "<STR_LIT>" ] [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> return messages <EOL> def ex3_change_bios_setting ( redfishobj , bios_property , property_value , bios_password = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { bios_property : property_value } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body , optionalpassword = bios_password ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex4_reset_server ( redfishobj , bios_password = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = dict ( ) <EOL> body [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> body [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> response = redfishobj . redfish_post ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex5_enable_secure_boot ( redfishobj , secure_boot_enable , bios_password = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { "<STR_LIT>" : secure_boot_enable } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body , optionalpassword = bios_password ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex6_bios_revert_default ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { "<STR_LIT>" : "<STR_LIT:default>" } <EOL> response = redfishobj . redfish_put ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex7_change_boot_order ( redfishobj , bios_password = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> bootorder = response . dict [ "<STR_LIT>" ] <EOL> body = dict ( ) <EOL> body [ "<STR_LIT>" ] = bootorder <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body , optionalpassword = bios_password ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex8_change_temporary_boot_order ( redfishobj , boottarget , bios_password = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> bootoptions = response . dict [ "<STR_LIT>" ] <EOL> body = dict ( ) <EOL> body [ "<STR_LIT>" ] = dict ( ) <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] = boottarget <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body , optionalpassword = bios_password ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex9_find_ilo_mac_address ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> tmp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> response = redfishobj . redfish_get ( tmp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> ethernet = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" not in ethernet . dict : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT:\t>" + ethernet . dict [ "<STR_LIT:Name>" ] + "<STR_LIT>" + ethernet . dict [ "<STR_LIT>" ] + "<STR_LIT>" + ethernet . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] + "<STR_LIT>" ) <EOL> def ex10_add_ilo_user_account ( redfishobj , new_ilo_loginname , new_ilo_username , new_ilo_password , irc = None , cfg = None , virtual_media = None , usercfg = None , vpr = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> rsp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> body = { "<STR_LIT>" : new_ilo_loginname , "<STR_LIT>" : new_ilo_password , "<STR_LIT>" : { } } <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] = { } <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = new_ilo_username <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = { } <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = irc <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = cfg <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = virtual_media <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = usercfg <EOL> body [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] = vpr <EOL> newrsp = redfishobj . redfish_post ( rsp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( newrsp ) <EOL> def ex11_modify_ilo_user_account ( redfishobj , ilo_login_name_to_modify , new_ilo_loginname , new_ilo_username , new_ilo_password , irc = None , cfg = None , virtual_media = None , usercfg = None , vpr = None ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> rsp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> accounts = redfishobj . redfish_get ( rsp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in accounts . dict [ "<STR_LIT>" ] : <EOL> account = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if account . dict [ "<STR_LIT>" ] == ilo_login_name_to_modify : <EOL> body = { } <EOL> body_oemhp = { } <EOL> body_oemhp_privs = { } <EOL> if new_ilo_password : <EOL> body [ "<STR_LIT>" ] = new_ilo_password <EOL> if new_ilo_loginname : <EOL> body [ "<STR_LIT>" ] = new_ilo_loginname <EOL> if new_ilo_username : <EOL> body_oemhp [ "<STR_LIT>" ] = new_ilo_username <EOL> if irc != None : <EOL> body_oemhp_privs [ "<STR_LIT>" ] = irc <EOL> if virtual_media != None : <EOL> body_oemhp_privs [ "<STR_LIT>" ] = virtual_media <EOL> if cfg != None : <EOL> body_oemhp_privs [ "<STR_LIT>" ] = cfg <EOL> if usercfg != None : <EOL> body_oemhp_privs [ "<STR_LIT>" ] = usercfg <EOL> if vpr != None : <EOL> body_oemhp_privs [ "<STR_LIT>" ] = vpr <EOL> if len ( body_oemhp_privs ) : <EOL> body_oemhp [ "<STR_LIT>" ] = body_oemhp_privs <EOL> if len ( body_oemhp ) : <EOL> body [ "<STR_LIT>" ] = { "<STR_LIT>" : body_oemhp } <EOL> newrsp = redfishobj . redfish_patch ( entry [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( newrsp ) <EOL> return <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> def ex12_remove_ilo_account ( redfishobj , ilo_loginname_to_remove ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> accounts = redfishobj . redfish_get ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in accounts . dict [ "<STR_LIT>" ] : <EOL> account = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if account . dict [ "<STR_LIT>" ] == ilo_loginname_to_remove : <EOL> newrsp = redfishobj . redfish_delete ( entry [ "<STR_LIT>" ] ) <EOL> redfishobj . error_handler ( newrsp ) <EOL> return <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> def ex13_dump_ilo_nic ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> rsp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> response = redfishobj . redfish_get ( rsp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> nic = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> sys . stdout . write ( "<STR_LIT:\t>" + nic . dict [ "<STR_LIT:Name>" ] + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" not in nic . dict : <EOL> sys . stderr . write ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( nic . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( nic . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if not "<STR_LIT>" in nic . dict : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( nic . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( nic . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" not in nic . dict : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( nic . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> for addr in nic . dict [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + addr [ "<STR_LIT>" ] <EOL> + "<STR_LIT>" + addr [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" not in nic . dict : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> else : <EOL> for addr in nic . dict [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + addr [ "<STR_LIT>" ] <EOL> + "<STR_LIT>" + addr [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> def ex14_sessions ( redfishobj , login_account , login_password ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> new_session = { "<STR_LIT>" : login_account , "<STR_LIT>" : login_password } <EOL> response = redfishobj . redfish_post ( "<STR_LIT>" , new_session ) <EOL> redfishobj . error_handler ( response ) <EOL> if response . status == <NUM_LIT> : <EOL> session_uri = response . getheader ( "<STR_LIT:location>" ) <EOL> session_uri = urlparse . urlparse ( session_uri ) <EOL> sys . stdout . write ( "<STR_LIT>" + session_uri . path + "<STR_LIT>" ) <EOL> x_auth_token = response . getheader ( "<STR_LIT>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + x_auth_token + "<STR_LIT>" ) <EOL> sessresp = redfishobj . redfish_delete ( session_uri . path ) <EOL> redfishobj . error_handler ( sessresp ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> def ex15_set_uid_light ( redfishobj , uid ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = dict ( ) <EOL> if uid : <EOL> body [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> else : <EOL> body [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex16_computer_details ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict : <EOL> sys . stdout . write ( "<STR_LIT>" + <EOL> str ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> if "<STR_LIT>" in response . dict : <EOL> sys . stdout . write ( "<STR_LIT>" + response . dict [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + response . dict [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + <EOL> str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" not in response . dict or "<STR_LIT>" not in response . dict [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict : <EOL> if "<STR_LIT>" in response . dict [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict [ "<STR_LIT>" ] : <EOL> for mac in response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( mac ) + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" + response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> if "<STR_LIT>" in response . dict [ "<STR_LIT>" ] : <EOL> for ip_address in response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> if ip_address : <EOL> sys . stdout . write ( "<STR_LIT>" + str ( ip_address ) + "<STR_LIT:\n>" ) <EOL> def ex17_mount_virtual_media_iso ( redfishobj , iso_url , boot_on_next_server_reset ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> rsp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> rsp = redfishobj . redfish_get ( rsp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for vmlink in rsp . dict [ "<STR_LIT>" ] : <EOL> response = redfishobj . redfish_get ( vmlink [ "<STR_LIT>" ] ) <EOL> if response . status == <NUM_LIT:200> and "<STR_LIT>" in response . dict [ "<STR_LIT>" ] : <EOL> body = { "<STR_LIT>" : iso_url } <EOL> if ( iso_url is not None and boot_on_next_server_reset is not None ) : <EOL> body [ "<STR_LIT>" ] = { "<STR_LIT>" : { "<STR_LIT>" : boot_on_next_server_reset } } <EOL> response = redfishobj . redfish_patch ( vmlink [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> elif response . status != <NUM_LIT:200> : <EOL> redfishobj . error_handler ( response ) <EOL> def ex18_set_server_asset_tag ( redfishobj , asset_tag ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { "<STR_LIT>" : asset_tag } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex19_reset_ilo ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { "<STR_LIT>" : "<STR_LIT>" } <EOL> response = redfishobj . redfish_post ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex20_get_ilo_nic ( redfishobj , get_active ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> tmp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> response = redfishobj . redfish_get ( tmp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> nic = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if get_active and nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> sys . stdout . write ( "<STR_LIT>" + entry [ "<STR_LIT>" ] + "<STR_LIT>" + json . dumps ( nic . dict ) + "<STR_LIT:\n>" ) <EOL> elif get_active == False and nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> sys . stdout . write ( "<STR_LIT>" + entry [ "<STR_LIT>" ] + "<STR_LIT>" + json . dumps ( nic . dict ) + "<STR_LIT:\n>" ) <EOL> def ex21_set_active_ilo_nic ( redfishobj , shared_nic ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> selected_nic_uri = None <EOL> for instance in instances : <EOL> tmp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> response = redfishobj . redfish_get ( tmp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> nic = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> try : <EOL> if ( nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] == True and shared_nic == True ) : <EOL> selected_nic_uri = nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> break <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> if ( nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] == True and shared_nic == True ) : <EOL> selected_nic_uri = nic . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> break <EOL> except KeyError : <EOL> pass <EOL> if not shared_nic : <EOL> selected_nic_uri = entry [ "<STR_LIT>" ] <EOL> break <EOL> elif not selected_nic_uri : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> break <EOL> if selected_nic_uri : <EOL> body = { "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : True } } } <EOL> response = redfishobj . redfish_patch ( selected_nic_uri , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex22_dump_iml ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> if instance [ "<STR_LIT>" ] . endswith ( "<STR_LIT>" ) : <EOL> tmp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> rsp = redfishobj . redfish_get ( tmp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in rsp . dict [ "<STR_LIT>" ] : <EOL> response = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> sys . stdout . write ( response . dict [ "<STR_LIT>" ] + "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" + response . dict [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> def ex23_dump_ilo_event_log ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> if instance [ "<STR_LIT>" ] . endswith ( "<STR_LIT>" ) : <EOL> tmp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> rsp = redfishobj . redfish_get ( tmp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> for entry in rsp . dict [ "<STR_LIT>" ] : <EOL> response = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> sys . stdout . write ( response . dict [ "<STR_LIT>" ] + "<STR_LIT:\n>" ) <EOL> def ex24_clear_iml ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> if instance [ "<STR_LIT>" ] . endswith ( "<STR_LIT>" ) : <EOL> body = { "<STR_LIT>" : "<STR_LIT>" } <EOL> response = redfishobj . redfish_post ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex25_clear_ilo_event_log ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> if instance [ "<STR_LIT>" ] . endswith ( "<STR_LIT>" ) : <EOL> body = { "<STR_LIT>" : "<STR_LIT>" } <EOL> response = redfishobj . redfish_post ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex26_configure_snmp ( redfishobj , snmp_mode , snmp_alerts ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> body = { "<STR_LIT>" : snmp_mode , "<STR_LIT>" : snmp_alerts } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex27_get_schema ( redfishobj , schema_prefix ) : <EOL> sys . stdout . write ( "<STR_LIT>" + schema_prefix + "<STR_LIT:\n>" ) <EOL> response = redfishobj . redfish_get ( "<STR_LIT>" ) <EOL> for entry in response . dict [ "<STR_LIT>" ] : <EOL> schema = redfishobj . redfish_get ( entry [ "<STR_LIT>" ] ) <EOL> if schema . dict [ "<STR_LIT>" ] . startswith ( schema_prefix ) : <EOL> for location in schema . dict [ "<STR_LIT>" ] : <EOL> extref_uri = location [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> response = redfishobj . redfish_get ( extref_uri ) <EOL> if response . status == <NUM_LIT:200> : <EOL> sys . stdout . write ( "<STR_LIT>" + schema_prefix + "<STR_LIT>" + extref_uri + "<STR_LIT:\n>" ) <EOL> return <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT:\t>" + schema_prefix + "<STR_LIT>" + extref_uri + "<STR_LIT:\n>" ) <EOL> return <EOL> sys . stderr . write ( "<STR_LIT>" + schema_prefix + "<STR_LIT>" ) <EOL> def ex28_set_ilo_timezone ( redfishobj , olson_timezone ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> for timezone in response . dict [ "<STR_LIT>" ] : <EOL> if timezone [ "<STR_LIT:Name>" ] . startswith ( olson_timezone ) : <EOL> body = { "<STR_LIT>" : { "<STR_LIT>" : timezone [ "<STR_LIT>" ] } } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex29_set_ilo_ntp_servers ( redfishobj , ntp_servers ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> sys . stdout . write ( "<STR_LIT>" + <EOL> json . dumps ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> sys . stdout . write ( "<STR_LIT>" + <EOL> json . dumps ( response . dict [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> body = { "<STR_LIT>" : ntp_servers } <EOL> response = redfishobj . redfish_patch ( instance [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> def ex30_get_powermetrics_average ( redfishobj ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> response = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" not in response . dict or "<STR_LIT>" not in response . dict [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] or "<STR_LIT>" not in response . dict [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] : <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> else : <EOL> sys . stdout . write ( "<STR_LIT:\t>" + "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" + str ( response . dict [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> def ex31_set_license_key ( redfishobj , iLO_Key ) : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> instances = redfishobj . search_for_type ( "<STR_LIT>" ) <EOL> for instance in instances : <EOL> rsp = redfishobj . redfish_get ( instance [ "<STR_LIT>" ] ) <EOL> body = dict ( ) <EOL> body [ "<STR_LIT>" ] = iLO_Key <EOL> response = redfishobj . redfish_post ( rsp . dict [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] , body ) <EOL> redfishobj . error_handler ( response ) <EOL> class RedfishObject ( object ) : <EOL> def __init__ ( self , host , login_account , login_password ) : <EOL> try : <EOL> self . redfish_client = redfish_client ( base_url = host , username = login_account , password = login_password , default_prefix = "<STR_LIT>" ) <EOL> except : <EOL> raise <EOL> self . redfish_client . login ( auth = AuthMethod . SESSION ) <EOL> self . SYSTEMS_RESOURCES = ex1_get_resource_directory ( self ) <EOL> self . MESSAGE_REGISTRIES = ex2_get_base_registry ( self ) <EOL> def __del__ ( self ) : <EOL> try : <EOL> self . redfish_client . logout ( ) <EOL> except AttributeError , excp : <EOL> pass <EOL> def search_for_type ( self , type ) : <EOL> instances = [ ] <EOL> for item in self . SYSTEMS_RESOURCES [ "<STR_LIT>" ] : <EOL> foundsettings = False <EOL> if "<STR_LIT>" in item and type . lower ( ) in item [ "<STR_LIT>" ] . lower ( ) : <EOL> for entry in self . SYSTEMS_RESOURCES [ "<STR_LIT>" ] : <EOL> if ( item [ "<STR_LIT>" ] + "<STR_LIT>" ) . lower ( ) == ( entry [ "<STR_LIT>" ] ) . lower ( ) : <EOL> foundsettings = True <EOL> if not foundsettings : <EOL> instances . append ( item ) <EOL> if not instances : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" % type ) <EOL> return instances <EOL> def error_handler ( self , response ) : <EOL> if not self . MESSAGE_REGISTRIES : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> try : <EOL> message = json . loads ( response . text ) <EOL> newmessage = message [ "<STR_LIT:error>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] . split ( "<STR_LIT:.>" ) <EOL> except : <EOL> sys . stdout . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> return <EOL> for err_mesg in self . MESSAGE_REGISTRIES : <EOL> if err_mesg != newmessage [ <NUM_LIT:0> ] : <EOL> continue <EOL> else : <EOL> for err_entry in self . MESSAGE_REGISTRIES [ err_mesg ] : <EOL> if err_entry == newmessage [ <NUM_LIT:3> ] : <EOL> sys . stdout . write ( "<STR_LIT>" % ( message [ "<STR_LIT:error>" ] [ "<STR_LIT>" ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , self . MESSAGE_REGISTRIES [ err_mesg ] [ err_entry ] [ "<STR_LIT>" ] ) ) <EOL> def redfish_get ( self , suburi ) : <EOL> """<STR_LIT>""" <EOL> return self . redfish_client . get ( path = suburi ) <EOL> def redfish_patch ( self , suburi , request_body , optionalpassword = None ) : <EOL> """<STR_LIT>""" <EOL> sys . stdout . write ( "<STR_LIT>" + str ( request_body ) + "<STR_LIT>" + suburi + "<STR_LIT:\n>" ) <EOL> response = self . redfish_client . patch ( path = suburi , body = request_body , optionalpassword = optionalpassword ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . status ) + "<STR_LIT:\n>" ) <EOL> return response <EOL> def redfish_put ( self , suburi , request_body , optionalpassword = None ) : <EOL> """<STR_LIT>""" <EOL> sys . stdout . write ( "<STR_LIT>" + str ( request_body ) + "<STR_LIT>" + suburi + "<STR_LIT:\n>" ) <EOL> response = self . redfish_client . put ( path = suburi , body = request_body , optionalpassword = optionalpassword ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . status ) + "<STR_LIT:\n>" ) <EOL> return response <EOL> def redfish_post ( self , suburi , request_body ) : <EOL> """<STR_LIT>""" <EOL> sys . stdout . write ( "<STR_LIT>" + str ( request_body ) + "<STR_LIT>" + suburi + "<STR_LIT:\n>" ) <EOL> response = self . redfish_client . post ( path = suburi , body = request_body ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . status ) + "<STR_LIT:\n>" ) <EOL> return response <EOL> def redfish_delete ( self , suburi ) : <EOL> """<STR_LIT>""" <EOL> sys . stdout . write ( "<STR_LIT>" + suburi + "<STR_LIT:\n>" ) <EOL> response = self . redfish_client . delete ( path = suburi ) <EOL> sys . stdout . write ( "<STR_LIT>" + str ( response . status ) + "<STR_LIT:\n>" ) <EOL> return response <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> iLO_host = "<STR_LIT>" <EOL> login_account = "<STR_LIT>" <EOL> login_password = "<STR_LIT:password>" <EOL> try : <EOL> REDFISH_OBJ = RedfishObject ( iLO_host , login_account , login_password ) <EOL> except ServerDownOrUnreachableError , excp : <EOL> sys . stderr . write ( "<STR_LIT>" "<STR_LIT>" ) <EOL> sys . exit ( ) <EOL> except Exception , excp : <EOL> raise excp </s>
