diff options
Diffstat (limited to 'src/flufigut.py')
-rwxr-xr-x | src/flufigut.py | 96 |
1 files changed, 76 insertions, 20 deletions
diff --git a/src/flufigut.py b/src/flufigut.py index 4d8dbbe..72e9e7b 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -84,11 +84,13 @@ class Description: class Porter: - def __init__(self, name): + def __init__(self, name, interface, port): self.name = name + self.interface = interface + self.port = port self.socket_path = rand_string() self.username = rand_string(size=12) - self.password = rand_string(size=12) + self.password = rand_string(size=20) class Planet: @@ -266,17 +268,17 @@ class Planet: # # streams - def __create_porter(self, comp_name_base, port, interface=None): - porter_name = 'port-%s-%i' % (comp_name_base, port) + def __create_porter(self, stream, idx, port, interface=None): + comp_name = 'port-%s%i-%i' % (stream, idx + 1, port) addr = '*:%i' % (port) if interface: - porter_name = 'port-%s-%s-%i' % (comp_name_base, interface, port) + comp_name = 'port-%s%i-%s-%i' % (stream, idx + 1, interface, port) addr = '%s:%i' % (interface, port) - porter = Porter(porter_name) + porter = Porter(comp_name, interface, port) self.atmosphere[porter.name] = { 'type': "porter", - 'desc': "Porter for %s on %s" % (comp_name_base, addr), + 'desc': "Porter for %s%i on %s" % (stream, idx + 1, addr), 'worker': None, 'properties': { 'port': port, @@ -290,23 +292,77 @@ class Planet: return porter - def __generate_stream_instance(self, stream_name, stream, idx, globals): - port = stream['port'] - comp_name_base = "%s%i" % (stream_name, idx + 1) - porter = self.__create_porter(comp_name_base, port) - porter_localdup = None - if 'localdup' in stream: - porter_localdump = self.__create_porter(comp_name_base, stream['localdup']['port'], "localhost") + def __generate_stream_mux_repeater(self, stream, mux, format, profile, feeder): + comp_name = 'repeater-%s-%s-%s-%s' % (stream, mux, format, profile) + + if comp_name in self.flow['repeaters']: + return comp_name + + self.flow['repeaters'][comp_name] = { + 'type': 'repeater', + 'desc': "repeater for %s (%s %s-%s)" % (stream, mux, format, profile), + 'worker': None, + 'feeder': feeder, + } + return comp_name + + def __generate_stream_mux_instance(self, stream_name, stream, mux, format, profile, idx, cnt, porter, globals): + muxer_feed = 'muxer-%s-%s-%s' % (mux, format, profile) + feeder = muxer_feed + if 'repeater' in stream: + feeder = self.__generate_stream_mux_repeater(stream_name, mux, format, profile, muxer_feed) + + comp_name = '%s-%s%i-%s-%s-%s' % (stream['type'], stream_name, idx + 1, mux, format, profile) + mount_point = '/%s-%s-%s.%s' % (mux, format, profile, globals['formats'][format]['muxer']) + if cnt > 1: + hostname = stream['hostname'] % (idx + 1) + if idx != 0: + hostname_next = stream['hostname'] % (idx) + else: + hostname_next = stream['hostname'] % (cnt) + else: + hostname = stream['hostname'] - def _generate_streams(self, streams, globals): + self.flow['streamers'][comp_name] = { + 'type': "%s-stream" % stream['type'], + 'desc': "%s streamer for %s %s-%s (part %i of %i in %s cluster)" % (stream['type'], mux, format, profile, idx + 1, cnt, stream_name), + 'worker': None, + 'feeder': feeder, + 'properties': { + 'description': globals['description'], + 'type': 'slave', + 'porter-socket-path': porter.socket_path, + 'porter-username': porter.username, + 'porter-password': porter.password, + 'mount-point': mount_point, + 'hostname': hostname, + 'port': porter.port, + } + } + + # TODO: add support for max-con, max-bw and burst-on-connect! + # TODO: add stats!! + + def __generate_stream_instance(self, stream_name, stream, idx, cnt, muxes, globals): + port = stream['port'] + interface = None + if 'interface' in stream: + interface = stream['interface'] + porter = self.__create_porter(stream_name, idx, port, interface) + for mux_name in stream['muxes']: + for format_name, format in muxes[mux_name]['formats'].items(): + for profile_name in format: + self.__generate_stream_mux_instance(stream_name, stream, mux_name, format_name, profile_name, + idx, cnt, porter, globals) + + def _generate_streams(self, streams, muxes, globals): self.flow['repeaters'] = {} self.flow['streamers'] = {} for stream_name, stream in streams.items(): - streamer_cnt = stream['count'] - for idx in range(streamer_cnt): - print(stream) - self.__generate_stream_instance(stream_name, stream, idx, globals) + cnt = stream['count'] + for idx in range(cnt): + self.__generate_stream_instance(stream_name, stream, idx, cnt, muxes, globals) # # records @@ -338,7 +394,7 @@ class Planet: def generate(self, desc): self._generate_inputs(desc.inputs, desc.globals) self._generate_muxes(desc.muxes, desc.inputs, desc.globals) - self._generate_streams(desc.streams, desc.globals) + self._generate_streams(desc.streams, desc.muxes, desc.globals) self._generate_records(desc.records, desc.globals) |