Created
March 17, 2016 15:35
-
-
Save ragingbal/15924f0746dc34f5ca47 to your computer and use it in GitHub Desktop.
Sample with Jinja simple, returning json, calling system commands
This file contains hidden or 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
| import json | |
| from jinja2 import Template | |
| import glob, os | |
| from subprocess import call | |
| def listProviders(): | |
| path = 'providers' | |
| plugins = glob.glob(os.path.join(path, '*')) | |
| p = dict() | |
| l= list() | |
| for plugin in plugins: | |
| if plugin != None: | |
| l.append(plugin.replace('providers/', '')) | |
| p['providers'] = l | |
| return(json.dumps(p)) | |
| def downloadSampleConfig(arg): | |
| file = open('config.sample', 'r') | |
| return (file.read()) | |
| def start(): | |
| file = open('start.model', 'r') | |
| return (file.read()) | |
| def install(): | |
| call(["terraform", "plan"]) | |
| def validateConfigAndInstall(arg): | |
| json1_file = open('config.sample', 'r') | |
| json1_str = json1_file.read() | |
| configs = json.loads(json1_str) | |
| print(configs['provider']) | |
| os.chdir('providers/' + configs['provider']) | |
| for file in glob.glob("*"): | |
| print(file) | |
| contents = open(file, 'r').read() | |
| template = Template(contents) | |
| print(template.render(configs)) | |
| target = open('../../cluster/' + file, 'w+') | |
| target.write(template.render(configs)) | |
| os.chdir('../../cluster') | |
| install() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment