Skip to content

feat: Adds admin scripts to help manage Understack and OpenStack #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions scripts/ironic-error-rekick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

function usage() {
# shellcheck disable=SC2005
echo "$(basename "$0")" >&2
echo "" >&2
echo "Rekicks ironic baremetal nodes in 'error' status" >&2
echo "" >&2
echo "Required environment variables:" >&2
echo "" >&2
echo "OS_CLOUD= OpenStack cloud config to use for ironic baremetal node management (infra)" >&2
echo "" >&2

exit 1
}

# check for inputs and required environment variables
if [[ -z "${OS_CLOUD}" ]]; then
echo "Error: OS_CLOUD environment variable not found."
usage
fi

IFS=$'\n'

# Query the nodes and find the ones in error state which have no instances.
for item in $(openstack baremetal node list -f json | jq -c -r '.[]') ; do
NODE_UUID=$(jq -r '.UUID' <<< "$item");
NODE_STATE=$(jq -r '."Provisioning State"' <<< "$item");
NODE_INSTANCE=$(jq -r '."Instance UUID"' <<< "$item");
if [[ "$NODE_STATE" == "error" && "$NODE_INSTANCE" == "null" ]]; then
NODE_IP=$(openstack baremetal node show "$NODE_UUID" -f json | jq -c -r '.driver_info.redfish_address' | sed 's|https://||g');
echo "NODE: $NODE_UUID ($NODE_IP) is in ERROR state and has no instance on it. Rekicking...";
echo "NODE: $NODE_UUID Setting maintenance mode...";
openstack baremetal node maintenance set "$NODE_UUID"
echo "NODE: $NODE_UUID Deleting from ironic...";
openstack baremetal node delete "$NODE_UUID"
echo "NODE: $NODE_UUID Submitting re-enroll workflow...";
argo -n argo-events submit --from wftmpl/enroll-server --serviceaccount workflow -p ip_address="$NODE_IP"
fi
done
54 changes: 54 additions & 0 deletions scripts/keystone-nautobot-tenant-resync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

function usage() {
# shellcheck disable=SC2005
echo "$(basename "$0")" >&2
echo "" >&2
echo "Resync keystone projects in to nautobot by updating the keystone project's description" >&2
echo "" >&2
echo "Required environment variables:" >&2
echo "" >&2
echo "OS_CLOUD= OpenStack cloud config to use for ironic baremetal node management (infra)" >&2
echo "" >&2

exit 1
}

# check for inputs and required environment variables
if [[ -z "${OS_CLOUD}" ]]; then
echo "Error: OS_CLOUD environment variable not found."
usage
fi

IFS=$'\n'

# We'll append a string `update-${TIMESTAMP}` to help us
# keep track of when the project was last updated.
TIMESTAMP=$(date -u +"%Y%m%d%H%M%S")

# For each keystone project, we want to trigger the keystone->argo workflow->nautobot sync,
# which we can do by updating the description of the project.
for item in $(openstack project list --long --domain default -f json | jq -c -r '.[]') ; do
PROJECT_ID=$(jq -r '.ID' <<< "$item");
PROJECT_NAME=$(jq -r '.Name' <<< "$item");
DESCRIPTION=$(jq -r '.Description' <<< "$item");
NEW_DESCRIPTION="$DESCRIPTION update-$TIMESTAMP"
# Grab the last word of the current description to check if
# it's the update timestamp.
last_word=$(echo "$DESCRIPTION" | awk '{print $NF}')
if [[ $last_word == update-* ]]; then
# The description has suffix update-{timestamp} already.
# This replaces the old update timestamp with the new one.
TMP=$(echo "$DESCRIPTION" | awk '{$NF=""; sub(/[ \t]+$/, ""); print}')
NEW_DESCRIPTION="$TMP update-$TIMESTAMP"
fi
# strip preceding whitespaces if necessary
# shellcheck disable=SC2001
NEW_DESCRIPTION=$(echo "$NEW_DESCRIPTION" | sed 's/^[ \t]*//')

echo "Updating: Project: $PROJECT_NAME ($PROJECT_ID)";
echo "Old description: $DESCRIPTION";
echo "New description: $NEW_DESCRIPTION";
openstack project set --domain default "$PROJECT_ID" --description "$NEW_DESCRIPTION"
echo "---"
done
Loading