Alex Miller | 7a48978 | 2014-06-04 18:24:16 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | FROM_HOST=cautotest |
| 3 | TO_HOST=cautotest-cq |
| 4 | POOL=pool:cq |
| 5 | |
| 6 | function quiet() { |
| 7 | $@ > /dev/null |
| 8 | } |
| 9 | |
| 10 | function silent() { |
| 11 | $@ > /dev/null 2>&1 |
| 12 | } |
| 13 | |
| 14 | function host_labels() { |
| 15 | ./cli/atest host list --web=$FROM_HOST --parse $1 | awk -F '|' '{ print $5 }' | sed 's/Labels=//' | sed 's/, /,/g' |
| 16 | } |
| 17 | |
| 18 | function host_platform() { |
| 19 | ./cli/atest host list --web=$FROM_HOST $1 | sed 1d | awk '{ print $4; }' |
| 20 | } |
| 21 | |
| 22 | function lock_host() { |
| 23 | ./cli/atest host mod --web=$FROM_HOST -l $1 |
| 24 | } |
| 25 | |
| 26 | function create_labels() { |
| 27 | ./cli/atest label create --web=$TO_HOST $1 |
| 28 | } |
| 29 | |
| 30 | function create_platform() { |
| 31 | ./cli/atest label create -t --web=$TO_HOST $1 |
| 32 | } |
| 33 | |
| 34 | function create_host() { |
| 35 | ./cli/atest host create --web=$TO_HOST -b $2 $1 |
| 36 | } |
| 37 | |
| 38 | function remove_host() { |
| 39 | ./cli/atest host delete --web=$FROM_HOST $1 |
| 40 | } |
| 41 | |
| 42 | HOSTS_TO_MOVE=$(./cli/atest host list --web=$FROM_HOST -b $POOL | sed 1d | awk '{ print $1 }') |
| 43 | |
| 44 | for host in $HOSTS_TO_MOVE |
| 45 | do |
| 46 | # if ! silent lock_host $host; then echo $host already handled; continue; fi |
| 47 | LABELS=$(host_labels $host) |
| 48 | PLATFORM=$(host_platform $host) |
| 49 | silent create_labels $LABELS |
| 50 | silent create_platform $PLATFORM |
| 51 | if create_host $host $LABELS |
| 52 | then |
| 53 | silent remove_host $host |
| 54 | echo $host migrated |
| 55 | else |
| 56 | echo $host failed |
| 57 | fi |
| 58 | done |