예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
 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))
     ]
예제 #6
0
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)
예제 #7
0
 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)
         }
예제 #8
0
 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,
     }
예제 #9
0
 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,
     }
예제 #10
0
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)
예제 #11
0
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'))
예제 #12
0
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'))
예제 #13
0
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'))
예제 #14
0
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'))
예제 #15
0
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'))
예제 #16
0
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'))
예제 #17
0
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))
예제 #18
0
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))
예제 #19
0
 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)}
예제 #20
0
 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))]
예제 #21
0
 def _update_select(self):
     cells = Cell.select().where(Cell.type == 'RAS')
     self.cell.choices = [(c.id, c.name) for c in cells]
예제 #22
0
 def _update_select(self):
     cells = Cell.select().where(Cell.type == 'RAS')
     self.cell.choices = [(c.id, c.name) for c in cells]