1 1 frueauf #!/bin/ksh 2 1 frueauf # 3 5 frueauf # Version 1.1 20080707 4 1 frueauf # Maintainer: Thorsten Frueauf 5 1 frueauf # 6 1 frueauf # CDDL HEADER START 7 1 frueauf # 8 1 frueauf # The contents of this file are subject to the terms of the 9 1 frueauf # Common Development and Distribution License (the License). 10 1 frueauf # You may not use this file except in compliance with the License. 11 1 frueauf # 12 1 frueauf # You can obtain a copy of the license at usr/src/CDDL.txt 13 1 frueauf # or http://www.opensolaris.org/os/licensing. 14 1 frueauf # See the License for the specific language governing permissions 15 1 frueauf # and limitations under the License. 16 1 frueauf # 17 1 frueauf # When distributing Covered Code, include this CDDL HEADER in each 18 1 frueauf # file and include the License file at <packagename>/CDDL.txt. 19 1 frueauf # If applicable, add the following below this CDDL HEADER, with the 20 1 frueauf # fields enclosed by brackets [] replaced with your own identifying 21 1 frueauf # information: Portions Copyright [yyyy] [name of copyright owner] 22 1 frueauf # 23 1 frueauf # CDDL HEADER END 24 1 frueauf # 25 1 frueauf # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 26 1 frueauf # Use is subject to license terms. 27 1 frueauf # 28 1 frueauf # 29 1 frueauf # The script will create two files for further use: 30 1 frueauf # 1) /tmp/${CLUSTERNAME}-resourcegroups.dot 31 1 frueauf # 2) /tmp/${CLUSTERNAME}-resources.dot 32 1 frueauf # 33 1 frueauf # Both files can then be used as input files for the dot command within the 34 1 frueauf # graphviz tools (http://www.graphviz.org/), e.g. 35 1 frueauf # 36 1 frueauf # $ dot -Tps /tmp/${CLUSTERNAME}-resources.dot -o ${CLUSTERNAME}-resources.ps 37 1 frueauf # 38 1 frueauf # to create a postscript file to visualize the dependencies. 39 1 frueauf # 40 1 frueauf # 1) is creating a directed graph for resource group dependencies and 41 1 frueauf # affinities. 42 1 frueauf # 43 1 frueauf # - black solid arrow = RG dependency 44 1 frueauf # - green solid arrow = strong positive affinity with failover delegation 45 1 frueauf # - blue solid arrow = strong positive affinity 46 1 frueauf # - brown dotted arrow = weak positive affinity 47 1 frueauf # - red solid arrow = strong negative affinity 48 1 frueauf # - orange dotted arrow = weak negative affinity 49 1 frueauf # 50 1 frueauf # 2) is creating a directed graph for the various resource dependencies. 51 1 frueauf # 52 1 frueauf # - black solid arrow = resource dependency 53 1 frueauf # - black dotted arrow = weak resource dependency 54 1 frueauf # - red solid arrow = restart dependency 55 1 frueauf # - orange solid arrow = offline restart dependencies 56 1 frueauf # - yellow solid arrow = implicit dependency on network resources 57 1 frueauf # 58 1 frueauf 59 1 frueauf PATH=/usr/cluster/bin:/bin:/usr/bin:/sbin:/usr/sbin 60 1 frueauf 61 1 frueauf if ! /usr/sbin/clinfo > /dev/null 62 1 frueauf then 63 1 frueauf echo "System is not running in cluster mode." 64 1 frueauf exit 1 65 1 frueauf fi 66 1 frueauf 67 1 frueauf if [ -f /usr/bin/zonename ] 68 1 frueauf then 69 1 frueauf if [ "$(/usr/bin/zonename)" != "global" ] 70 1 frueauf then 71 1 frueauf echo "Script needs to be run in the global zone." 72 1 frueauf exit 1 73 1 frueauf fi 74 1 frueauf fi 75 1 frueauf 76 1 frueauf CLUSTERNAME=`scha_cluster_get -O CLUSTERNAME` 77 1 frueauf 78 1 frueauf OUTPUTRG="/tmp/${CLUSTERNAME}-resourcegroups.dot" 79 1 frueauf OUTPUTRS="/tmp/${CLUSTERNAME}-resources.dot" 80 1 frueauf OUTPUTTMP="/tmp/${CLUSTERNAME}-resources-tmp.dot" 81 1 frueauf 82 1 frueauf ALLRGS=`scha_cluster_get -O ALL_RESOURCEGROUPS` 83 1 frueauf 84 1 frueauf LOCALHOST=`uname -n` 85 1 frueauf 86 1 frueauf if [ -f ${OUTPUTRG} ] 87 1 frueauf then 88 1 frueauf rm ${OUTPUTRG} 89 1 frueauf fi 90 1 frueauf 91 1 frueauf if [ -f ${OUTPUTRS} ] 92 1 frueauf then 93 1 frueauf rm ${OUTPUTRS} 94 1 frueauf fi 95 1 frueauf 96 1 frueauf if [ -f ${OUTPUTTMP} ] 97 1 frueauf then 98 1 frueauf rm ${OUTPUTTMP} 99 1 frueauf fi 100 1 frueauf 101 1 frueauf echo "digraph \"${CLUSTERNAME}\" {" >> ${OUTPUTRG} 102 1 frueauf echo "\tlabel=\"Cluster ${CLUSTERNAME} - RG Dependencies and Affinities\\\\n\\\\nblack solid arrow = RG dependency\\\\ngreen solid arrow = strong positive affinity with failover delegation\\\\nblue solid arrow = strong positive affinity\\\\nbrown dotted arrow = weak positive affinity\\\\nred solid arrow = strong negative affinity\\\\norange dotted arrow = weak negative affinity\";" >> ${OUTPUTRG} 103 1 frueauf 104 1 frueauf echo "digraph \"${CLUSTERNAME}\" {" >> ${OUTPUTRS} 105 1 frueauf echo "\tlabel=\"Cluster ${CLUSTERNAME} - Resource Dependencies\\\\n\\\\nblack solid arrow = resource dependency\\\\nblack dotted arrow = weak resource dependency\\\\nred solid arrow = restart dependency\\\\norange solid arrow = offline restart dependencies\\\\nyellow solid arrow = implicit dependency on network resources\";" >> ${OUTPUTRS} 106 1 frueauf 107 1 frueauf for RG in ${ALLRGS} 108 1 frueauf do 109 1 frueauf if [ "x${RG}" = "x" ]; then 110 1 frueauf break 111 1 frueauf fi 112 1 frueauf 113 1 frueauf echo "\tsubgraph \"cluster_${RG}\" {" >> ${OUTPUTRS} 114 1 frueauf echo "\t\tlabel=\"${RG}\";" >> ${OUTPUTRS} 115 1 frueauf 116 1 frueauf RG_DEP=`scha_resourcegroup_get -O RG_DEPENDENCIES -G ${RG} | tr -s "\n" " "` 117 1 frueauf if [ "${RG_DEP}" != " " ]; then 118 1 frueauf for dep in ${RG_DEP} 119 1 frueauf do 120 1 frueauf echo "\t\"${RG}\" -> \"${dep}\" [shape=box];" >> ${OUTPUTRG} 121 1 frueauf done 122 1 frueauf else 123 1 frueauf echo "\t\"${RG}\" [shape=box];" >> ${OUTPUTRG} 124 1 frueauf fi 125 1 frueauf 126 1 frueauf RG_AFF=`scha_resourcegroup_get -O RG_AFFINITIES -G ${RG} | tr -s "\n" " "` 127 1 frueauf if [ "${RG_AFF}" != " " ]; then 128 1 frueauf for dep in ${RG_AFF} 129 1 frueauf do 130 1 frueauf if echo ${dep} | grep "^+++" > /dev/null 131 1 frueauf then 132 1 frueauf echo "\t\"${RG}\" -> \"$(echo ${dep} | tr -d "^+++")\" [color=green,shape=box];" >> ${OUTPUTRG} 133 1 frueauf continue 134 1 frueauf fi 135 1 frueauf 136 1 frueauf if echo ${dep} | grep "^++" > /dev/null 137 1 frueauf then 138 1 frueauf echo "\t\"${RG}\" -> \"$(echo ${dep} | tr -d "^++")\" [color=blue,shape=box];" >> ${OUTPUTRG} 139 1 frueauf continue 140 1 frueauf fi 141 1 frueauf 142 1 frueauf if echo ${dep} | grep "^+" > /dev/null 143 1 frueauf then 144 1 frueauf echo "\t\"${RG}\" -> \"$(echo ${dep} | tr -d "^+")\" [color=brown,shape=box,style=dotted];" >> ${OUTPUTRG} 145 1 frueauf continue 146 1 frueauf fi 147 1 frueauf 148 1 frueauf if echo ${dep} | grep "^--" > /dev/null 149 1 frueauf then 150 1 frueauf echo "\t\"${RG}\" -> \"$(echo ${dep} | tr -d "^--")\" [color=red,shape=box];" >> ${OUTPUTRG} 151 1 frueauf continue 152 1 frueauf fi 153 1 frueauf 154 1 frueauf if echo ${dep} | grep "^-" > /dev/null 155 1 frueauf then 156 1 frueauf echo "\t\"${RG}\" -> \"$(echo ${dep} | tr -d "^-")\" [color=orange,shape=box,style=dotted];" >> ${OUTPUTRG} 157 1 frueauf continue 158 1 frueauf fi 159 1 frueauf done 160 1 frueauf fi 161 1 frueauf 162 1 frueauf RESOURCES=`scha_resourcegroup_get -O RESOURCE_LIST -G ${RG}` 163 1 frueauf NONNETRS= 164 1 frueauf NETRS= 165 1 frueauf 166 1 frueauf if [ "$(scha_resourcegroup_get -O Implicit_network_dependencies -G ${RG} | tr '[A-Z]' '[a-z]')" = "true" ]; then 167 1 frueauf IMPL_DEP=true 168 1 frueauf for RS in ${RESOURCES} 169 1 frueauf do 170 1 frueauf if echo $(scha_resource_get -O TYPE -R ${RS}) | /usr/xpg4/bin/grep -e ^SUNW.LogicalHostname -e ^SUNW.SharedAddress > /dev/null 171 1 frueauf then 172 5 frueauf if [ -z "${NETRS}" ] 173 1 frueauf then 174 1 frueauf NETRS=${RS} 175 1 frueauf else 176 1 frueauf NETRS="${NETRS} ${RS}" 177 1 frueauf fi 178 1 frueauf else 179 5 frueauf if [ -z "${NONNETRS}" ] 180 1 frueauf then 181 1 frueauf NONNETRS=${RS} 182 1 frueauf else 183 1 frueauf NONNETRS="${NONNETRS} ${RS}" 184 1 frueauf fi 185 1 frueauf fi 186 1 frueauf done 187 1 frueauf else 188 1 frueauf IMPL_DEP=false 189 1 frueauf fi 190 1 frueauf 191 1 frueauf for RS in ${RESOURCES} 192 1 frueauf do 193 5 frueauf if [ "${IMPL_DEP}" = "true" -a ! -z "${NETRS}" ] 194 1 frueauf then 195 1 frueauf if echo ${NONNETRS} | tr -s " " "\n" | grep ^${RS}$ > /dev/null 196 1 frueauf then 197 1 frueauf for res in ${NETRS} 198 1 frueauf do 199 1 frueauf echo "\t\t\"${RS}\" -> \"${res}\" [color=yellow];" >> ${OUTPUTRS} 200 1 frueauf done 201 1 frueauf fi 202 1 frueauf fi 203 1 frueauf 204 1 frueauf DEP=`scha_resource_get -O RESOURCE_DEPENDENCIES -R ${RS} | tr -s "\n" " "` 205 1 frueauf if [ "${DEP}" != " " ]; then 206 1 frueauf for dep in ${DEP} 207 1 frueauf do 208 1 frueauf if echo ${RESOURCES} | tr -s " " "\n" | grep -w ${dep} > /dev/null 209 1 frueauf then 210 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\";" >> ${OUTPUTRS} 211 1 frueauf else 212 1 frueauf echo "\t\"${RS}\" -> \"${dep}\";" >> ${OUTPUTTMP} 213 1 frueauf fi 214 1 frueauf done 215 1 frueauf else 216 1 frueauf echo "\t\t\"${RS}\";" >> ${OUTPUTRS} 217 1 frueauf fi 218 1 frueauf 219 1 frueauf DEP_WEAK=`scha_resource_get -O RESOURCE_DEPENDENCIES_WEAK -R ${RS} | tr -s "\n" " "` 220 1 frueauf if [ "${DEP_WEAK}" != " " ]; then 221 1 frueauf for dep in ${DEP_WEAK} 222 1 frueauf do 223 1 frueauf if echo ${RESOURCES} | tr -s " " "\n" | grep -w ${dep} > /dev/null 224 1 frueauf then 225 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [style=dotted];" >> ${OUTPUTRS} 226 1 frueauf else 227 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [style=dotted];" >> ${OUTPUTTMP} 228 1 frueauf fi 229 1 frueauf done 230 1 frueauf else 231 1 frueauf echo "\t\t\"${RS}\";" >> ${OUTPUTRS} 232 1 frueauf fi 233 1 frueauf 234 1 frueauf DEP_RESTART=`scha_resource_get -O RESOURCE_DEPENDENCIES_RESTART -R ${RS} | tr -s "\n" " "` 235 1 frueauf if [ "${DEP_RESTART}" != " " ]; then 236 1 frueauf for dep in ${DEP_RESTART} 237 1 frueauf do 238 1 frueauf if echo ${RESOURCES} | tr -s " " "\n" | grep -w ${dep} > /dev/null 239 1 frueauf then 240 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [color=red];" >> ${OUTPUTRS} 241 1 frueauf else 242 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [color=red];" >> ${OUTPUTTMP} 243 1 frueauf fi 244 1 frueauf done 245 1 frueauf else 246 1 frueauf echo "\t\t\"${RS}\";" >> ${OUTPUTRS} 247 1 frueauf fi 248 1 frueauf 249 1 frueauf DEP_OFFLINE_RESTART=`scha_resource_get -O RESOURCE_DEPENDENCIES_OFFLINE_RESTART -R ${RS} | tr -s "\n" " "` 250 1 frueauf if [ "${DEP_OFFLINE_RESTART}" != " " ]; then 251 1 frueauf for dep in ${DEP_OFFLINE_RESTART} 252 1 frueauf do 253 1 frueauf if echo ${RESOURCES} | tr -s " " "\n" | grep -w ${dep} > /dev/null 254 1 frueauf then 255 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [color=orange];" >> ${OUTPUTRS} 256 1 frueauf else 257 1 frueauf echo "\t\t\"${RS}\" -> \"${dep}\" [color=orange];" >> ${OUTPUTTMP} 258 1 frueauf fi 259 1 frueauf done 260 1 frueauf else 261 1 frueauf echo "\t\t\"${RS}\";" >> ${OUTPUTRS} 262 1 frueauf fi 263 1 frueauf 264 1 frueauf done 265 1 frueauf echo "\t}" >> ${OUTPUTRS} 266 1 frueauf done 267 1 frueauf 268 1 frueauf if [ -f ${OUTPUTTMP} ] 269 1 frueauf then 270 1 frueauf cat ${OUTPUTTMP} >> ${OUTPUTRS} 271 1 frueauf fi 272 1 frueauf 273 1 frueauf echo "}" >> ${OUTPUTRS} 274 1 frueauf echo "}" >> ${OUTPUTRG} 275 1 frueauf 276 1 frueauf echo "Output files for dot created:\n\t${OUTPUTRG}\n\t${OUTPUTRS}" 277 1 frueauf exit 0 278