#!/bin/bash
# Copyright (C) 2000-2005 SWsoft. All rights reserved.
#
# This file may be distributed under the terms of the Q Public License
# as defined by Trolltech AS of Norway and appearing in the file
# LICENSE.QPL included in the packaging of this file.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# This script remove routing for given VPS.
#
# Parameters are passed in environment variables.
# Required parameters:
#   IP_ADDR       - IPs to delete, several addresses should be divided by space
#   VEID          - VPS id
# Optional parameters:
#   VE_STATE      - state of VPS; could be one of:
#                     starting | stopping | running | stopped

. /usr/lib/vzctl/scripts/vps-functions

vzcheckvar IP_ADDR VEID

vzgetnetdev

for IP in $IP_ADDR; do
	vzdelrouting $IP
	vzarp del $IP
	# Update ip address information
	if [ "${VE_STATE}" = "running" ]; then
		cat ${VE_STATE_DIR}/${VEID} | tr ' ' '\n' | \
		grep -w -v "${IP}" | tr '\n' ' ' > ${VE_STATE_DIR}/${VEID}
	fi		
done

exit 0
# end of script
