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 rasgrp_detail(id): if request.method == 'GET': group = RasGroup.get(RasGroup.id == id) return render_template('ras/group_show.html', group=group) elif request.method == 'POST': if request.form['operation'] == 'Delete': RasGroupForm.delete(id) return redirect(url_for('rasgrp_list'))
def obj2dict(cls, obj): grp = RasGroup.select().where(RasGroup.name == obj.name).first() logger.debug("RasGroup ID: {}".format(grp.id)) return { 'type': 'ras', 'group': grp.id, 'comment': obj.comment, }
def delete(cls, id): grp = RasGroup.get(RasGroup.id == id) with database.database.atomic(): RasTargetForm.delete_nonexists_target('ras', grp.name) for tgt in grp.targets: RasTargetForm.delete(tgt.id) for srv in grp.servers: RasServerForm.delete(srv.id) grp.delete_instance()
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): srv = RasServer() self.populate_obj(srv) srv.id = None last_no = RasServer.select(fn.Max( RasServer.no)).where(RasServer.group == grpid).scalar() srv.no = last_no + 1 if last_no is not None else 0 srv.group = grpid if len(srv.group.servers) == 0: grp = RasGroup.get(RasGroup.id == grpid) srv.save(callback=lambda: self.regist_auto_target(grp)) else: srv.save()
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 create(self, grpid): srv = RasServer() self.populate_obj(srv) srv.id = None last_no = RasServer.select( fn.Max(RasServer.no)).where(RasServer.group == grpid).scalar() srv.no = last_no + 1 if last_no is not None else 0 srv.group = grpid if len(srv.group.servers) == 0: grp = RasGroup.get(RasGroup.id == grpid) srv.save(callback=lambda: self.regist_auto_target(grp)) else: srv.save()
def rasgrp_list(): if request.method == 'GET': if Cell.select().where(Cell.type == 'RAS').count() == 0: return redirect(url_for('rascell_list')) grps = RasGroup.select() return render_template('ras/ras_index.html', groups=grps) elif request.method == 'POST': form = RasGroupForm(request.form) if not form.validate(): return render_template('ras/group_create.html', form=form) logger.debug('URL: {}'.format(request.url_root)) grp = form.create(request.url_root) logger.debug('GROUP: {}'.format(str(grp))) return redirect(url_for('rasgrp_list'))
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 ras_event(): listener = EventListener('ras:status') events = [ {'name': 'status;{}'.format(ras.name), 'target': ras} for ras in RasGroup.select()] def setup(_callback): listener.regist(_callback) for ev in events: listener.enable(ev) def teardown(_callback): listener.unregist(_callback) for ev in events: listener.disable(ev) return _make_sse_response(_generator(setup, teardown))
def ras_event(): listener = EventListener('ras:status') events = [{ 'name': 'status;{}'.format(ras.name), 'target': ras } for ras in RasGroup.select()] def setup(_callback): listener.regist(_callback) for ev in events: listener.enable(ev) def teardown(_callback): listener.unregist(_callback) for ev in events: listener.disable(ev) return _make_sse_response(_generator(setup, teardown))
def ras_clst_event(id): ras = RasGroup.get(RasGroup.id == id) params = [] for op in ['status', 'server_status']: params.append( (EventListener('ras:{}'.format(op), source=ras.name), {'name': op, 'target': ras})) def setup(_callback): for (listener, event) in params: listener.regist(_callback) listener.enable(event) def teardown(_callback): for (listener, event) in params: listener.unregist(_callback) listener.disable(event) return _make_sse_response(_generator(setup, teardown))
def ras_clst_event(id): ras = RasGroup.get(RasGroup.id == id) params = [] for op in ['status', 'server_status']: params.append((EventListener('ras:{}'.format(op), source=ras.name), { 'name': op, 'target': ras })) def setup(_callback): for (listener, event) in params: listener.regist(_callback) listener.enable(event) def teardown(_callback): for (listener, event) in params: listener.unregist(_callback) listener.disable(event) return _make_sse_response(_generator(setup, teardown))
def _ras_status(self): group_name = self.target.name from cellconfig.ras.model import RasServer, RasGroup group = RasGroup.select().where(RasGroup.name == group_name).first() srvs = RasServer.select().where(RasServer.group == group.id) try: st = self._get_status( group.cell.name, '/RAS/RasEye/{}'.format(group.name), srvs) if st['running'] == st['total']: status = 'running' elif st['running'] == 0: status = 'stopped' else: status = 'warning' st.update({'cid': group.id, 'name': group.name, 'status': status}) return st except Exception as e: logger.exception(e) return {'cid': group.id, 'name': group.name, 'status': 'unknown', 'total': len(srvs)}
def _ras_status(self): group_name = self.target.name from cellconfig.ras.model import RasServer, RasGroup group = RasGroup.select().where(RasGroup.name == group_name).first() srvs = RasServer.select().where(RasServer.group == group.id) try: st = self._get_status(group.cell.name, '/RAS/RasEye/{}'.format(group.name), srvs) if st['running'] == st['total']: status = 'running' elif st['running'] == 0: status = 'stopped' else: status = 'warning' st.update({'cid': group.id, 'name': group.name, 'status': status}) return st except Exception as e: logger.exception(e) return { 'cid': group.id, 'name': group.name, 'status': 'unknown', 'total': len(srvs) }
def get_group_name(self, id): grp = RasGroup.get(RasGroup.id == id) return grp.name
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 rasgrp_delete(id): grp = RasGroup.get(RasGroup.id == id) form = RasGroupForm(data=RasGroupForm.obj2dict(grp)) return render_template('ras/group_delete.html', form=form, id=id)
def api_ras_srv_state_by_name(name, no): grp = RasGroup.select().where(RasGroup.name == name).first() if grp is None: logger.debug("SRV 404") abort(404) return api_ras_srv_state(grp.id, no)
def create(self, url): group = RasGroup() self.populate_obj(group) group.id = None group.save(url=url) return group