Skip to content

Instantly share code, notes, and snippets.

@mcornea
Created March 21, 2023 14:07
Show Gist options
  • Save mcornea/2a2ca368cb70fdc455f0508a61ea51ce to your computer and use it in GitHub Desktop.
Save mcornea/2a2ca368cb70fdc455f0508a61ea51ce to your computer and use it in GitHub Desktop.
redfish reboot
import openshift as oc
import redfish
import time
def bmc_hard_reboot(bmc_url, bmc_user, bmc_pass):
bmc_host = bmc_url.split('://')[-1].split('/')[0]
bmc_prefix = '/' + '/'.join(bmc_url.split('://')[-1].split('/')[1:])
headers = {'Content-Type': 'application/json'}
body = {'ResetType': 'ForceRestart'}
REDFISH_OBJ = redfish.redfish_client(base_url='https://'+bmc_host, username=bmc_user,
password=bmc_pass, default_prefix='/redfish/v1/')
REDFISH_OBJ.login(auth="basic")
REDFISH_OBJ.post(bmc_prefix + '/Actions/ComputerSystem.Reset', body=body, headers=headers)
REDFISH_OBJ.logout()
def verify_openshift_service_is_up(timeout=300):
backoff = 5
start_time = time.time()
while time.time() - start_time < timeout:
try:
oc.invoke('status')
print('Node back up')
return True
except oc.OpenShiftPythonException as e:
print(f'OpenShift API is not ready yet.\nTrying again in {backoff} seconds')
time.sleep(backoff)
bmc_hard_reboot(bmc_url='https://192.168.0.1/redfish/v1/Systems/1',
bmc_user='admin',
bmc_pass='password')
verify_openshift_service_is_up()
#curl -s -X POST https://192.168.0.1/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset -d '{"ResetType": "ForceOff"}' -H "Content-Type: application/json" -k -u root:calvin
curl -s -X POST https://192.168.0.1/redfish/v1/Systems/1/Actions/ComputerSystem.Reset -d '{"ResetType": "ForceRestart"}' -H "Content-Type: application/json" -k -u admin:password
i=0; while [[ $i -lt 10 ]]; do oc -n test wait --for condition=Ready=false --timeout=30s pods --all; if [[ $? -eq 0 ]]; then echo "Pods are starting."; break; else echo "Waiting for the node to come back up."; sleep 5; i=$((i+1)); fi; done
oc -n test wait --for condition=Ready --timeout=300s pods --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment