Created
October 21, 2014 21:26
-
-
Save quiffman/6a35cd72a6e166ea0a60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
def which(program): | |
import os | |
def is_exe(fpath): | |
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | |
fpath, fname = os.path.split(program) | |
if fpath: | |
if is_exe(program): | |
return program | |
else: | |
for path in os.environ["PATH"].split(os.pathsep): | |
path = path.strip('"') | |
exe_file = os.path.join(path, program) | |
if is_exe(exe_file): | |
return exe_file | |
return None | |
import imp | |
imp.load_source("le", which("le")) | |
from le import * | |
import json | |
def cmd_export_to_hiera(args): | |
config.load() | |
config.agent_key_required() | |
no_more_args(args) | |
prefix = 'le_' | |
if len(args) > 0: | |
prefix = args[0] | |
hostTokens = {} | |
hosts = request_hosts() | |
for h in hosts: | |
key = h['key'] | |
name = h['hostname'] | |
host = request( 'hosts/%s/'%key, True, True) | |
logs = host['list'] | |
for ilog in logs: | |
if ilog['type'] == 'token': | |
hostTokens[name] = {} | |
hostTokens[name][ilog['name']] = ilog['token'] | |
print json.dumps(hostTokens) | |
def get_response(operation, addr, data=None, headers={'Connection':'keep-alive'}, silent=False, die_on_error=True, domain=Domain.API): | |
return le.get_response(operation, addr, data, headers, silent, die_on_error, domain) | |
if __name__ == '__main__': | |
# Read command line parameters | |
args = config.process_params( sys.argv[1:]) | |
if config.debug: | |
log.setLevel( logging.DEBUG) | |
if config.debug_system: | |
die( system_detect( True)) | |
if config.debug_loglist: | |
die( collect_log_names( system_detect( True))) | |
cmd_export_to_hiera(args) | |
# vim: set ts=4 sw=4 tw=0 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment