class Alias(FooApp): name = 'alias' def __init__(self, server=None, listen_port=None): FooApp.__init__(self, server) self.data = FileStore('/tmp/apps/alias') self.aliases = {} self.baseurl = 'http://%s:%i' % (getfqdn(), listen_port) def send(self, appname, msg): for target in self.aliases[appname]: try: self.recv(msg['text'], dst=target) logging.debug('Alias %s -> %s' % (appname, target)) except: logging.error(format_exc()) def run(self): while True: self.update() sleep(60) def update(self): for name in self.data.keys(): logging.info('Registering alias %s' % name) if not name in self.aliases: self.register('%s/%s' % (self.baseurl, name), name) targets = json.loads(self.data[name]) self.aliases[name] = targets
def __init__(self, server=None, listen_port=None): FooApp.__init__(self, server) self.data = FileStore('/tmp/apps/alias') self.aliases = {} self.baseurl = 'http://%s:%i' % (getfqdn(), listen_port)