summaryrefslogtreecommitdiff
path: root/src/flufig.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/flufig.py')
-rwxr-xr-xsrc/flufig.py50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/flufig.py b/src/flufig.py
index 3c095f5..48577cc 100755
--- a/src/flufig.py
+++ b/src/flufig.py
@@ -27,22 +27,64 @@
# along with flufig. If not, see <http://www.gnu.org/licenses/>.
#
+import string
+import random
import sys
import simplejson as json
from exceptions import *
from jinja2 import Environment, FileSystemLoader
+
+def rand_string(size=8, chars=string.ascii_lowercase + string.ascii_uppercase + string.digits):
+ return ''.join(random.choice(chars) for x in range(size))
+
+
if len(sys.argv) <= 2:
- raise SystemExit("No template name and or config file given")
+ raise SystemExit("No template name and or config file given")
cf = open(sys.argv[2], 'r')
config = json.load(cf);
cf.close();
data = { 'globals' : config['globals'], 'atmosphere' : {}, 'flow' : {} }
-
-# TODO: implement generation of atmosphere and flow
-
+machines = {}
+idx = 0
+for streamer in config['streamer']:
+ worker = 'streamer%i'%(idx)
+ port = streamer['config']['port']
+ found = False
+ for machine in config['globals']['machines'].keys():
+ if worker in config['globals']['machines'][machine]:
+ if machine in machines and 'porter' in machines[machine]:
+ if port in machines[machine]['porter']:
+ print "Machine %s already uses port %i" % (machine, port)
+ sys.exit(1)
+ else:
+ machines[machine] = { 'porter': {} }
+
+ found = True
+ machines[machine]['porter'][port] = {
+ 'socket-path': "porter%i-%s"%(idx, rand_string()),
+ 'username': rand_string(size=12),
+ 'password': rand_string(size=12),
+ }
+
+ data['atmosphere']['porter%i'%idx] = {
+ 'type': "porter",
+ 'desc': "Porter for %s on port %i"%(machine, port),
+ 'worker': worker,
+ 'properties': {
+ 'port': port,
+ 'socket-path': machines[machine]['porter'][port]['socket-path'],
+ 'username': machines[machine]['porter'][port]['username'],
+ 'password': machines[machine]['porter'][port]['password'],
+ },
+ }
+ if not found:
+ print "Streamer %i has no machine assigned" % (idx)
+ sys.exit(1)
+ idx+=1
+
env = Environment(loader=FileSystemLoader('../templates/%s/' % (sys.argv[1])))
template = env.get_template('planet.xml')
planet = template.render(globals=data['globals'], atmosphere=data['atmosphere'], flow=data['flow'])