root / trunk / shell / generate-dhcp-hostsfile
Historique | Voir | Annoter | Télécharger (1,91 ko)
| 1 | 38 | storres | #! /bin/bash |
|---|---|---|---|
| 2 | 3 | storres | # |
| 3 | 3 | storres | # Generate a dhcp-hostsfile for dnsmasq. |
| 4 | 3 | storres | # MAC_address,node_name,IP_address |
| 5 | 3 | storres | # |
| 6 | 3 | storres | # Get the directory of the script. |
| 7 | 3 | storres | SCRIPT_PATH=`dirname $0` |
| 8 | 3 | storres | # Get the script name. |
| 9 | 3 | storres | SCRIPT_NAME=`basename $0` |
| 10 | 3 | storres | # Source the common configuration variables. |
| 11 | 3 | storres | . $SCRIPT_PATH/c-i-a-b.common |
| 12 | 3 | storres | # Clean up the file |
| 13 | 50 | storres | DHCP_HOSTS_FILE="${SCRIPT_PATH}/${CONST_TEMPLATES_DIR}/etc/${CONST_DHCP_HOSTS_FILE_BASENAME}"
|
| 14 | 38 | storres | rm -f $DHCP_HOSTS_FILE |
| 15 | 29 | storres | # Compute the file entries. |
| 16 | 3 | storres | for i in `seq 1 $COMPUTE_NODE_MAX_NUM` |
| 17 | 3 | storres | do |
| 18 | 3 | storres | NODE_NUMBER=$i |
| 19 | 3 | storres | NODE_NUMBER_STRING=$NODE_NUMBER |
| 20 | 3 | storres | # Normalize the node numbers for the node names on 3 characters. |
| 21 | 3 | storres | while [ ${#NODE_NUMBER_STRING} -lt 3 ]
|
| 22 | 3 | storres | do |
| 23 | 3 | storres | NODE_NUMBER_STRING="0$NODE_NUMBER_STRING" |
| 24 | 3 | storres | done |
| 25 | 3 | storres | # Transform the decimal node number in hexadecimal for the MAC address. |
| 26 | 3 | storres | NODE_NUMBER_HEXA=`printf "%X" $NODE_NUMBER` |
| 27 | 3 | storres | while [ ${#NODE_NUMBER_HEXA} -lt 2 ]
|
| 28 | 3 | storres | do |
| 29 | 3 | storres | NODE_NUMBER_HEXA="0$NODE_NUMBER_HEXA" |
| 30 | 3 | storres | done |
| 31 | 29 | storres | MAC_ADDRESS="${CLUSTER_MAC_ADDRESS_PREFIX}:${NODE_NUMBER_HEXA}"
|
| 32 | 3 | storres | COMPUTE_NODE_NAME="${COMPUTE_NODE_NAME_PREFIX}${NODE_NUMBER_STRING}"
|
| 33 | 38 | storres | echo "${MAC_ADDRESS},id:*,${CLUSTER_STATIC_NETWORK_PREFIX}.${NODE_NUMBER},${COMPUTE_NODE_NAME}" >> $DHCP_HOSTS_FILE
|
| 34 | 29 | storres | |
| 35 | 3 | storres | done |
| 36 | 29 | storres | # Front end stuff |
| 37 | 29 | storres | NODE_NUMBER_HEXA=`printf "%X" $CONST_FRONT_END_CLUSTER_STATIC_NETWORK_POSTFIX` |
| 38 | 29 | storres | MAC_ADDRESS="${CLUSTER_MAC_ADDRESS_PREFIX}:${NODE_NUMBER_HEXA}"
|
| 39 | 38 | storres | echo "${MAC_ADDRESS},id:*,${CLUSTER_STATIC_NETWORK_PREFIX}.$CONST_FRONT_END_CLUSTER_STATIC_NETWORK_POSTFIX,${FRONT_END_CLUSTER_HOST_NAME}" >> $DHCP_HOSTS_FILE
|
| 40 | 29 | storres | # Compute node model stuff |
| 41 | 29 | storres | NODE_NUMBER_HEXA=`printf "%X" $CONST_COMPUTE_NODE_MODEL_CLUSTER_STATIC_NETWORK_POSTFIX` |
| 42 | 25 | storres | MAC_ADDRESS="${CLUSTER_MAC_ADDRESS_PREFIX}:$NODE_NUMBER_HEXA"
|
| 43 | 38 | storres | echo "${MAC_ADDRESS},id:*,${CLUSTER_STATIC_NETWORK_PREFIX}.${CONST_COMPUTE_NODE_MODEL_CLUSTER_STATIC_NETWORK_POSTFIX},${COMPUTE_NODE_MODEL_CLUSTER_HOST_NAME}" >> $DHCP_HOSTS_FILE
|
| 44 | 3 | storres | echo |
| 45 | 3 | storres | echo Copy the file to the front end! |
| 46 | 3 | storres | echo |
| 47 | 3 | storres | exit 0 |