cluster.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash -eu
  2. MINIONS=3
  3. MASTERS=1
  4. PROVIDER=gce
  5. # @formatter:off
  6. function usage {
  7. cat 1>&2 <<-EOT
  8. ${0} : [create|destroy|update|list] {GCE environment tag}
  9. Supported environment tags:
  10. $(grep 'SUPPORTED_ENVS.*=' ./cloud.rb)
  11. EOT
  12. }
  13. # @formatter:on
  14. function create_cluser {
  15. for (( i = 0; i < $MINIONS; i ++ )); do
  16. ./cloud.rb "${PROVIDER}" launch -e "${ENV}" --type=os3-minion
  17. done
  18. for (( i = 0; i < $MASTERS; i ++ )); do
  19. ./cloud.rb "${PROVIDER}" launch -e "${ENV}" --type=os3-master
  20. done
  21. update_cluster
  22. echo -n "\nCreated ${MASTERS} masters and ${MINIONS} minions using ${PROVIDER} provider\n"
  23. }
  24. function update_cluster {
  25. for (( i = 0; i < $MINIONS; i ++ )); do
  26. ./cloud.rb "${PROVIDER}" config -e "${ENV}" --type=os3-minion
  27. done
  28. for (( i = 0; i < $MASTERS; i ++ )); do
  29. ./cloud.rb "${PROVIDER}" config -e "${ENV}" --type=os3-master
  30. done
  31. }
  32. function terminate_cluster {
  33. for (( i = 0; i < $MINIONS; i ++ )); do
  34. ./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=os3-minion
  35. done
  36. for (( i = 0; i < $MASTERS; i ++ )); do
  37. ./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=os3-master
  38. done
  39. }
  40. [ -f ./cloud.rb ] || (echo 1 > 2 'Cannot find ./cloud.rb' && exit 1)
  41. while getopts ':p:m:n:' flag; do
  42. case "${flag}" in
  43. p) PROVIDER="${OPTARG}" ;;
  44. m) MASTERS="${OPTARG}" ;;
  45. n) MINIONS="${OPTARG}" ;;
  46. *) echo -n 2>&1 "unsupported option $OPTARG\n"
  47. usage
  48. exit 1 ;;
  49. esac
  50. done
  51. shift $((OPTIND-1))
  52. [ -z "${1:-}" ] && (usage; exit 1)
  53. case "${1}" in
  54. 'create')
  55. [ -z "${2:-''}" ] && (usage; exit 1)
  56. ENV="${2}"
  57. create_cluser ;;
  58. 'update')
  59. [ -z "${2:-''}" ] && (usage; exit 1)
  60. ENV="${2}"
  61. update_cluster ;;
  62. 'terminate')
  63. [ -z "${2:-''}" ] && (usage; exit 1)
  64. ENV="${2}"
  65. terminate_cluster ;;
  66. 'list') ./cloud.rb "${PROVIDER}" list ;;
  67. 'help') usage; exit 0 ;;
  68. *)
  69. echo -n 1>&2 "${1} is not a supported operation";
  70. usage;
  71. exit 1 ;;
  72. esac
  73. exit 0