setupAgent.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. import socket
  18. import time
  19. import sys
  20. import logging
  21. import pprint
  22. import os
  23. import subprocess
  24. import threading
  25. import traceback
  26. from pprint import pformat
  27. AMBARI_PASSPHRASE_VAR = "AMBARI_PASSPHRASE"
  28. def execOsCommand(osCommand):
  29. """ Run yum install and make sure the puppet install alright """
  30. osStat = subprocess.Popen(osCommand, stdout=subprocess.PIPE)
  31. log = osStat.communicate(0)
  32. ret = {}
  33. ret["exitstatus"] = osStat.returncode
  34. ret["log"] = log
  35. return ret
  36. def installPreReq():
  37. """ Adds hdp repo
  38. rpmCommand = ["rpm", "-Uvh", "http://public-repo-1.hortonworks.com/HDP-1.1.1.16/repos/centos6/hdp-release-1.1.1.16-1.el6.noarch.rpm"]
  39. execOsCommand(rpmCommand)
  40. """
  41. yumCommand = ["yum", "-y", "install", "epel-release"]
  42. execOsCommand(yumCommand)
  43. def installPuppet():
  44. """ Run yum install and make sure the puppet install alright """
  45. osCommand = ["useradd", "-G", "puppet", "puppet"]
  46. execOsCommand(osCommand)
  47. yumCommand = ["yum", "-y", "install", "puppet"]
  48. return execOsCommand(yumCommand)
  49. def installAgent():
  50. """ Run yum install and make sure the agent install alright """
  51. # TODO replace rpm with yum -y
  52. rpmCommand = ["yum", "install", "-y", "/tmp/ambari-agent*.rpm"]
  53. return execOsCommand(rpmCommand)
  54. def configureAgent():
  55. """ Configure the agent so that it has all the configs knobs properly
  56. installed """
  57. return
  58. def runAgent(passPhrase):
  59. os.environ[AMBARI_PASSPHRASE_VAR] = passPhrase
  60. subprocess.call("/usr/sbin/ambari-agent start", shell=True)
  61. def main(argv=None):
  62. scriptDir = os.path.realpath(os.path.dirname(argv[0]))
  63. """ Parse the input"""
  64. onlyargs = argv[1:]
  65. passPhrase = onlyargs[0]
  66. installPreReq()
  67. # installPuppet()
  68. installAgent()
  69. configureAgent()
  70. runAgent(passPhrase)
  71. if __name__ == '__main__':
  72. logging.basicConfig(level=logging.DEBUG)
  73. main(sys.argv)