Statistics
| Branch: | Tag: | Revision:

one / share / hooks / fence_host.sh @ c2159551

History | View | Annotate | Download (3.77 KB)

1
#!/bin/bash
2

    
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2016, 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
# WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
21
#
22
# This script needs to be modified to enable fencing of the host. By default it
23
# will fail, as the first line is 'exit 1'. You will need to remove it.
24
#
25
# In order to perform the fencing, you will probably need to install a fencing
26
# utility. They are typically found in: fence-agents-all (CentOS) and fence-
27
# agents (Ubuntu). They come with many utilities: fence_ilo, fence_ipmilan,
28
# fence_apc, etc...
29
#
30
# To call the fencing utility, you will need to pass some parameters, which are
31
# typically the iLO IP of the host, etc. We recommend you enter this information
32
# in the host's template, and pick it up using the xpath example below. AS AN
33
# EXAMPLE (only an example) the script below expects that you have defined a
34
# parameter called FENCE_IP in the Host's template, and it will rely on that to
35
# call the fencing mechanism. You should customize this to your needs. It is
36
# perfectly OK to discard the code below and use a different mechanism, like
37
# storing the information required to perform the fencing in a separate CMDB,
38
# etc. However, you will probably need to get the host's NAME, which should be
39
# done as shown below.
40
#
41
# WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
42
#############################################################################
43

    
44
# @param $1 the host information in base64
45
# @return 0 on success. Make sure this script does not return 0 if it fails.
46

    
47
# To enable remove this line
48
exit 1
49

    
50
#-------------------------------------------------------------------------------
51
# Get host parameters with XPATH
52
#-------------------------------------------------------------------------------
53

    
54
if [ -z "$ONE_LOCATION" ]; then
55
    XPATH=/var/lib/one/remotes/datastore/xpath.rb
56
else
57
    XPATH=$ONE_LOCATION/var/remotes/datastore/xpath.rb
58
fi
59

    
60
if [ ! -x "$XPATH" ]; then
61
    echo "XPATH not found: $XPATH"
62
    exit 1
63
fi
64

    
65
XPATH="${XPATH} -b $1"
66

    
67
unset i j XPATH_ELEMENTS
68

    
69
while IFS= read -r -d '' element; do
70
    XPATH_ELEMENTS[i++]="$element"
71
done < <($XPATH     /HOST/ID \
72
                    /HOST/NAME \
73
                    /HOST/TEMPLATE/FENCE_IP )
74

    
75
HOST_ID="${XPATH_ELEMENTS[j++]}"
76
NAME="${XPATH_ELEMENTS[j++]}"
77
FENCE_IP="${XPATH_ELEMENTS[j++]}"
78

    
79
if [ -z "$FENCE_IP" ]; then
80
    echo "Fence ip not found"
81
    exit 1
82
fi
83

    
84
#-------------------------------------------------------------------------------
85
# Fence
86
#-------------------------------------------------------------------------------
87

    
88
# Example:
89
# fence_ilo -a $FENCE_IP -l <username> -p <password>