fuel-library/deployment/puppet/pacemaker_wrappers/templates/ocf_handler.erb
Dmitry Ilyin cd3f8b2cb2 Refactor virtual_ips task
* Use function instead of hardcoded values
* Use ocf_handlers for vrouter and vip manifests
* Add prefix option to pcmk wrapper
* Netmask_to_cidr should always return strings
* Fix naming of interfaces in vrouter OCF

Implements: blueprint templates-for-networking
Related-Blueprint: detach-components-from-controllers

Change-Id: I3527f2d85baac83b209c7af713466b593238555f
2015-08-04 15:57:07 +03:00

130 lines
2.2 KiB
Plaintext

#!/bin/bash
export PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
export OCF_ROOT='<%= @ocf_root_path %>'
export OCF_RA_VERSION_MAJOR='1'
export OCF_RA_VERSION_MINOR='0'
export OCF_RESOURCE_INSTANCE='<%= @primitive_name %>'
# OCF Parameters
<% if @parameters.is_a? Hash -%>
<% @parameters.each do |k,v| -%>
<% v = v.to_s -%>
<% v = v + "'" unless v.end_with? "'" -%>
<% v = "'" + v unless v.start_with? "'" -%>
<%= "export OCF_RESKEY_#{k}=#{v}" %>
<% end -%>
<% end -%>
help() {
cat<<EOF
OCF wrapper for <%= @service_name %> Pacemaker primitive
Usage: <%= @ocf_handler_name %> [-dh] (action)
Options:
-d - Use set -x to debug the shell script
-h - Show this help
Main actions:
* start
* stop
* monitor
* meta-data
* validate-all
Multistate:
* promote
* demote
* notify
Migration:
* migrate_to
* migrate_from
Optional and unused:
* usage
* help
* status
* reload
* restart
* recover
EOF
}
red() {
echo -e "\033[31m${1}\033[0m"
}
green() {
echo -e "\033[32m${1}\033[0m"
}
blue() {
echo -e "\033[34m${1}\033[0m"
}
ec2error() {
case "${1}" in
0) green 'Success' ;;
1) red 'Error: Generic' ;;
2) red 'Error: Arguments' ;;
3) red 'Error: Unimplemented' ;;
4) red 'Error: Permissions' ;;
5) red 'Error: Installation' ;;
6) red 'Error: Configuration' ;;
7) blue 'Not Running' ;;
8) green 'Master Running' ;;
9) red 'Master Failed' ;;
*) red "Unknown" ;;
esac
}
DEBUG='0'
while getopts ':dh' opt; do
case $opt in
d)
DEBUG='1'
;;
h)
help
exit 0
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
help
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
ACTION="${1}"
# set default action to monitor
if [ "${ACTION}" = '' ]; then
ACTION='monitor'
fi
# alias status to monitor
if [ "${ACTION}" = 'status' ]; then
ACTION='monitor'
fi
# view defined OCF parameters
if [ "${ACTION}" = 'params' ]; then
env | grep 'OCF_'
exit 0
fi
if [ "${DEBUG}" = '1' ]; then
bash -x <%= @ocf_script_path %> "${ACTION}"
else
<%= @ocf_script_path %> "${ACTION}"
fi
ec="${?}"
message="$(ec2error ${ec})"
echo "Exit status: ${message} (${ec})"
exit "${ec}"