cluster.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash -eu
  2. MINIONS=2
  3. MASTERS=1
  4. # If the environment variable OO_PROVDER is defined, it used for the provider
  5. PROVIDER=${OO_PROVIDER:-''}
  6. # Otherwise, default is gce (Google Compute Engine)
  7. if [ "x$PROVIDER" == "x" ];then
  8. PROVIDER=gce
  9. fi
  10. UPPER_CASE_PROVIDER=$(echo $PROVIDER | tr '[:lower:]' '[:upper:]')
  11. # FIXME: Add options
  12. MASTER_PLAYBOOK=openshift-master
  13. MINION_PLAYBOOK=openshift-minion
  14. # @formatter:off
  15. function usage {
  16. cat 1>&2 <<-EOT
  17. ${0} : [create|terminate|update|list] { ${UPPER_CASE_PROVIDER} environment tag}
  18. Supported environment tags:
  19. $(grep --no-messages 'SUPPORTED_ENVS.*=' ./lib/${PROVIDER}_command.rb)
  20. $([ $? -ne 0 ] && echo "No supported environment tags found for ${PROVIDER}")
  21. EOT
  22. }
  23. # @formatter:on
  24. function create_cluster {
  25. ./cloud.rb "${PROVIDER}" launch -e "${ENV}" --type=$MASTER_PLAYBOOK -c $MASTERS
  26. ./cloud.rb "${PROVIDER}" launch -e "${ENV}" --type=$MINION_PLAYBOOK -c $MINIONS
  27. update_cluster
  28. echo -e "\nCreated ${MASTERS}/${MASTER_PLAYBOOK} masters and ${MINIONS}/${MINION_PLAYBOOK} minions using ${PROVIDER} provider\n"
  29. }
  30. function update_cluster {
  31. ./cloud.rb "${PROVIDER}" config -e "${ENV}" --type=$MASTER_PLAYBOOK
  32. ./cloud.rb "${PROVIDER}" config -e "${ENV}" --type=$MINION_PLAYBOOK
  33. }
  34. function terminate_cluster {
  35. ./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=$MASTER_PLAYBOOK
  36. ./cloud.rb "${PROVIDER}" terminate -e "${ENV}" --type=$MINION_PLAYBOOK
  37. }
  38. [ -f ./cloud.rb ] || (echo 1>&2 'Cannot find ./cloud.rb' && exit 1)
  39. while getopts ':p:m:n:' flag; do
  40. case "${flag}" in
  41. p) PROVIDER="${OPTARG}" ;;
  42. m) MASTERS="${OPTARG}" ;;
  43. n) MINIONS="${OPTARG}" ;;
  44. *) echo -e 2>&1 "unsupported option $OPTARG\n"
  45. usage
  46. exit 1 ;;
  47. esac
  48. done
  49. shift $((OPTIND-1))
  50. [ -z "${1:-}" ] && (usage; exit 1)
  51. case "${1}" in
  52. 'create')
  53. [ -z "${2:-}" ] && (usage; exit 1)
  54. ENV="${2}"
  55. create_cluster ;;
  56. 'update')
  57. [ -z "${2:-}" ] && (usage; exit 1)
  58. ENV="${2}"
  59. update_cluster ;;
  60. 'terminate')
  61. [ -z "${2:-}" ] && (usage; exit 1)
  62. ENV="${2}"
  63. terminate_cluster ;;
  64. 'list') ./cloud.rb "${PROVIDER}" list ;;
  65. 'help') usage; exit 0 ;;
  66. *)
  67. echo -n 1>&2 "${1} is not a supported operation";
  68. usage;
  69. exit 1 ;;
  70. esac
  71. exit 0