Updated Branches: refs/heads/trunk 2e11b88d1 -> c97f62fb1
AMBARI-2638. Create a utility script to distribute all the keytabs generated by keytabs.sh. (jaimin) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/c97f62fb Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/c97f62fb Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/c97f62fb Branch: refs/heads/trunk Commit: c97f62fb186f0d55025343f32a03bea282218e58 Parents: 2e11b88 Author: Jaimin Jetly <[email protected]> Authored: Mon Jul 15 11:08:30 2013 -0700 Committer: Jaimin Jetly <[email protected]> Committed: Mon Jul 15 11:08:30 2013 -0700 ---------------------------------------------------------------------- .../resources/scripts/distribute_keytabs.py | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/c97f62fb/ambari-server/src/main/resources/scripts/distribute_keytabs.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/scripts/distribute_keytabs.py b/ambari-server/src/main/resources/scripts/distribute_keytabs.py new file mode 100644 index 0000000..6d47470 --- /dev/null +++ b/ambari-server/src/main/resources/scripts/distribute_keytabs.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +''' +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +from optparse import OptionParser +import sys +import subprocess +import re +import os +import glob + + +def sendTarfileToHosts(hostnames,identity_file,krb5_conf): + user = "root" + for i in range(len(hostnames)): + remotehost, localfile = hostnames[i] + os.system('scp -i "%s" -oStrictHostKeyChecking=no "%s" "%s"@"%s":/' % (identity_file, localfile, user, remotehost)) + if krb5_conf: + os.system('scp -i "%s" -oStrictHostKeyChecking=no "%s" "%s"@"%s":%s' % (identity_file, krb5_conf, user, remotehost, krb5_conf)) + sshCommand = "tar xvf /" + os.path.basename(localfile) + " -C /" + ssh = subprocess.Popen(["ssh", "-i", "%s" % identity_file, "-oStrictHostKeyChecking=no","%s" % remotehost, sshCommand],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + result = ssh.stdout.readlines() + if result == []: + error = ssh.stderr.readlines() + print >>sys.stderr, "ERROR: %s" % error + else: + print result + + +def getHostnames(filenames,regex): + return [(hostname.group(1),tarfile) for tarfile in filenames for hostname in (regex(tarfile),) if hostname] + + +def main(): + parser = OptionParser() + parser.add_option('-d','--directory', help='Path to the Directory containing tar files',dest='dirPath', default='.') + parser.add_option('-i','--identity-file', help='Path to the identity file',dest='identity_file', default='/tmp/ec2-keypair') + parser.add_option('-k','--krb5-conf', help='Path to the krb5_conf file',dest='krb5_conf') + (options, args) = parser.parse_args() + pattern = options.dirPath + "/*.tar" + tarfiles = glob.glob(pattern) + hostnames_regex = re.compile("(?<=keytabs_)(.*)(?=.tar)").search + hostnames = getHostnames(tarfiles,hostnames_regex) + sendTarfileToHosts(hostnames,options.identity_file,options.krb5_conf) + + +if __name__ == '__main__': + main() + +
