VPC VR: return UNKNOWN redundant state if no guest nics (#11518)

* VPC VR: return UNKNOWN redundant state if no guest nics
This commit is contained in:
Wei Zhou 2025-08-29 09:21:33 +02:00 committed by GitHub
parent f80a9ca482
commit 05e7a257ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,13 +18,33 @@
STATUS=UNKNOWN STATUS=UNKNOWN
get_guest_nics() {
python3 -c "
import json
data = json.load(open('/etc/cloudstack/ips.json'))
for nic, objs in data.items():
if isinstance(objs, list):
for obj in objs:
if obj.get('nw_type') == 'guest' and obj.get('add'):
print(nic)
"
}
ROUTER_TYPE=$(cat /etc/cloudstack/cmdline.json | grep type | awk '{print $2;}' | sed -e 's/[,\"]//g')
if [ "$ROUTER_TYPE" = "vpcrouter" ];then
GUEST_NICS=$(get_guest_nics)
if [ "$GUEST_NICS" = "" ];then
echo "Status: ${STATUS}"
exit
fi
fi
if [ "$(systemctl is-active keepalived)" != "active" ] if [ "$(systemctl is-active keepalived)" != "active" ]
then then
echo "Status: FAULT" echo "Status: FAULT"
exit exit
fi fi
ROUTER_TYPE=$(cat /etc/cloudstack/cmdline.json | grep type | awk '{print $2;}' | sed -e 's/[,\"]//g')
if [ "$ROUTER_TYPE" = "router" ] if [ "$ROUTER_TYPE" = "router" ]
then then
ROUTER_STATE=$(ip -4 addr show dev eth0 | grep inet | wc -l | xargs bash -c 'if [ $0 == 2 ]; then echo "PRIMARY"; else echo "BACKUP"; fi') ROUTER_STATE=$(ip -4 addr show dev eth0 | grep inet | wc -l | xargs bash -c 'if [ $0 == 2 ]; then echo "PRIMARY"; else echo "BACKUP"; fi')