# Also redirect stderr as we parse the output to use an appropriate exit code
routed_to_instance=$(eval $cmd 2>&1)
if [ $? -ne 0 ]; then
if echo $routed_to_instance | grep -qi "Insufficient Permission" ; then
ocf_exit_reason "Insufficient permissions to get route information"
exit $OCF_ERR_PERM
elif echo $routed_to_instance | grep -qi "Could not fetch resource"; then
ocf_log debug "The route ${OCF_RESKEY_route_name} doesn't exist"
return $OCF_NOT_RUNNING
else
ocf_exit_reason "Error : ${routed_to_instance}"
exit $OCF_ERR_GENERIC
fi
fi
if [ -z "${routed_to_instance}" ]; then
routed_to_instance="<unknown>"
fi
if [ "${routed_to_instance}" != "${gcp_api_url_prefix}/projects/${GCE_INSTANCE_PROJECT}/zones/${GCE_INSTANCE_ZONE}/instances/${GCE_INSTANCE_NAME}" ]; then
ocf_log warn "The floating IP ${OCF_RESKEY_ip} is not routed to this instance (${GCE_INSTANCE_NAME}) but to instance ${routed_to_instance##*/}"
return $OCF_NOT_RUNNING
fi
ocf_log debug "The floating IP ${OCF_RESKEY_ip} is correctly routed to this instance (${GCE_INSTANCE_NAME})"
return $OCF_SUCCESS
}
ip_monitor() {
ocf_log info "IP monitor: checking local network configuration"
cmd="ip address show dev ${OCF_RESKEY_interface} to ${OCF_RESKEY_ip}/32"
ocf_log debug "Executing command: $cmd"
if [ -z "$($cmd)" ]; then
ocf_log warn "The floating IP ${OCF_RESKEY_ip} is not locally configured on this instance (${GCE_INSTANCE_NAME})"
return $OCF_NOT_RUNNING
fi
ocf_log debug "The floating IP ${OCF_RESKEY_ip} is correctly configured on this instance (${GCE_INSTANCE_NAME})"
return $OCF_SUCCESS
}
ip_release() {
cmd="ip address delete ${OCF_RESKEY_ip}/32 dev ${OCF_RESKEY_interface}"