Ejemplo n.º 1
0
 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))
     ]
Ejemplo n.º 2
0
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'))
Ejemplo n.º 3
0
 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,
     }
Ejemplo n.º 4
0
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'))
Ejemplo n.º 5
0
 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,
     }
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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()
Ejemplo n.º 8
0
 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()
Ejemplo n.º 9
0
 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()
Ejemplo n.º 10
0
 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()
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
 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()
Ejemplo n.º 13
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'))
Ejemplo n.º 14
0
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')
Ejemplo n.º 15
0
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)
Ejemplo n.º 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'))
Ejemplo n.º 17
0
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')
Ejemplo n.º 18
0
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))
Ejemplo n.º 19
0
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))
Ejemplo n.º 20
0
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))
Ejemplo n.º 21
0
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))
Ejemplo n.º 22
0
 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)}
Ejemplo n.º 23
0
 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)
         }
Ejemplo n.º 24
0
 def get_group_name(self, id):
     grp = RasGroup.get(RasGroup.id == id)
     return grp.name
Ejemplo n.º 25
0
 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))]
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
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)
Ejemplo n.º 29
0
 def create(self, url):
     group = RasGroup()
     self.populate_obj(group)
     group.id = None
     group.save(url=url)
     return group
Ejemplo n.º 30
0
 def create(self, url):
     group = RasGroup()
     self.populate_obj(group)
     group.id = None
     group.save(url=url)
     return group
Ejemplo n.º 31
0
 def get_group_name(self, id):
     grp = RasGroup.get(RasGroup.id == id)
     return grp.name
Ejemplo n.º 32
0
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)