Statistics
| Branch: | Tag: | Revision:

one / src / datastore_mad / remotes / ceph / monitor @ 3cfbb666

History | View | Annotate | Download (3.29 KB)

1
#!/bin/bash
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
17
#--------------------------------------------------------------------------- #
18

    
19
###############################################################################
20
# This script is used to monitor the free and used space of a datastore
21
###############################################################################
22

    
23
# -------- Set up the environment to source common tools & conf ------------
24

    
25
if [ -z "${ONE_LOCATION}" ]; then
26
    LIB_LOCATION=/usr/lib/one
27
else
28
    LIB_LOCATION=$ONE_LOCATION/lib
29
fi
30

    
31
. $LIB_LOCATION/sh/scripts_common.sh
32

    
33
DRIVER_PATH=$(dirname $0)
34
source ${DRIVER_PATH}/../libfs.sh
35
source ${DRIVER_PATH}/ceph.conf
36
source ${DRIVER_PATH}/ceph_utils.sh
37

    
38
# -------- Get datastore arguments from OpenNebula core ------------
39

    
40
DRV_ACTION=$1
41
ID=$2
42

    
43
XPATH="${DRIVER_PATH}/../xpath.rb -b $DRV_ACTION"
44

    
45
unset i j XPATH_ELEMENTS
46

    
47
while IFS= read -r -d '' element; do
48
    XPATH_ELEMENTS[i++]="$element"
49
done < <($XPATH     /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/BRIDGE_LIST \
50
                    /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/POOL_NAME \
51
                    /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_USER \
52
                    /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_KEY \
53
                    /DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/CEPH_CONF)
54

    
55
BRIDGE_LIST="${XPATH_ELEMENTS[j++]}"
56
POOL_NAME="${XPATH_ELEMENTS[j++]:-$POOL_NAME}"
57
CEPH_USER="${XPATH_ELEMENTS[j++]}"
58
CEPH_KEY="${XPATH_ELEMENTS[j++]}"
59
CEPH_CONF="${XPATH_ELEMENTS[j++]}"
60

    
61
HOST=`get_destination_host`
62

    
63
if [ -z "$HOST" ]; then
64
    error_message "Datastore template missing 'BRIDGE_LIST' attribute."
65
    exit -1
66
fi
67

    
68
if [ -n "$CEPH_USER" ]; then
69
    CEPH="$CEPH --id ${CEPH_USER}"
70
fi
71

    
72
if [ -n "$CEPH_KEY" ]; then
73
    CEPH="$CEPH --keyfile ${CEPH_KEY}"
74
fi
75

    
76
if [ -n "$CEPH_CONF" ]; then
77
    CEPH="$CEPH --conf ${CEPH_CONF}"
78
    RADOS="$RADOS --conf ${CEPH_CONF}"
79
fi
80

    
81
# ------------ Compute datastore usage -------------
82

    
83
MONITOR_SCRIPT=$(cat <<EOF
84
$CEPH df --format xml
85
EOF
86
)
87

    
88
MONITOR_DATA=$(ssh_monitor_and_log $HOST "$MONITOR_SCRIPT" 2>&1)
89
MONITOR_STATUS=$?
90

    
91
if [ "$MONITOR_STATUS" = "0" ]; then
92
    XPATH="${DRIVER_PATH}/../xpath.rb --stdin"
93
    echo -e "$(rbd_df_monitor ${MONITOR_DATA} ${POOL_NAME})"
94
else
95
    echo "$MONITOR_DATA"
96
    exit $MONITOR_STATUS
97
fi
98