| 1 | #! /bin/sh |
| 2 | |
| 3 | #set -x |
| 4 | |
| 5 | # The type of host. Could be : |
| 6 | # - server |
| 7 | # - frontend |
| 8 | # - node |
| 9 | SCRIPT_PREFIX=oar_resources_setup_as_ |
| 10 | SCRIPT_BASENAME=$(basename $0) |
| 11 | TYPE=${SCRIPT_BASENAME##$SCRIPT_PREFIX} |
| 12 | |
| 13 | THIS_HOSTNAME=$1 |
| 14 | shift |
| 15 | |
| 16 | # The first node is the server |
| 17 | SERVER_HOSTNAME=$1 |
| 18 | shift |
| 19 | |
| 20 | # The second node is the frontend |
| 21 | FRONTEND_HOSTNAME=$1 |
| 22 | shift |
| 23 | |
| 24 | # the other nodes are compute nodes. |
| 25 | NODE_HOSTNAME_LISTFILE=$1 |
| 26 | shift |
| 27 | |
| 28 | CORE_FACTOR=$1 |
| 29 | shift |
| 30 | |
| 31 | CPU_FACTOR=$1 |
| 32 | shift |
| 33 | |
| 34 | |
| 35 | openssh_cmd() { |
| 36 | host=$1 |
| 37 | shift |
| 38 | cmd=$* |
| 39 | su - oar -c "ssh -p 6667 $host $cmd" |
| 40 | } |
| 41 | |
| 42 | # |
| 43 | # Set oar with "normal ressources" |
| 44 | # |
| 45 | normal_resources_setup() { |
| 46 | if [ ! -f "$NODE_HOSTNAME_LISTFILE" ]; then |
| 47 | echo "Unable to read the node file list"; |
| 48 | fi |
| 49 | |
| 50 | cat "$NODE_HOSTNAME_LISTFILE" > /tmp/compute_nodes |
| 51 | oar_resources_init /tmp/compute_nodes << EOF |
| 52 | yes |
| 53 | yes |
| 54 | EOF |
| 55 | sh /tmp/oar_resources_init.txt |
| 56 | } |
| 57 | |
| 58 | dummy_resources_setup() { |
| 59 | if [ ! -f "$NODE_HOSTNAME_LISTFILE" ]; then |
| 60 | echo "Unable to read the node file list"; |
| 61 | fi |
| 62 | |
| 63 | tot_cpt_cpu=0 |
| 64 | tot_cpt_core=0 |
| 65 | |
| 66 | tmp_res=$(mktemp) |
| 67 | chown oar:oar $tmp_res |
| 68 | |
| 69 | PATH=/usr/local/sbin:/usr/sbin:$PATH |
| 70 | oarproperty -a cpu |
| 71 | oarproperty -a core |
| 72 | oarproperty -c -a host |
| 73 | oarproperty -a cpuset |
| 74 | oarproperty -a mem |
| 75 | |
| 76 | echo -n "[" > $tmp_res |
| 77 | for HOST in `cat $NODE_HOSTNAME_LISTFILE|sort -u` ; do |
| 78 | CPUS=$(openssh_cmd $HOST lscpu -p | tail -n+5 | cut -d',' -f 3 | uniq | wc -l) |
| 79 | TOTAL_CORES=$(openssh_cmd $HOST lscpu -p | tail -n+5 | cut -d',' -f 2 | uniq | wc -l) |
| 80 | CORES=$(($TOTAL_CORES / $CPUS)) |
| 81 | EMUL_CPUS=$(($CPUS * $CPU_FACTOR)) |
| 82 | EMUL_CORES=$(($CORES * $CORE_FACTOR)) |
| 83 | |
| 84 | for cpt_cpu in $(seq `expr $tot_cpt_cpu` 1 `expr $EMUL_CPUS + $tot_cpt_cpu - 1`); do |
| 85 | for cpt_core in $(seq `expr $tot_cpt_core` 1 `expr $EMUL_CORES + $tot_cpt_core - 1`); do |
| 86 | |
| 87 | echo -n "{\"hostname\":\"$HOST\", \"cpu\":\"$cpt_cpu\", \"core\":\"$cpt_core\", \"cpuset\":\"$(expr $cpt_core % $TOTAL_CORES)\"}," >> $tmp_res |
| 88 | |
| 89 | tot_cpt_core=`expr $tot_cpt_core + 1` |
| 90 | done ; |
| 91 | tot_cpt_cpu=`expr $tot_cpt_cpu + 1` |
| 92 | done ; |
| 93 | done |
| 94 | sed -e 's/,$/]/' -i $tmp_res |
| 95 | su - oar -c "curl -x '' -i http://$FRONTEND_HOSTNAME/oarapi/resources -H'Content-Type: application/json' -d @$tmp_res" > /dev/null |
| 96 | |
| 97 | } |
| 98 | |
| 99 | |
| 100 | case $TYPE in |
| 101 | normal) |
| 102 | normal_resources_setup |
| 103 | ;; |
| 104 | dummy) |
| 105 | dummy_resources_setup |
| 106 | ;; |
| 107 | *) |
| 108 | echo "$0: the type $TYPE is invalid. It could be currently only 'normal'. Failing." |
| 109 | exit 1 |
| 110 | ;; |
| 111 | esac |