def task_generate(srv_ids=(), station_ids=()): cfg = app.settings factory = ConfigGeneratorFactory(cfg, app.mmgr) ret = [] sess = DBSession() loc = sys_localizer(app.mmgr.cfg.registry) q = sess.query(Server) if len(srv_ids) > 0: q = q.filter(Server.id.in_(srv_ids)) if len(station_ids) > 0: q = q.filter(Server.host_id.in_(station_ids)) for srv in q: gen = factory.get(srv.type.generator_name) logger.info('Generating config of type %s for host %s', srv.type.generator_name, str(srv.host)) gen.generate(srv) ret.append(loc.translate(_('Successfully generated %s configuration for host %s.')) % ( srv.type.name, str(srv.host) )) hosts = factory.deploy() ret.append(loc.translate(_('Successfully deployed configuration for hosts: %s.')) % (', '.join(hosts),)) factory.restore_umask() transaction.commit() return ret
def locale(self): return sys_localizer(self.app_config.registry)