|
|
5371d1 |
--- a/heartbeat/aliyun-vpc-move-ip 2020-06-09 13:41:35.308379032 +0200
|
|
|
5371d1 |
+++ b/heartbeat/aliyun-vpc-move-ip 2020-06-05 10:48:45.555132686 +0200
|
|
|
5371d1 |
@@ -9,12 +9,46 @@
|
|
|
5371d1 |
# Initialization:
|
|
|
5371d1 |
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
|
|
|
5371d1 |
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+# Parameter defaults
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+OCF_RESKEY_address_default=""
|
|
|
5371d1 |
+OCF_RESKEY_routing_table_default=""
|
|
|
5371d1 |
+OCF_RESKEY_interface_default="eth0"
|
|
|
5371d1 |
+OCF_RESKEY_profile_default="default"
|
|
|
5371d1 |
+OCF_RESKEY_endpoint_default="vpc.aliyuncs.com"
|
|
|
5371d1 |
+OCF_RESKEY_aliyuncli_default="detect"
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+: ${OCF_RESKEY_address=${OCF_RESKEY_address_default}}
|
|
|
5371d1 |
+: ${OCF_RESKEY_routing_table=${OCF_RESKEY_routing_table_default}}
|
|
|
5371d1 |
+: ${OCF_RESKEY_interface=${OCF_RESKEY_interface_default}}
|
|
|
5371d1 |
+: ${OCF_RESKEY_profile=${OCF_RESKEY_profile_default}}
|
|
|
5371d1 |
+: ${OCF_RESKEY_endpoint=${OCF_RESKEY_endpoint_default}}
|
|
|
5371d1 |
+: ${OCF_RESKEY_aliyuncli=${OCF_RESKEY_aliyuncli_default}}
|
|
|
5371d1 |
+
|
|
|
5371d1 |
#######################################################################
|
|
|
5371d1 |
|
|
|
5371d1 |
-# aliyuncli doesnt work without HOME parameter
|
|
|
5371d1 |
+# aliyun cli doesnt work without HOME parameter
|
|
|
5371d1 |
export HOME="/root"
|
|
|
5371d1 |
|
|
|
5371d1 |
USAGE="usage: $0 {start|stop|status|meta-data}";
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+if [ "${OCF_RESKEY_aliyuncli}" = "detect" ]; then
|
|
|
5371d1 |
+ OCF_RESKEY_aliyuncli="$(which aliyuncli 2> /dev/null || which aliyun 2> /dev/null)"
|
|
|
5371d1 |
+fi
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+if [[ "${OCF_RESKEY_aliyuncli##*/}" == 'aliyuncli' ]]; then
|
|
|
5371d1 |
+ OUTPUT="text"
|
|
|
5371d1 |
+ EXECUTING='{ print $3 }'
|
|
|
5371d1 |
+ IFS_=" "
|
|
|
5371d1 |
+ ENDPOINT=""
|
|
|
5371d1 |
+elif [[ "${OCF_RESKEY_aliyuncli##*/}" == 'aliyun' ]]; then
|
|
|
5371d1 |
+ OUTPUT="table cols=InstanceId,DestinationCidrBlock rows=RouteTables.RouteTable[].RouteEntrys.RouteEntry[]"
|
|
|
5371d1 |
+ EXECUTING='{ gsub (" ", "", $0); print $1 }'
|
|
|
5371d1 |
+ IFS_="|"
|
|
|
5371d1 |
+ ENDPOINT="--endpoint $OCF_RESKEY_endpoint"
|
|
|
5371d1 |
+fi
|
|
|
5371d1 |
###############################################################################
|
|
|
5371d1 |
|
|
|
5371d1 |
|
|
|
5371d1 |
@@ -24,27 +58,61 @@
|
|
|
5371d1 |
#
|
|
|
5371d1 |
###############################################################################
|
|
|
5371d1 |
|
|
|
5371d1 |
+request_create_route_entry() {
|
|
|
5371d1 |
+ cmd="${OCF_RESKEY_aliyuncli} vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance ${ENDPOINT}"
|
|
|
5371d1 |
+ ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
+ res=$($cmd 2>&1)
|
|
|
5371d1 |
+ rc=$?
|
|
|
5371d1 |
+ if [[ $rc -eq 0 ]]
|
|
|
5371d1 |
+ then
|
|
|
5371d1 |
+ ocf_log debug "result: $res; rc: $rc"
|
|
|
5371d1 |
+ else
|
|
|
5371d1 |
+ ocf_log err "result: $res; cmd: $cmd; rc: $rc"
|
|
|
5371d1 |
+ fi
|
|
|
5371d1 |
+ return $rc
|
|
|
5371d1 |
+}
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+request_delete_route_entry() {
|
|
|
5371d1 |
+ cmd="${OCF_RESKEY_aliyuncli} vpc DeleteRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ROUTE_TO_INSTANCE ${ENDPOINT}"
|
|
|
5371d1 |
+ ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
+ res=$($cmd)
|
|
|
5371d1 |
+ rc=$?
|
|
|
5371d1 |
+ if [[ $rc -eq 0 ]]
|
|
|
5371d1 |
+ then
|
|
|
5371d1 |
+ ocf_log debug "result: $res; rc: $rc"
|
|
|
5371d1 |
+ else
|
|
|
5371d1 |
+ ocf_log err "result: $res; cmd: $cmd; rc: $rc"
|
|
|
5371d1 |
+ fi
|
|
|
5371d1 |
+ return $rc
|
|
|
5371d1 |
+}
|
|
|
5371d1 |
|
|
|
5371d1 |
+request_describe_route_tables() {
|
|
|
5371d1 |
+ cmd="${OCF_RESKEY_aliyuncli} vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output ${OUTPUT} ${ENDPOINT}"
|
|
|
5371d1 |
+ ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
+ res=$($cmd)
|
|
|
5371d1 |
+ rc=$?
|
|
|
5371d1 |
+ if [[ $rc -eq 0 ]]
|
|
|
5371d1 |
+ then
|
|
|
5371d1 |
+ ROUTE_TO_INSTANCE=$(echo "$res" |grep "\s${OCF_RESKEY_address}/" | awk -F "${IFS_}" "${EXECUTING}")
|
|
|
5371d1 |
+ ocf_log debug "ROUTE_TO_INSTANCE: $ROUTE_TO_INSTANCE"
|
|
|
5371d1 |
+ else
|
|
|
5371d1 |
+ ocf_log err "result: $res; cmd: $cmd; rc: $rc"
|
|
|
5371d1 |
+ fi
|
|
|
5371d1 |
+}
|
|
|
5371d1 |
|
|
|
5371d1 |
ip_get_and_configure() {
|
|
|
5371d1 |
ocf_log debug "function: ip_get_and_configure"
|
|
|
5371d1 |
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
-
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
if [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then
|
|
|
5371d1 |
if [ -n "$ROUTE_TO_INSTANCE" ]; then
|
|
|
5371d1 |
ip_drop
|
|
|
5371d1 |
fi
|
|
|
5371d1 |
-
|
|
|
5371d1 |
- cmd="aliyuncli vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- $cmd
|
|
|
5371d1 |
+ request_create_route_entry
|
|
|
5371d1 |
rc=$?
|
|
|
5371d1 |
while [ $rc -ne 0 ]; do
|
|
|
5371d1 |
sleep 1
|
|
|
5371d1 |
- cmd="aliyuncli vpc CreateRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ECS_INSTANCE_ID --NextHopType Instance --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- $cmd
|
|
|
5371d1 |
+ request_create_route_entry
|
|
|
5371d1 |
rc=$?
|
|
|
5371d1 |
done
|
|
|
5371d1 |
wait_for_started
|
|
|
5371d1 |
@@ -68,17 +136,15 @@
|
|
|
5371d1 |
ocf_log debug "function: ip_drop"
|
|
|
5371d1 |
cmd="ip addr delete ${OCF_RESKEY_address}/32 dev $OCF_RESKEY_interface"
|
|
|
5371d1 |
ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- $cmd
|
|
|
5371d1 |
+ res=$($cmd)
|
|
|
5371d1 |
rc=$?
|
|
|
5371d1 |
if [ $rc -ne 0 ] && [ $rc -ne 2 ]; then
|
|
|
5371d1 |
- ocf_log err "command failed, rc $rc"
|
|
|
5371d1 |
+ ocf_log err "command failed, rc: $rc; cmd: $cmd; result: $res"
|
|
|
5371d1 |
return $OCF_ERR_GENERIC
|
|
|
5371d1 |
fi
|
|
|
5371d1 |
-
|
|
|
5371d1 |
- cmd="aliyuncli vpc DeleteRouteEntry --RouteTableId $OCF_RESKEY_routing_table --DestinationCidrBlock ${OCF_RESKEY_address}/32 --NextHopId $ROUTE_TO_INSTANCE --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- $cmd
|
|
|
5371d1 |
- if [ $? -ne 0 ]; then
|
|
|
5371d1 |
+ request_delete_route_entry
|
|
|
5371d1 |
+ rc=$?
|
|
|
5371d1 |
+ if [ $rc -ne 0 ]; then
|
|
|
5371d1 |
ocf_log err "command failed, rc: $rc"
|
|
|
5371d1 |
return $OCF_ERR_GENERIC
|
|
|
5371d1 |
fi
|
|
|
5371d1 |
@@ -90,26 +156,18 @@
|
|
|
5371d1 |
}
|
|
|
5371d1 |
|
|
|
5371d1 |
wait_for_started() {
|
|
|
5371d1 |
- cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd | grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
-
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
while [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; do
|
|
|
5371d1 |
sleep 3
|
|
|
5371d1 |
- cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd | grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
done
|
|
|
5371d1 |
}
|
|
|
5371d1 |
|
|
|
5371d1 |
wait_for_deleted() {
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
-
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
while [ ! -z "$ROUTE_TO_INSTANCE" ]; do
|
|
|
5371d1 |
sleep 1
|
|
|
5371d1 |
- cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
done
|
|
|
5371d1 |
}
|
|
|
5371d1 |
|
|
|
5371d1 |
@@ -124,38 +182,58 @@
|
|
|
5371d1 |
by changing an entry in an specific routing table
|
|
|
5371d1 |
</longdesc>
|
|
|
5371d1 |
<shortdesc lang="en">Move IP within a VPC of the Aliyun ECS</shortdesc>
|
|
|
5371d1 |
+
|
|
|
5371d1 |
<parameters>
|
|
|
5371d1 |
+<parameter name="aliyuncli" required="0">
|
|
|
5371d1 |
+<longdesc lang="en">
|
|
|
5371d1 |
+Path to command line tools for Aliyun
|
|
|
5371d1 |
+</longdesc>
|
|
|
5371d1 |
+<shortdesc lang="en">Path to Aliyun CLI tools</shortdesc>
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_aliyuncli_default}" />
|
|
|
5371d1 |
+</parameter>
|
|
|
5371d1 |
+
|
|
|
5371d1 |
<parameter name="address" required="1">
|
|
|
5371d1 |
<longdesc lang="en">
|
|
|
5371d1 |
VPC private IP address
|
|
|
5371d1 |
</longdesc>
|
|
|
5371d1 |
<shortdesc lang="en">vpc ip</shortdesc>
|
|
|
5371d1 |
-<content type="string" default="" />
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_address_default}" />
|
|
|
5371d1 |
</parameter>
|
|
|
5371d1 |
+
|
|
|
5371d1 |
<parameter name="routing_table" required="1">
|
|
|
5371d1 |
<longdesc lang="en">
|
|
|
5371d1 |
Name of the routing table, where the route for the IP address should be changed, i.e. vtb-...
|
|
|
5371d1 |
</longdesc>
|
|
|
5371d1 |
<shortdesc lang="en">routing table name</shortdesc>
|
|
|
5371d1 |
-<content type="string" default="" />
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_routing_table_default}" />
|
|
|
5371d1 |
</parameter>
|
|
|
5371d1 |
+
|
|
|
5371d1 |
<parameter name="interface" required="1">
|
|
|
5371d1 |
<longdesc lang="en">
|
|
|
5371d1 |
Name of the network interface, i.e. eth0
|
|
|
5371d1 |
</longdesc>
|
|
|
5371d1 |
<shortdesc lang="en">network interface name</shortdesc>
|
|
|
5371d1 |
-<content type="string" default="eth0" />
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_interface_default}" />
|
|
|
5371d1 |
</parameter>
|
|
|
5371d1 |
-<parameter name="profile" required="0">
|
|
|
5371d1 |
+
|
|
|
5371d1 |
+<parameter name="endpoint" required="0">
|
|
|
5371d1 |
<longdesc lang="en">
|
|
|
5371d1 |
-Valid Aliyun CLI profile name (see 'aliyuncli-ra configure').
|
|
|
5371d1 |
+An endpoint is the service entry of an Alibaba Cloud service, i.e. vpc.cn-beijing.aliyuncs.com
|
|
|
5371d1 |
+</longdesc>
|
|
|
5371d1 |
+<shortdesc lang="en">service endpoint</shortdesc>
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_endpoint_default}" />
|
|
|
5371d1 |
+</parameter>
|
|
|
5371d1 |
|
|
|
5371d1 |
-See https://www.alibabacloud.com/help/doc-detail/43039.htm?spm=a2c63.p38356.b99.16.38a914abRZtOU3 for more information about aliyuncli-ra.
|
|
|
5371d1 |
+<parameter name="profile" required="0">
|
|
|
5371d1 |
+<longdesc lang="en">
|
|
|
5371d1 |
+Valid Aliyun CLI profile name (see 'aliyun cli configure').
|
|
|
5371d1 |
+See https://www.alibabacloud.com/help/zh/product/29991.htm for more information about aliyun cli.
|
|
|
5371d1 |
</longdesc>
|
|
|
5371d1 |
<shortdesc lang="en">profile name</shortdesc>
|
|
|
5371d1 |
-<content type="string" default="default" />
|
|
|
5371d1 |
+<content type="string" default="${OCF_RESKEY_profile_default}" />
|
|
|
5371d1 |
</parameter>
|
|
|
5371d1 |
</parameters>
|
|
|
5371d1 |
+
|
|
|
5371d1 |
<actions>
|
|
|
5371d1 |
<action name="start" timeout="180s" />
|
|
|
5371d1 |
<action name="stop" timeout="180s" />
|
|
|
5371d1 |
@@ -170,6 +248,11 @@
|
|
|
5371d1 |
ecs_ip_validate() {
|
|
|
5371d1 |
ocf_log debug "function: validate"
|
|
|
5371d1 |
|
|
|
5371d1 |
+ if [ -z "${OCF_RESKEY_aliyuncli}" ]; then
|
|
|
5371d1 |
+ ocf_exit_reason "unable to detect aliyuncli binary"
|
|
|
5371d1 |
+ exit $OCF_ERR_INSTALLED
|
|
|
5371d1 |
+ fi
|
|
|
5371d1 |
+
|
|
|
5371d1 |
# IP address
|
|
|
5371d1 |
if [ -z "$OCF_RESKEY_address" ]; then
|
|
|
5371d1 |
ocf_log err "IP address parameter not set $OCF_RESKEY_ADDRESS!"
|
|
|
5371d1 |
@@ -250,10 +333,7 @@
|
|
|
5371d1 |
|
|
|
5371d1 |
ecs_ip_monitor() {
|
|
|
5371d1 |
ocf_log debug "function: ecsip_monitor: check routing table"
|
|
|
5371d1 |
- cmd="aliyuncli vpc DescribeRouteTables --RouteTableId $OCF_RESKEY_routing_table --output text"
|
|
|
5371d1 |
- ocf_log debug "executing command: $cmd"
|
|
|
5371d1 |
-
|
|
|
5371d1 |
- ROUTE_TO_INSTANCE="$($cmd |grep $OCF_RESKEY_address | awk '{ print $3 }')"
|
|
|
5371d1 |
+ request_describe_route_tables
|
|
|
5371d1 |
|
|
|
5371d1 |
if [ "$ECS_INSTANCE_ID" != "$ROUTE_TO_INSTANCE" ]; then
|
|
|
5371d1 |
ocf_log debug "not routed to this instance ($ECS_INSTANCE_ID) but to instance $ROUTE_TO_INSTANCE"
|