Skip to content

Instantly share code, notes, and snippets.

@jkilpatr
Created April 25, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkilpatr/1679f8d14f63b880e357e3ef2ced5c5a to your computer and use it in GitHub Desktop.
Save jkilpatr/1679f8d14f63b880e357e3ef2ced5c5a to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script will take any nodes in a manageable state and issue an introspection every 30 seconds
# it will set any nodes that successfully finish introspection and shutdown to available. Otherwise it will
# wait for the timeout to complete and try again on only the nodes that are still manageable.
introspect()
{
for node in `ironic --json node-list | jq -r '.[]| select(.["provision_state"] == "manageable")| .["uuid"]'`; do
openstack baremetal introspection start $node
sleep 30s
done
manageable_count=1
on_count=0
while [ $on_count -eq 0 ] && [ $manageable_count -gt 0 ]; do
manageable_count=$(ironic --json node-list | jq -r '.[]| select(.["provision_state"] == "manageable")| .["uuid"]' | wc -l)
on_count=$(ironic --json node-list|jq -r '.[]| select(.["power_state"] == "power on")| .["uuid"]' | wc -l)
sleep 30
done
set +e
timeout $1 bash -c -- 'source $HOME/stackrc; \
on_count=$(ironic --json node-list|jq -r ".[]| select(.[\"power_state\"] == \"power on\")| .[\"uuid\"]" | wc -l) ; \
while [ $on_count -gt 0 ]; do \
sleep 30s; \
on_count=$(ironic --json node-list|jq -r ".[]| select(.[\"power_state\"] == \"power on\")| .[\"uuid\"]" | wc -l) ; \
done'
set -e
for node in `ironic --json node-list | jq -r '.[]| select(.["power_state"] == "power off")| select(.["provision_state"] == "manageable")|.["uuid"]'`; do
ironic node-set-provision-state $node provide
done
}
introspect 15m
introspect 30m
introspect 60m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment