launcher_cluster.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. '''
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. '''
  16. import time
  17. import sys
  18. from cluster import Cluster
  19. from config import Config
  20. def all(argv):
  21. if len(argv) < 7:
  22. print_help()
  23. exit(1)
  24. cluster_name = argv[2]
  25. VMs_num = int(argv[3])
  26. Docker_num_each_VM = int(argv[4])
  27. server_Weave_IP = argv[5]
  28. server_external_IP = argv[6]
  29. cluster = Cluster()
  30. cluster.request_GCE_cluster(VMs_num, Docker_num_each_VM, cluster_name)
  31. print "wait 50 seconds for the cluster to boot ... ..."
  32. time.sleep(50)
  33. cluster.run_docker_on_cluster(server_external_IP, server_Weave_IP)
  34. def request_cluster(argv):
  35. if len(argv) < 5:
  36. print_help()
  37. exit(1)
  38. cluster_name = argv[2]
  39. VMs_num = int(argv[3])
  40. Docker_num_each_VM = int(argv[4])
  41. cluster = Cluster()
  42. cluster.request_GCE_cluster(VMs_num, Docker_num_each_VM, cluster_name)
  43. print "Before run Docker on the Cluster, wait at least 50 seconds for the cluster to boot"
  44. def run_cluster(argv):
  45. if len(argv) < 4:
  46. print_help()
  47. exit(1)
  48. server_Weave_IP = argv[2]
  49. server_external_IP = argv[3]
  50. config = Config
  51. config.load()
  52. cluster = Cluster()
  53. cluster.load_cluster_info(config.ATTRIBUTES["cluster_info_file"])
  54. cluster.run_docker_on_cluster(server_external_IP, server_Weave_IP)
  55. def terminate():
  56. print "Log into GCE controller to terminate your cluster manually"
  57. def print_help():
  58. print "usage:"
  59. print
  60. print "all", " ", "request a GCE cluster and run Docker containers with Ambari-agent in all VMs"
  61. print "\t\t", "<the name of the cluster>"
  62. print "\t\t", "<number of VMs>"
  63. print "\t\t", "<number of dockers each VMs>"
  64. print "\t\t", "<Weave IP of Ambari-server>"
  65. print "\t\t", "<external IP of Ambari-server>"
  66. print
  67. print "request", " ", "request a cluster from GCE, generate the configuration for the cluster"
  68. print "\t\t", "<the name of the cluster>"
  69. print "\t\t", "<number of VMs>"
  70. print "\t\t", "<number of dockers each VMs>"
  71. print
  72. print "run", " ", "run Docker containers with Ambari-agent in all VMs of the cluster"
  73. print "\t\t", "<Weave IP of Ambari-server>"
  74. print "\t\t", "<external IP of Ambari-server>"
  75. print
  76. print "terminate", " ", "terminate the cluster"
  77. print
  78. print "help", " ", "help info"
  79. print
  80. print "more options in configuration file config/config.ini"
  81. print "see more instructions in tips.txt"
  82. print
  83. def main(argv):
  84. # the first argument is the python file name
  85. if len(argv) < 2:
  86. print_help()
  87. exit(1)
  88. command = argv[1]
  89. if command == "all":
  90. all(argv)
  91. elif command == "request":
  92. request_cluster(argv)
  93. elif command == "run":
  94. run_cluster(argv)
  95. elif command == "terminate":
  96. terminate()
  97. elif command == "help":
  98. print_help()
  99. else:
  100. print_help()
  101. main(sys.argv)
  102. # python launcher_cluster.py all test-cluster 2 3 192.168.10.10 104.196.84.248