summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorequinox <equinox@88d0365b-309c-4eec-8061-d8e0c04ad69e>2012-09-27 01:50:51 +0000
committerequinox <equinox@88d0365b-309c-4eec-8061-d8e0c04ad69e>2012-09-27 01:50:51 +0000
commita08da99312e721434589185f13957261c8501b7f (patch)
tree255ac90d36fa8e4ce4a2521f7494618b97a1df3e /src
parentupdated flufig structure (diff)
porter generation works
git-svn-id: https://svn.spreadspace.org/flufigut/trunk@9 88d0365b-309c-4eec-8061-d8e0c04ad69e
Diffstat (limited to 'src')
-rwxr-xr-xsrc/flufig.py50
-rw-r--r--src/test.json10
2 files changed, 51 insertions, 9 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'])
diff --git a/src/test.json b/src/test.json
index eba2d36..23f9a18 100644
--- a/src/test.json
+++ b/src/test.json
@@ -20,7 +20,7 @@
"low": { "video": "360p25", "audio": 96 }
},
"machines": {
- "titan": [ "input", "muxer", "encoder-vorbis", "encoder-aac", "streamer0" ],
+ "titan": [ "input", "encoder-vorbis", "encoder-aac", "muxer", "streamer0" ],
"calypso": [ "encoder-h264" ],
"telesto": [ "encoder-vp8" ],
"elevate1": [ "streamer1" ],
@@ -49,16 +49,16 @@
},
"streamer": [
{ "flash": [ "high", "medium", "low" ], "webm": [ "high", "medium", "low" ], "ogg-audio": [ "high" ],
- "config": { "max-con": 5 }
+ "config": { "port": 8000, "max-con": 5 }
},
{ "flash": [ "high", "medium", "low" ], "webm": [ "high", "medium", "low" ],
- "config": { "max-bw": 290000, "next": 2 }
+ "config": { "port": 8000, "max-bw": 290000, "next": 2 }
},
{ "flash": [ "high", "medium", "low" ], "webm": [ "high", "medium", "low" ],
- "config": { "max-bw": 290000, "next": 3 }
+ "config": { "port": 8000, "max-bw": 290000, "next": 3 }
},
{ "flash": [ "high", "medium", "low" ], "webm": [ "high", "medium", "low" ],
- "config": { "max-bw": 290000, "next": 1 }
+ "config": { "port": 8000, "max-bw": 290000, "next": 1 }
}
]
}