-lf-activate-venv --python python3 \
- python-heatclient \
- python-openstackclient
-
-set -eux -o pipefail
-
-mapfile -t os_ports_ts < <(openstack --os-cloud "$os_cloud" port list \
- -f value \
- -c ID \
- -c status \
- -c created_at \
- | grep -E DOWN \
- | awk -F' ' '{print $1 " " $3}')
-
-if [ ${#os_ports_ts[@]} -eq 0 ]; then
- echo "No orphaned ports found."
-else
- cutoff=$(date -d "30 minutes ago" +%s)
- for port_ts in "${os_ports_ts[@]}"; do
- created_at_isots="${port_ts#* }"
- port_uuid="${port_ts% *}"
- echo "checking port uuid: ${port_uuid} with TS: ${created_at_isots}"
- created_at_uxts=$(date -d "${created_at_isots}" +"%s")
- # Clean up ports where created_at > 30 minutes
- if [[ "$created_at_uxts" -gt "$cutoff" ]]; then
- echo "Removing orphaned port $port_uuid created_at ts > 30 minutes."
- openstack --os-cloud "$os_cloud" port delete "$port_uuid"
+set -eu -o pipefail
+
+tmpfile=$(mktemp --suffix -openstack-ports.txt)
+cores=$(nproc --all)
+threads=$((3*cores))
+
+# Set age for deletion/removal
+age="30 minutes ago"
+cutoff=$(date -d "$age" +%s)
+
+_cleanup()
+{
+ uuid=$1
+ created_at=$(openstack --os-cloud "$os_cloud" port show -f value -c created_at "$uuid")
+ if [ "$created_at" == "None" ]; then
+ echo "No value for port creation time; skipping: $uuid"
+ else
+ created_at_uxts=$(date -d "$created_at" +"%s")
+
+ # For debugging only; this outout usually disabled
+ # echo "Port: ${uuid} created at ${created_at} / ${created_at_uxts}"
+
+ # Validate timing values are numeric
+ if [[ "$created_at_uxts" -eq "$created_at_uxts" ]]; then
+ # Clean up ports where created_at > 30 minutes
+ if [[ "$created_at_uxts" -lt "$cutoff" ]]; then
+ echo "Removing orphaned port $uuid created > $age"
+ openstack --os-cloud "$os_cloud" port delete "$uuid"
+ fi
+ else
+ echo "Date variable failed numeric test; deletion not possible"