forked from OpenNebula/addon-linstor_un
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor
executable file
·91 lines (73 loc) · 3.56 KB
/
monitor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2019, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
###############################################################################
# This script is used to monitor the free and used space of a datastore
###############################################################################
# -------- Set up the environment to source common tools & conf ------------
if [ -z "${ONE_LOCATION}" ]; then
LIB_LOCATION=/usr/lib/one
else
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $LIB_LOCATION/sh/scripts_common.sh
DRIVER_PATH=$(dirname $0)
UTILS_PATH="${DRIVER_PATH}/.."
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/../../etc/datastore/linstor_un/linstor_un.conf
source ${DRIVER_PATH}/linstor_utils.sh
# -------- Get datastore arguments from OpenNebula core ------------
DRV_ACTION=$1
ID=$2
XPATH="${UTILS_PATH}/xpath.rb -b $DRV_ACTION"
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LS_CONTROLLERS \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LS_CERTFILE \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LS_KEYFILE \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/LS_CAFILE \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/RESOURCE_GROUP \
/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/STORAGE_POOL)
LS_CONTROLLERS="${XPATH_ELEMENTS[j++]}"
LS_CERTFILE="${XPATH_ELEMENTS[j++]}"
LS_KEYFILE="${XPATH_ELEMENTS[j++]}"
LS_CAFILE="${XPATH_ELEMENTS[j++]}"
RESOURCE_GROUP="${XPATH_ELEMENTS[j++]}"
STORAGE_POOL="${XPATH_ELEMENTS[j++]}"
linstor_load_keys
if [ -z "$STORAGE_POOL" ]; then
if [ -z "$RESOURCE_GROUP" ]; then
error_message "Datastore template missing 'STORAGE_POOL' attribute."
exit -1
fi
STORAGE_POOL=$($LINSTOR -m --output-version v0 resource-group list -r "$RESOURCE_GROUP" \
| $JQ -r '.[][].select_filter.storage_pool_list // [] | join(" ")')
if [ -z "$STORAGE_POOL" ]; then
error_message "Resource group missing 'StoragePool' attribute."
exit -1
fi
fi
# ------------ Compute datastore usage -------------
MONITOR_SCRIPT="timeout 10 $LINSTOR -m --output-version v0 storage-pool list -s $STORAGE_POOL"
MONITOR_DATA="$(monitor_and_log "$MONITOR_SCRIPT" 2>&1)"
MONITOR_STATUS=$?
if [ "$MONITOR_STATUS" = "0" ]; then
linstor_monitor_storpool "${MONITOR_DATA}"
else
echo "$MONITOR_DATA"
exit $MONITOR_STATUS
fi