#!/bin/sh
# copyright (C) 2013 FUJITSU LIMITED All Rights Reserved

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
# 02110-1301, USA.

trap 'lxcf stop -f asia-srv euro-srv usa-srv ' 0

ASIASTATE=`lxcf list  | egrep asia-srv`
if [ -z "${ASIASTATE}" ] ; then
	echo 'create asia-srv'
	lxcf sysgen asia-srv
fi
lxcf start asia-srv
lxcf set -c 33 -m 512 asia-srv

EUROSTATE=`lxcf list | egrep euro-srv`
if [ -z "${EUROSTATE}" ] ; then
	echo 'create euro-srv'
	lxcf sysgen euro-srv
fi
lxcf start euro-srv
lxcf set -c 33 -m 512 euro-srv

USASTATE=`lxcf list | egrep usa-srv`
if [ -z "${USASTATE}" ] ; then
	echo 'create usa-srv'
	lxcf sysgen usa-srv
fi
lxcf start usa-srv
lxcf set -c 33 -m 512 usa-srv

echo "initialize cpurate"
echo "  asia-srv : 33%"
echo "  euro-srv : 33%"
echo "  usa-srv  : 33%"

sleep 10

echo
echo "run Bisiness JOBs : asia-srv"
lxcf run asia-srv "while : ; do true ;done"  >& /dev/null &
echo "run Bisiness JOBs : euro-srv"
lxcf run euro-srv "while : ; do true ;done"  >& /dev/null &
echo "run Bisiness JOBs : usa-srv"
lxcf run usa-srv "while : ; do true ;done"  >& /dev/null &
echo

sleep 10

while :
do
	echo
	echo "change cpurate"
	echo "  asia-srv : 80%"
	lxcf set -c 80 asia-srv
	echo "  euro-srv : 10%"
	lxcf set -c 10 euro-srv
	echo "  usa-srv : 10%"
	lxcf set -c 10 usa-srv

	sleep 30

	echo
	echo "change cpurate"
	echo "  asia-srv : 20%"
	lxcf set -c 20 asia-srv
	echo "  euro-srv : 70%"
	lxcf set -c 70 euro-srv
	echo "  usa-srv : 10%"
	lxcf set -c 10 usa-srv

	sleep 30

	echo
	echo "change cpurate"
	echo "  asia-srv : 10%"
	lxcf set -c 10 asia-srv
	echo "  euro-srv : 30%"
	lxcf set -c 30 euro-srv
	echo "  usa-srv : 60%"
	lxcf set -c 60 usa-srv

	sleep 30
done

