Skip to content
Merged
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
48 changes: 26 additions & 22 deletions containers/shell-operator-ironic/hooks/create_runbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,36 @@ if [[ $1 == "--config" ]] ; then
}
EOF
else
type=$(jq -r '.[0].type' "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
fi
binding_count=$(jq -r 'length' "${BINDING_CONTEXT_PATH}")
for ((i = 0; i < binding_count; i++)); do
type=$(jq -r ".[$i].type" "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
continue
fi

if [[ $type == "Event" ]] ; then
resource_name=$(jq -r '.[0].object.metadata.name' "${BINDING_CONTEXT_PATH}")
kind=$(jq -r '.[0].object.kind' "${BINDING_CONTEXT_PATH}")
if [[ $type == "Event" ]] ; then
resource_name=$(jq -r ".[$i].object.metadata.name" "${BINDING_CONTEXT_PATH}")
kind=$(jq -r ".[$i].object.kind" "${BINDING_CONTEXT_PATH}")

runbook_name=$(jq -r '.[0].object.spec.runbookName' "${BINDING_CONTEXT_PATH}")
public=$(jq -r '.[0].object.spec.public' "${BINDING_CONTEXT_PATH}")
owner=$(jq -r '.[0].object.spec.owner' "${BINDING_CONTEXT_PATH}")
jq -r '.[0].object.spec.steps' "${BINDING_CONTEXT_PATH}" > /tmp/steps.yaml
runbook_name=$(jq -r ".[$i].object.spec.runbookName" "${BINDING_CONTEXT_PATH}")
public=$(jq -r ".[$i].object.spec.public" "${BINDING_CONTEXT_PATH}")
owner=$(jq -r ".[$i].object.spec.owner" "${BINDING_CONTEXT_PATH}")
jq -r ".[$i].object.spec.steps" "${BINDING_CONTEXT_PATH}" > /tmp/steps.yaml

# Ironic's runbook extra field is essentially a dict of dicts, representing a key values. baremetal cli allows you
# to pass in multiple --extra options, adding any you do pass. We would need to make an initial query to determine
# existing extras, and then sync the differences. This work is probably better suited to a full controller implementation.
# extra=$(jq -r '.spec.extra | [to_entries[] | "--extra \(.key)=\(.value | @json | @sh)"] | join(" ")' ${BINDING_CONTEXT_PATH})
# Ironic's runbook extra field is essentially a dict of dicts, representing a key values. baremetal cli allows you
# to pass in multiple --extra options, adding any you do pass. We would need to make an initial query to determine
# existing extras, and then sync the differences. This work is probably better suited to a full controller implementation.
# extra=$(jq -r '.spec.extra | [to_entries[] | "--extra \(.key)=\(.value | @json | @sh)"] | join(" ")' ${BINDING_CONTEXT_PATH})

command_args=(baremetal runbook create --name "${runbook_name}" --public "${public}" --steps /tmp/steps.yaml)
if [[ -n "${owner}" && "${owner}" != "null" ]]; then
command_args+=(--owner "${owner}")
fi
command_args=(baremetal runbook create --name "${runbook_name}" --public "${public}" --steps /tmp/steps.yaml)
if [[ -n "${owner}" && "${owner}" != "null" ]]; then
command_args+=(--owner "${owner}")
fi

echo "${kind}/${resource_name} created, running: openstack ${command_args[*]}"
echo "${kind}/${resource_name} created, running: openstack ${command_args[*]}"

openstack "${command_args[@]}"
fi
openstack "${command_args[@]}"
fi
done
fi
28 changes: 16 additions & 12 deletions containers/shell-operator-ironic/hooks/delete_runbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@ if [[ $1 == "--config" ]] ; then
}
EOF
else
type=$(jq -r '.[0].type' "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
fi
binding_count=$(jq -r 'length' "${BINDING_CONTEXT_PATH}")
for ((i = 0; i < binding_count; i++)); do
type=$(jq -r ".[$i].type" "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
continue
fi

if [[ $type == "Event" ]] ; then
resource_name=$(jq -r '.[0].object.metadata.name' "${BINDING_CONTEXT_PATH}")
kind=$(jq -r '.[0].object.kind' "${BINDING_CONTEXT_PATH}")
if [[ $type == "Event" ]] ; then
resource_name=$(jq -r ".[$i].object.metadata.name" "${BINDING_CONTEXT_PATH}")
kind=$(jq -r ".[$i].object.kind" "${BINDING_CONTEXT_PATH}")

runbook_name=$(jq -r '.[0].object.spec.runbookName' "${BINDING_CONTEXT_PATH}")
runbook_name=$(jq -r ".[$i].object.spec.runbookName" "${BINDING_CONTEXT_PATH}")

command_args=(baremetal runbook delete "${runbook_name}")
echo "${kind}/${resource_name} deleted, running: openstack ${command_args[*]}"
command_args=(baremetal runbook delete "${runbook_name}")
echo "${kind}/${resource_name} deleted, running: openstack ${command_args[*]}"

openstack "${command_args[@]}"
fi
openstack "${command_args[@]}"
fi
done
fi
49 changes: 26 additions & 23 deletions containers/shell-operator-ironic/hooks/update_runbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,36 @@ if [[ $1 == "--config" ]] ; then
}
EOF
else
type=$(jq -r '.[0].type' "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
fi

if [[ $type == "Event" ]] ; then
resource_name=$(jq -r '.[0].object.metadata.name' "${BINDING_CONTEXT_PATH}")
kind=$(jq -r '.[0].object.kind' "${BINDING_CONTEXT_PATH}")
binding_count=$(jq -r 'length' "${BINDING_CONTEXT_PATH}")
for ((i = 0; i < binding_count; i++)); do
type=$(jq -r ".[$i].type" "${BINDING_CONTEXT_PATH}")
if [[ $type == "Synchronization" ]] ; then
echo "Implement any reconciliation logic needed here."
continue
fi

runbook_name=$(jq -r '.[0].object.spec.runbookName' "${BINDING_CONTEXT_PATH}")
public=$(jq -r '.[0].object.spec.public' "${BINDING_CONTEXT_PATH}")
owner=$(jq -r '.[0].object.spec.owner' "${BINDING_CONTEXT_PATH}")
jq -r '.[0].object.spec.steps' "${BINDING_CONTEXT_PATH}" > /tmp/steps.yaml
if [[ $type == "Event" ]] ; then
resource_name=$(jq -r ".[$i].object.metadata.name" "${BINDING_CONTEXT_PATH}")
kind=$(jq -r ".[$i].object.kind" "${BINDING_CONTEXT_PATH}")

# Ironic's runbook extra field is essentially a dict of dicts, representing a key values. baremetal cli allows you
# to pass in multiple --extra options, adding any you do pass. We would need to make an initial query to determine
# existing extras, and then sync the differences. This work is probably better suited to a full controller implementation.
# extra=$(jq -r '.spec.extra | [to_entries[] | "--extra \(.key)=\(.value | @json | @sh)"] | join(" ")' ${BINDING_CONTEXT_PATH})
runbook_name=$(jq -r ".[$i].object.spec.runbookName" "${BINDING_CONTEXT_PATH}")
public=$(jq -r ".[$i].object.spec.public" "${BINDING_CONTEXT_PATH}")
owner=$(jq -r ".[$i].object.spec.owner" "${BINDING_CONTEXT_PATH}")
jq -r ".[$i].object.spec.steps" "${BINDING_CONTEXT_PATH}" > /tmp/steps.yaml

command_args=(baremetal runbook set "${runbook_name}" --public "${public}" --steps /tmp/steps.yaml)
if [[ -n "${owner}" && "${owner}" != "null" ]]; then
command_args+=(--owner "${owner}")
fi
# Ironic's runbook extra field is essentially a dict of dicts, representing a key values. baremetal cli allows you
# to pass in multiple --extra options, adding any you do pass. We would need to make an initial query to determine
# existing extras, and then sync the differences. This work is probably better suited to a full controller implementation.
# extra=$(jq -r '.spec.extra | [to_entries[] | "--extra \(.key)=\(.value | @json | @sh)"] | join(" ")' ${BINDING_CONTEXT_PATH})

echo "${kind}/${resource_name} updated, running: openstack ${command_args[*]}"
command_args=(baremetal runbook set "${runbook_name}" --public "${public}" --steps /tmp/steps.yaml)
if [[ -n "${owner}" && "${owner}" != "null" ]]; then
command_args+=(--owner "${owner}")
fi

openstack "${command_args[@]}"
echo "${kind}/${resource_name} updated, running: openstack ${command_args[*]}"

fi
openstack "${command_args[@]}"
fi
done
fi
Loading