def create(self, grpid): tgt = RasTarget() group = RasGroup.get(RasGroup.id == self.group.data) tgt.name = group.name tgt.group = grpid tgt.type = 'ras' tgt.path = '{app}/{grp}'.format(app='RasEye', grp=group.name) tgt.comment = self.comment.data tgt.save()
def create(self, grpid): tgt = RasTarget() tgt.name = self.name.data tgt.group = grpid tgt.type = 'app' tgt.path = '{app}/{name}'.format(app=self.application.data, name=self.name.data) tgt.comment = self.comment.data tgt.save()
def create(self, grpid): logger.debug("CREATE: {}".format(grpid)) tgt = RasTarget() cell = Cell.get(Cell.id == self.cell.data) tgt.name = cell.name tgt.group = grpid tgt.type = 'cell' tgt.path = '{app}/{cell}'.format(app=cell.get_appname(), cell=cell.name) tgt.comment = self.comment.data tgt.save()
def delete(cls, id): tgt = RasTarget.get(RasTarget.id == id) with database.database.atomic(): for act in tgt.actions: RasActionForm.delete(act.id) tgt.delete_instance() tgt.teardown()
def _update_selectfield(self): registerd = RasTarget.select( RasTarget.name).where(RasTarget.type == 'cell') self.cell.choices = [ (c.id, c.name) for c in Cell.select().where(Cell.name.not_in(registerd)) ]
def _update_selectfield(self): registerd = RasTarget.select( RasTarget.name).where(RasTarget.type == 'ras') self.group.choices = [ (g.id, g.name) for g in RasGroup.select().where(RasGroup.name.not_in(registerd)) ]
def create(self, grpid): tgt = RasTarget() tgt.name = self.name.data tgt.group = grpid tgt.type = 'app' tgt.path = '{app}/{name}'.format( app=self.application.data, name=self.name.data) tgt.comment = self.comment.data tgt.save()
def rasact_create(grpid, tgtid, atype): form = _ACTION_FORMS[atype]() tgt = RasTarget.get(RasTarget.id == tgtid) return render_template('ras/action_create.html', form=form, grpid=grpid, target=tgt, atype=atype)
def regist_ras_eye(self, group): logger.debug("REGIST RAS: {}".format(group)) tgt = RasTargetRasForm(data={'type': 'ras', 'group': group.id}) tgt.create(group.id) tobj = RasTarget.select().where((RasTarget.name == group.name) & ( RasTarget.type == 'ras') & (RasTarget.group == group.id)).first() act = RasActionRestartForm(data={'type': 'restart', 'name': 'restart'}) act.create(tobj.id)
def match(cls, event): from cellconfig.ras.model import RasTarget if _event_name2task(event['name']) not in cls.EVENTS: return False cell = event['target'] count = RasTarget.select().where( (RasTarget.type == 'cell') & (RasTarget.name == cell.name)).count() return count > 0
def match(cls, event): from cellconfig.ras.model import RasTarget if _event_name2task(event['name']) not in cls.EVENTS: return False cell = event['target'] count = RasTarget.select().where((RasTarget.type == 'cell') & ( RasTarget.name == cell.name)).count() return count > 0
def rastgt_delete(grpid, typ, tgtid): tgt = RasTarget.get(RasTarget.id == tgtid) fclass = _TARGET_FORMS[typ] form = fclass(data=fclass.obj2dict(tgt)) return render_template( 'ras/target_delete.html', form=form, grpid=grpid, typ=typ, tgtid=tgtid, group_name=tgt.group.name)
def exist_restart_action(self, cell): tgts = RasTarget.select().where((RasTarget.name == cell.name) & (RasTarget.type == 'cell')) for tgt in tgts: acts = RasAction.select().where((RasAction.target == tgt.id) & ( RasAction.type == 'restart')).first() if acts is not None: return True return False
def create(self, grpid): logger.debug("CREATE: {}".format(grpid)) tgt = RasTarget() cell = Cell.get(Cell.id == self.cell.data) tgt.name = cell.name tgt.group = grpid tgt.type = 'cell' tgt.path = '{app}/{cell}'.format( app=cell.get_appname(), cell=cell.name) tgt.comment = self.comment.data tgt.save()
def rastgt_delete(grpid, typ, tgtid): tgt = RasTarget.get(RasTarget.id == tgtid) fclass = _TARGET_FORMS[typ] form = fclass(data=fclass.obj2dict(tgt)) return render_template('ras/target_delete.html', form=form, grpid=grpid, typ=typ, tgtid=tgtid, group_name=tgt.group.name)
def regist_ras_eye(self, group): logger.debug("REGIST RAS: {}".format(group)) tgt = RasTargetRasForm(data={'type': 'ras', 'group': group.id}) tgt.create(group.id) tobj = RasTarget.select().where( (RasTarget.name == group.name) & (RasTarget.type == 'ras') & (RasTarget.group == group.id)).first() act = RasActionRestartForm(data={'type': 'restart', 'name': 'restart'}) act.create(tobj.id)
def _start(self, cell, nodes): from cellconfig.ras.model import RasTarget tgts = RasTarget.select().where( (RasTarget.type == 'cell') & (RasTarget.name == cell.name) & RasTarget.enabled) for tgt in tgts: logger.debug("RasCluster {}".format(tgt.name)) self._execute_fab( task=fabfile.setup_cell, nodes=nodes, cell=cell, ras_cell=tgt.group.cell.name, path=tgt.path, warn_only=False)
def exist_restart_action(self, cell): tgts = RasTarget.select().where( (RasTarget.name == cell.name) & (RasTarget.type == 'cell')) for tgt in tgts: acts = RasAction.select().where( (RasAction.target == tgt.id) & (RasAction.type == 'restart')).first() if acts is not None: return True return False
def _save(self, action, tgtid, script_data=None): tgt = RasTarget.get(RasTarget.id == tgtid) action.target = tgtid action.name = self.name.data action.mode = 1 << 1 action.type = 'restart' action.data = json.dumps( {'type': tgt.type, 'retry': int(self.retry.data), 'interval': int(self.interval.data)}) action.save()
def regist_ras_cell(self, group): cell = group.cell if self.exist_restart_action(cell): return logger.debug("REGIST CELL: {}".format(cell)) tgt = RasTargetCellForm(data={'type': 'cell', 'cell': cell.id}) tgt.create(group.id) tobj = RasTarget.select().where((RasTarget.name == cell.name) & ( RasTarget.type == 'cell') & (RasTarget.group == group.id)).first() act = RasActionRestartForm(data={'type': 'restart', 'name': 'restart'}) act.create(tobj.id)
def rasact_list(grpid, tgtid): atype = request.form['type'] form = _ACTION_FORMS[atype](request.form) if not form.validate(): tgt = RasTarget.get(RasTarget.id == tgtid) return render_template( 'ras/action_create.html', form=form, grpid=grpid, target=tgt, atype=atype) script = request.files['script'] if 'script' in request.files else None form.create(tgtid, script) return redirect(url_for( 'rastgt_detail', grpid=grpid, tgtid=tgtid))
def _save(self, action, tgtid, script_data=None): tgt = RasTarget.get(RasTarget.id == tgtid) action.target = tgtid action.name = self.name.data action.mode = 1 << 1 action.type = 'restart' action.data = json.dumps({ 'type': tgt.type, 'retry': int(self.retry.data), 'interval': int(self.interval.data) }) action.save()
def enable(self, event): from cellconfig.ras.model import RasTarget ras = event['target'] task = _event_name2task(event['name']) if task == 'status': for tgt in ras.targets: self._send_signal(self.signal, tgt) elif task == 'server_status': tgt = RasTarget.select().where((RasTarget.type == 'ras') & ( RasTarget.name == ras.name)).first() if tgt is not None: self._send_server_signal(self.signal, tgt, ras)
def regist_ras_cell(self, group): cell = group.cell if self.exist_restart_action(cell): return logger.debug("REGIST CELL: {}".format(cell)) tgt = RasTargetCellForm(data={'type': 'cell', 'cell': cell.id}) tgt.create(group.id) tobj = RasTarget.select().where( (RasTarget.name == cell.name) & (RasTarget.type == 'cell') & (RasTarget.group == group.id)).first() act = RasActionRestartForm(data={'type': 'restart', 'name': 'restart'}) act.create(tobj.id)
def ras_action_info(clst, app, name): ras = RasGroup.select().where(RasGroup.name == clst).first() if ras is None: abort(404) actions = [] tgts = RasTarget.select().where((RasTarget.path == '/'.join([app, name])) & (RasTarget.group == ras.id)) for tgt in tgts: for act in tgt.actions: aparams = {'name': act.name, 'mode': act.mode, 'action': act.type} aparams.update(json.loads(act.data)) actions.append(aparams) return jsonify(actions)
def rasact_list(grpid, tgtid): atype = request.form['type'] form = _ACTION_FORMS[atype](request.form) if not form.validate(): tgt = RasTarget.get(RasTarget.id == tgtid) return render_template('ras/action_create.html', form=form, grpid=grpid, target=tgt, atype=atype) script = request.files['script'] if 'script' in request.files else None form.create(tgtid, script) return redirect(url_for('rastgt_detail', grpid=grpid, tgtid=tgtid))
def enable(self, event): from cellconfig.ras.model import RasTarget ras = event['target'] task = _event_name2task(event['name']) if task == 'status': for tgt in ras.targets: self._send_signal(self.signal, tgt) elif task == 'server_status': tgt = RasTarget.select().where( (RasTarget.type == 'ras') & (RasTarget.name == ras.name)).first() if tgt is not None: self._send_server_signal(self.signal, tgt, ras)
def ras_report(app, name, no): from cellconfig.agents.ras.rasagent import RasEvent, CellEvent rsig = blinker.signal('ras:status') ssig = blinker.signal('ras:server_status') csig = blinker.signal('cell:status') tgts = RasTarget.select().where(RasTarget.path == '/'.join([app, name])) for tgt in tgts: RasEvent._send_signal(rsig, tgt) if tgt.type == 'cell': CellEvent._send_signal(csig, tgt.name, tgt) elif tgt.type == 'ras': ras = RasGroup.select().where(RasGroup.name == tgt.name).first() RasEvent._send_server_signal(ssig, tgt, ras) return make_response('ok')
def ras_action_info(clst, app, name): ras = RasGroup.select().where(RasGroup.name == clst).first() if ras is None: abort(404) actions = [] tgts = RasTarget.select().where( (RasTarget.path == '/'.join([app, name])) & (RasTarget.group == ras.id)) for tgt in tgts: for act in tgt.actions: aparams = {'name': act.name, 'mode': act.mode, 'action': act.type} aparams.update(json.loads(act.data)) actions.append(aparams) return jsonify(actions)
def start(self): self._execute_fab(fabfile.start_server, nodes=[self.target], group=self.target.group.name, warn_only=False) for tgt in self.target.group.targets: self._set_event(tgt) from cellconfig.ras.model import RasTarget tgts = RasTarget.select().where((RasTarget.type == 'ras') & ( RasTarget.name == self.target.group.name) & RasTarget.enabled) for tgt in tgts: logger.debug("Ras RegistME {}".format(tgt.name)) self._execute_fab( task=fabfile.setup_ras, nodes=[self.target], group=self.target.group.name, ras_cell=self.target.group.cell.name, ) logger.debug("START SERVER: success")
def start(self): self._execute_fab( fabfile.start_server, nodes=[self.target], group=self.target.group.name, warn_only=False) for tgt in self.target.group.targets: self._set_event(tgt) from cellconfig.ras.model import RasTarget tgts = RasTarget.select().where( (RasTarget.type == 'ras') & (RasTarget.name == self.target.group.name) & RasTarget.enabled) for tgt in tgts: logger.debug("Ras RegistME {}".format(tgt.name)) self._execute_fab( task=fabfile.setup_ras, nodes=[self.target], group=self.target.group.name, ras_cell=self.target.group.cell.name, ) logger.debug("START SERVER: success")
def enable(self, event): from cellconfig.ras.model import RasTarget cell = event['target'] tgt = RasTarget.select().where((RasTarget.type == 'cell') & (RasTarget.name == cell.name)).first() self._send_signal(self.signal, cell.name, tgt)
def delete_nonexists_target(cls, _type, name): tgts = RasTarget.select().where( (RasTarget.type == _type) & (RasTarget.name == name)) for tgt in tgts: RasTargetForm.delete(tgt.id)
def rasact_create(grpid, tgtid, atype): form = _ACTION_FORMS[atype]() tgt = RasTarget.get(RasTarget.id == tgtid) return render_template( 'ras/action_create.html', form=form, grpid=grpid, target=tgt, atype=atype)
def _update_selectfield(self): registerd = RasTarget.select(RasTarget.name).where( RasTarget.type == 'cell') self.cell.choices = [ (c.id, c.name) for c in Cell.select().where(Cell.name.not_in(registerd))]
def rastgt_detail(grpid, tgtid): tgt = RasTarget.get(RasTarget.id == tgtid) return render_template('ras/target_show.html', target=tgt)
def _update_selectfield(self): registerd = RasTarget.select(RasTarget.name).where( RasTarget.type == 'ras') self.group.choices = [ (g.id, g.name) for g in RasGroup.select().where(RasGroup.name.not_in(registerd))]
def enable(self, event): from cellconfig.ras.model import RasTarget cell = event['target'] tgt = RasTarget.select().where( (RasTarget.type == 'cell') & (RasTarget.name == cell.name)).first() self._send_signal(self.signal, cell.name, tgt)
def delete_nonexists_target(cls, _type, name): tgts = RasTarget.select().where((RasTarget.type == _type) & (RasTarget.name == name)) for tgt in tgts: RasTargetForm.delete(tgt.id)