#!/bin/bash

source /usr/local/lib/hostsharing/pac

SRV=$(hostname -s |sed -e's/^h/vm10/')

pac_get $SRV
PAC_QUOTA=$(($PAC_QUOTA/1024))
PAC_STORAGE=$(($PAC_STORAGE/1024))
PAC_RAM=$(($PAC_RAM/1024))

CPU=$(cat /proc/cpuinfo |grep ^processor |wc -l)
RAM=$(dmidecode --type memory |grep 'Maximum Capacity:' |awk '{ print $3 }')
ANZ_DISK=$(ls /dev/disk/by-id/wwn-0x000000000000000[12] | wc -l)
ONLY_STORAGE="NO";
NO_STORAGE="NO";

#if [ "$SRV" == "vm1023" ]; then
#	ONLY_STORAGE="YES";
#fi

if [ "$SRV" == "vm0000" ]; then
	NO_STORAGE="YES";
fi

if [ "$ONLY_STORAGE" == "NO" ]; then
	QUOTA=$(parted /dev/disk/by-id/wwn-0x0000000000000001 unit gib print |grep 'Disk /dev/sd' |awk '{ print $3 }' |sed -e's/[^0-9].*$//g')
fi

if [ "$ANZ_DISK" == "2" ]; then
	STORAGE=$(parted /dev/disk/by-id/wwn-0x0000000000000002 unit gib print |grep 'Disk /dev/sd' |awk '{ print $3 }' |sed -e's/[^0-9].*$//g')
fi

if [ "$ONLY_STORAGE" == "YES" ]; then
	STORAGE=$(parted /dev/disk/by-id/wwn-0x0000000000000001 unit gib print |grep 'Disk /dev/sd' |awk '{ print $3 }' |sed -e's/[^0-9].*$//g')
fi

if [ ! "$PAC_CPU" == "$CPU" ]; then
    echo "$SRV: CPU misconfiguration! Booked: $PAC_CPU Threads, but assigned: $CPU Threads."
fi

if [ ! "$PAC_RAM" == "$RAM" ]; then
    echo "$SRV: RAM misconfiguration! Booked: $PAC_RAM GB, but assigned: $RAM GB."
fi

if [ ! "$PAC_QUOTA" == "$QUOTA" -a "$ONLY_STORAGE" == "NO" ]; then
    echo "$SRV: QUOTA misconfiguration! Booked: $PAC_QUOTA GB, but assigned: $QUOTA GB."
fi

if [ "$NO_STORAGE" == "NO" ]; then
	if [ "$ANZ_DISK" == "2" -o "$ONLY_STORAGE" == "YES" ]; then
		if [ ! "$PAC_STORAGE" == "$STORAGE" ]; then
    		echo "$SRV: STORAGE misconfiguration! Booked: $PAC_STORAGE GB, but assigned: $STORAGE GB."
fi
fi
fi
