#!/bin/sh # # # OpenStack HA tool for Neutron (neutron-ha-tool) # # Description: This resource agent wraps the Neutron HA Tool(neutron-ha-tool). # It can be used to monitor neutron for the availability of the # l3-agents and migrate routers away from agents that are # currently offline. Additionally it makes sure that dns and dhcp # configuration is synchronized across all dhcp-agents. The # neutron-ha-tool is currently part of the openstack-network # cookbook for chef. The lastest release is available here: # https://raw.githubusercontent.com/stackforge/cookbook-openstack-network/master/files/default/neutron-ha-tool.py # # Authors: Ralf Haferkamp # Mainly inspired by the Neutron L3 resource agent written by Emilien Macchi # # Support: openstack@lists.launchpad.net # License: Apache Software License (ASL) 2.0 # # # See usage() function below for more details ... # # OCF instance parameters: # OCF_RESKEY_binary # OCF_RESKEY_os_auth_url # OCF_RESKEY_os_username # OCF_RESKEY_os_password # OCF_RESKEY_os_tenant_name ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs ####################################################################### # Fill in some defaults if no values are specified OCF_RESKEY_binary_default="neutron-ha-tool" OCF_RESKEY_os_auth_url_default="http://localhost:5000/v2" OCF_RESKEY_os_username_default="admin" OCF_RESKEY_os_password_defaut="" OCF_RESKEY_os_tenant_name_default="admin" OCF_RESKEY_os_insecure_default="0" OCF_RESKEY_os_cacert_default="" : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} : ${OCF_RESKEY_os_auth_url=${OCF_RESKEY_os_auth_url_default}} : ${OCF_RESKEY_os_tenant_name=${OCF_RESKEY_os_tenant_name_default}} : ${OCF_RESKEY_os_username=${OCF_RESKEY_os_username_default}} : ${OCF_RESKEY_os_password=${OCF_RESKEY_os_password_default}} : ${OCF_RESKEY_os_insecure=${OCF_RESKEY_os_insecure_default}} : ${OCF_RESKEY_os_cacert=${OCF_RESKEY_os_cacert_default}} ####################################################################### usage() { cat < 1.0 This resource agent wraps the Neutron HA Tool (neutron-ha-tool) and can be used to check neutron for offline l3-agents that have routers assigend and migrate those routers to a different (online) l3-agent. Manages the OpenStack Neutron HA Tool (neutron-ha-tool) Location of the OpenStack Neutron HA Tool binary (neutron-ha-tool) OpenStack Neutron HA Tool binary (neutron-ha-tool) The URL pointing to the Keystone instance to use for authentication. Keystone URL The password to use for authentication against keystone. Password for authentication The Tenant to use for authentication against keystone. Tenant name for authentication OpenStack Username for authentication. OpenStack Username Disable SSL certificate verification. Disable SSL certificate verification Filename of a SSL CA Certificate Bundle to use for Server Certificate verification. SSL CA Bundle file END } ####################################################################### # Functions invoked by resource manager actions neutron_ha_tool_validate() { check_binary $OCF_RESKEY_binary if [ -n "$OCF_RESKEY_os_cacert" ]; then if [ ! -f "$OCF_RESKEY_os_cacert" ]; then ocf_log err "Failed to verify CA Certifcate Bundle ($OCF_RESKEY_os_cacert)" return 1 fi fi true } neutron_ha_tool_status() { # There is not much to do here, since there is no daemon to check for. # Just pretend we're running successfully return $OCF_SUCCESS } neutron_ha_tool_monitor() { INSECURE="" if ocf_is_true $OCF_RESKEY_os_insecure; then INSECURE="--insecure" fi ${OCF_RESKEY_binary} --l3-agent-check --quiet $INSECURE rc=$? if [ $rc -eq 2 ]; then ocf_log err "Some Neutron routers need migration." return $OCF_NOT_RUNNING fi ocf_log debug "Neutron HA Tool (neutron-ha-tool) monitor succeeded" return $OCF_SUCCESS } neutron_ha_tool_start() { INSECURE="" if ocf_is_true $OCF_RESKEY_os_insecure; then INSECURE="--insecure" fi ${OCF_RESKEY_binary} --replicate-dhcp $INSECURE rc=$? if [ $rc -ne 0 ]; then ocf_log err "Neutron HA Tool failed to replicate networks to DHCP agents." return $OCF_ERR_GENERIC fi ${OCF_RESKEY_binary} --l3-agent-migrate --now $INSECURE rc=$? if [ $rc -ne 0 ]; then ocf_log err "Neutron HA Tool failed to migrate routers away from offline L3 agents." return $OCF_ERR_GENERIC fi ocf_log debug "Neutron HA Tool (neutron-ha-tool) router migration succeeded." return $OCF_SUCCESS } neutron_ha_tool_stop() { # This is a noop return $OCF_SUCCESS } ####################################################################### case "$1" in meta-data) meta_data exit $OCF_SUCCESS;; usage|help) usage exit $OCF_SUCCESS;; esac # Anything except meta-data and help must pass validation neutron_ha_tool_validate || exit $? # OPENSTACK env variables export OS_AUTH_URL=$OCF_RESKEY_os_auth_url export OS_TENANT_NAME=$OCF_RESKEY_os_tenant_name export OS_USERNAME=$OCF_RESKEY_os_username export OS_PASSWORD=$OCF_RESKEY_os_password if [ -n "$OCF_RESKEY_os_cacert" ]; then export OS_CACERT=$OCF_RESKEY_os_cacert fi # What kind of method was invoked? case "$1" in start) neutron_ha_tool_start;; stop) neutron_ha_tool_stop;; status) neutron_ha_tool_status;; monitor) neutron_ha_tool_monitor;; validate-all) ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac