Skip to content

Instantly share code, notes, and snippets.

@ragingbal
Created March 17, 2016 15:35
Show Gist options
  • Select an option

  • Save ragingbal/15924f0746dc34f5ca47 to your computer and use it in GitHub Desktop.

Select an option

Save ragingbal/15924f0746dc34f5ca47 to your computer and use it in GitHub Desktop.
Sample with Jinja simple, returning json, calling system commands
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