cluster.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 -e "\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. #./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=os3-master
  34. ./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=os3-minion
  35. }
  36. [ -f ./cloud.rb ] || (echo 1>&2 'Cannot find ./cloud.rb' && exit 1)
  37. while getopts ':p:m:n:' flag; do
  38. case "${flag}" in
  39. p) PROVIDER="${OPTARG}" ;;
  40. m) MASTERS="${OPTARG}" ;;
  41. n) MINIONS="${OPTARG}" ;;
  42. *) echo -e 2>&1 "unsupported option $OPTARG\n"
  43. usage
  44. exit 1 ;;
  45. esac
  46. done
  47. shift $((OPTIND-1))
  48. [ -z "${1:-}" ] && (usage; exit 1)
  49. case "${1}" in
  50. 'create')
  51. [ -z "${2:-}" ] && (usage; exit 1)
  52. ENV="${2}"
  53. create_cluser ;;
  54. 'update')
  55. [ -z "${2:-}" ] && (usage; exit 1)
  56. ENV="${2}"
  57. update_cluster ;;
  58. 'terminate')
  59. [ -z "${2:-}" ] && (usage; exit 1)
  60. ENV="${2}"
  61. terminate_cluster ;;
  62. 'list') ./cloud.rb "${PROVIDER}" list ;;
  63. 'help') usage; exit 0 ;;
  64. *)
  65. echo -n 1>&2 "${1} is not a supported operation";
  66. usage;
  67. exit 1 ;;
  68. esac
  69. exit 0