Esempio n. 1
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()
Esempio n. 2
0
 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()
Esempio n. 3
0
 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()
Esempio n. 4
0
 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()
Esempio n. 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))
     ]
Esempio n. 6
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))
     ]
Esempio n. 7
0
 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()
Esempio n. 8
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()
Esempio n. 9
0
 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()
Esempio n. 10
0
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)
Esempio n. 11
0
 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)
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
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)
Esempio n. 15
0
 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
Esempio n. 16
0
 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()
Esempio n. 17
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)
Esempio n. 18
0
 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)
Esempio n. 19
0
 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)
Esempio n. 20
0
 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
Esempio n. 21
0
 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()
Esempio n. 22
0
 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)
Esempio n. 23
0
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))
Esempio n. 24
0
 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()
Esempio n. 25
0
 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)
Esempio n. 26
0
 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)
Esempio n. 27
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)
Esempio n. 28
0
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))
Esempio n. 29
0
 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)
Esempio n. 30
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')
Esempio n. 31
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)
Esempio n. 32
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')
Esempio n. 33
0
 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")
Esempio n. 34
0
 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")
Esempio n. 35
0
 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)
Esempio n. 36
0
 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)
Esempio n. 37
0
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)
Esempio n. 38
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))]
Esempio n. 39
0
def rastgt_detail(grpid, tgtid):
    tgt = RasTarget.get(RasTarget.id == tgtid)
    return render_template('ras/target_show.html', target=tgt)
Esempio n. 40
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))]
Esempio n. 41
0
 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)
Esempio n. 42
0
 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)
Esempio n. 43
0
def rastgt_detail(grpid, tgtid):
    tgt = RasTarget.get(RasTarget.id == tgtid)
    return render_template('ras/target_show.html', target=tgt)