--- a/heartbeat/aws-vpc-move-ip 2019-05-20 10:54:01.527329668 +0200 +++ b/heartbeat/aws-vpc-move-ip 2019-05-20 11:33:35.386089091 +0200 @@ -93,11 +93,19 @@ + + +Deprecated IP address param. Use the ip param instead. + +Deprecated VPC private IP Address + + + -Name of the routing table, where the route for the IP address should be changed, i.e. rtb-... +Name of the routing table(s), where the route for the IP address should be changed. If declaring multiple routing tables they should be separated by comma. Example: rtb-XXXXXXXX,rtb-YYYYYYYYY -routing table name +routing table name(s) @@ -129,6 +137,13 @@ END } +ec2ip_set_address_param_compat(){ + # Include backward compatibility for the deprecated address parameter + if [ -z "$OCF_RESKEY_ip" ] && [ -n "$OCF_RESKEY_address" ]; then + OCF_RESKEY_ip="$OCF_RESKEY_address" + fi +} + ec2ip_validate() { for cmd in aws ip curl; do check_binary "$cmd" @@ -150,20 +165,29 @@ } ec2ip_monitor() { - if ocf_is_true ${OCF_RESKEY_monapi} || [ "$__OCF_ACTION" = "start" ]; then - ocf_log info "monitor: check routing table (API call)" - cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 describe-route-tables --route-table-ids $OCF_RESKEY_routing_table --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].InstanceId" - ocf_log debug "executing command: $cmd" - ROUTE_TO_INSTANCE=$($cmd) - ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}" - if [ -z "$ROUTE_TO_INSTANCE" ]; then - ROUTE_TO_INSTANCE="" - fi + MON_RES="" + if ocf_is_true ${OCF_RESKEY_monapi} || [ "$__OCF_ACTION" = "start" ] || ocf_is_probe; then + for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do + ocf_log info "monitor: check routing table (API call) - $rtb" + cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 describe-route-tables --route-table-ids $rtb --query RouteTables[*].Routes[?DestinationCidrBlock=='$OCF_RESKEY_ip/32'].InstanceId" + ocf_log debug "executing command: $cmd" + ROUTE_TO_INSTANCE="$($cmd)" + ocf_log debug "Overlay IP is currently routed to ${ROUTE_TO_INSTANCE}" + if [ -z "$ROUTE_TO_INSTANCE" ]; then + ROUTE_TO_INSTANCE="" + fi + + if [ "$EC2_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then + ocf_log warn "not routed to this instance ($EC2_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE on $rtb" + MON_RES="$MON_RES $rtb" + fi + sleep 1 + done - if [ "$EC2_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ];then - ocf_log warn "not routed to this instance ($EC2_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE" + if [ ! -z "$MON_RES" ]; then return $OCF_NOT_RUNNING fi + else ocf_log debug "monitor: Enhanced Monitoring disabled - omitting API call" fi @@ -195,19 +219,23 @@ } ec2ip_get_and_configure() { - # Adjusting the routing table - cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile ec2 replace-route --route-table-id $OCF_RESKEY_routing_table --destination-cidr-block ${OCF_RESKEY_ip}/32 --instance-id $EC2_INSTANCE_ID" - ocf_log debug "executing command: $cmd" - $cmd - rc=$? - if [ "$rc" != 0 ]; then - ocf_log warn "command failed, rc: $rc" - return $OCF_ERR_GENERIC - fi + for rtb in $(echo $OCF_RESKEY_routing_table | sed -e 's/,/ /g'); do + cmd="$OCF_RESKEY_awscli --profile $OCF_RESKEY_profile --output text ec2 replace-route --route-table-id $rtb --destination-cidr-block ${OCF_RESKEY_ip}/32 --instance-id $EC2_INSTANCE_ID" + ocf_log debug "executing command: $cmd" + $cmd + rc=$? + if [ "$rc" != 0 ]; then + ocf_log warn "command failed, rc: $rc" + return $OCF_ERR_GENERIC + fi + sleep 1 + done # Reconfigure the local ip address ec2ip_drop - ip addr add "${OCF_RESKEY_ip}/32" dev $OCF_RESKEY_interface + cmd="ip addr add ${OCF_RESKEY_ip}/32 dev $OCF_RESKEY_interface" + ocf_log debug "executing command: $cmd" + $cmd rc=$? if [ $rc != 0 ]; then ocf_log warn "command failed, rc: $rc" @@ -289,6 +317,8 @@ exit $OCF_ERR_PERM fi +ec2ip_set_address_param_compat + ec2ip_validate case $__OCF_ACTION in