def api_cnode_state_by_name(name, no): query = Cell.select().where(Cell.name == name) try: id = query[0].id except: abort(404) return api_cnode_state(id, no)
def api_cell_detail_by_name(name): query = Cell.select().where(Cell.name == name) try: id = query[0].id except: abort(404) return api_cell_detail(id)
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 query_cell_all_list(): query = Cell.select().dicts() cell_list = [] for cell in query: cell_list.append(cell) cell['url'] = url_for('api_cell_detail', id=cell['id'], _external=True) return jsonify(cell=cell_list)
def _cell_status(self): cell_name = self.target.name from cellconfig.model import Cell cell = Cell.select().where(Cell.name == cell_name).first() try: st = self._get_status( self.target.group.cell.name, '/RAS/{}/{}'.format(cell.get_appname(), cell.name), cell.nodes) if st['running'] == st['total']: status = 'running' elif st['running'] == 0: status = 'stopped' elif st['running'] >= (st['total'] + 1) // 2: status = 'warning' else: status = 'error' st.update({'cid': cell.id, 'name': cell.name, 'status': status}) return st except Exception as e: logger.exception(e) return { 'cid': cell.id, 'name': cell.name, 'status': 'unknown', 'total': len(cell.nodes) }
def obj2dict(cls, obj): cell = Cell.select().where(Cell.name == obj.name).first() logger.debug("CELL ID: {}".format(cell.id)) return { 'type': 'cell', 'cell': cell.id, 'comment': obj.comment, }
def cell_list(): if request.method == 'GET': cells = Cell.select().where(Cell.type != 'RAS') return render_template('cell_list.html', cells=cells) elif request.method == 'POST': form = CellForm(request.form) if not (form.validate() and form.create()): return render_template('cell_create.html', form=form) return redirect(url_for('cell_list'))
def rascell_list(): if request.method == 'GET': cells = Cell.select().where(Cell.type == 'RAS') return render_template('ras/cell_list.html', cells=cells) elif request.method == 'POST': form = RasCellForm(request.form) if not form.validate(): return render_template('ras/cell_create.html', form=form) form.create() return redirect(url_for('rasgrp_list'))
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 cell_list_event(): listener = EventListener('cell:status') cells = Cell.select() events = [{'name': 'status;{}'.format(cell.name), 'target': cell} for cell in cells] 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 cell_list_event(): listener = EventListener('cell:status') cells = Cell.select() events = [{ 'name': 'status;{}'.format(cell.name), 'target': cell } for cell in cells] 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 _cell_status(self): cell_name = self.target.name from cellconfig.model import Cell cell = Cell.select().where(Cell.name == cell_name).first() try: st = self._get_status( self.target.group.cell.name, '/RAS/{}/{}'.format(cell.get_appname(), cell.name), cell.nodes) if st['running'] == st['total']: status = 'running' elif st['running'] == 0: status = 'stopped' elif st['running'] >= (st['total'] + 1) // 2: status = 'warning' else: status = 'error' st.update({'cid': cell.id, 'name': cell.name, 'status': status}) return st except Exception as e: logger.exception(e) return {'cid': cell.id, 'name': cell.name, 'status': 'unknown', 'total': len(cell.nodes)}
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_select(self): cells = Cell.select().where(Cell.type == 'RAS') self.cell.choices = [(c.id, c.name) for c in cells]