예제 #1
0
 def delete(cls, id):
     with database.database.atomic():
         cell = Cell.get(Cell.id == id)
         try:
             from .ras.forms import RasTargetForm
             RasTargetForm.delete_nonexists_target('cell', cell.name)
         except Exception as e:
             logger.exception(e)
         cell.delete_instance()
         CellNode.delete().where(CellNode.cell == id).execute()
예제 #2
0
 def delete(cls, id):
     with database.database.atomic():
         cell = Cell.get(Cell.id == id)
         try:
             from .ras.forms import RasTargetForm
             RasTargetForm.delete_nonexists_target('cell', cell.name)
         except Exception as e:
             logger.exception(e)
         cell.delete_instance()
         CellNode.delete().where(CellNode.cell == id).execute()
예제 #3
0
 def _pop_cnode(self, num):
     cnode_list = []
     for i in range(num):
         cnode = CellNode()
         nform = self.nodes.pop_entry()
         nform.form.populate_obj(cnode)
         cnode_list.insert(0, cnode)
     return cnode_list
예제 #4
0
def api_cnode_detail(cid, no):
    cnode = CellNode.select().where((CellNode.no == no)
                                    & (CellNode.cell == cid)).dicts().first()
    if cnode is not None:
        node = Node.select().where(Node.id == cnode['node']).dicts().first()
        cnode['node'] = node
        return jsonify(cell_node=cnode)
    else:
        abort(404)
예제 #5
0
def api_cnode_detail(cid, no):
    cnode = CellNode.select().where(
        (CellNode.no == no) & (CellNode.cell == cid)).dicts().first()
    if cnode is not None:
        node = Node.select().where(Node.id == cnode['node']).dicts().first()
        cnode['node'] = node
        return jsonify(cell_node=cnode)
    else:
        abort(404)
예제 #6
0
 def _save_cnode(self, nform, nid, idx, cell):
     cnode = CellNode()
     nform.form.populate_obj(cnode)
     cnode.id = nid
     cnode.no = idx
     cnode.cell = cell
     try:
         cnode.save()
         return True
     except IntegrityError as e:
         logger.error(str(e))
         if string.find(e.message, 'tcp') >= 0:
             nform.form.tcp_port.errors.append(e.message)
         elif string.find(e.message, 'udp') >= 0:
             nform.form.udp_port.errors.append(e.message)
         else:
             self.name.errors.append(e.message)
예제 #7
0
def api_cnode_state(cid, no):
    cnode = CellNode.select().where((CellNode.no == no)
                                    & (CellNode.cell == cid)).first()
    if cnode is None:
        abort(404)

    if request.method == 'GET':
        return jsonify(cell_node=cnode.get_current_status())
    if request.method == 'PUT':
        params = request.get_json()
        op = params['operation']
        if op == 'start':
            cnode.start(params)
            return jsonify(cell_node=cnode.get_current_status())
        elif op == 'stop':
            cnode.stop(params)
            return jsonify(cell_node=cnode.get_current_status())
        else:
            abort(400)
예제 #8
0
def api_cnode_state(cid, no):
    cnode = CellNode.select().where(
        (CellNode.no == no) & (CellNode.cell == cid)).first()
    if cnode is None:
        abort(404)

    if request.method == 'GET':
        return jsonify(cell_node=cnode.get_current_status())
    if request.method == 'PUT':
        params = request.get_json()
        op = params['operation']
        if op == 'start':
            cnode.start(params)
            return jsonify(cell_node=cnode.get_current_status())
        elif op == 'stop':
            cnode.stop(params)
            return jsonify(cell_node=cnode.get_current_status())
        else:
            abort(400)
예제 #9
0
def api_cell_update(id, jcell):
    with database.database.atomic():
        cell = Cell.get(Cell.id == id)
        jnodes = jcell['nodes']
        del jcell['nodes']
        _update_model(Cell, cell, jcell)
        cell.save()
        cnids = [jcnode['id'] for jcnode in jnodes if 'id' in jcnode]
        for cnode in cell.nodes:
            if cnode.id not in cnids:
                cnode.delete_instance()
        for jcnode in jnodes:
            if 'id' in jcnode:
                cnode = CellNode.get(CellNode.id == jcnode['id'])
                _update_model(CellNode, cnode, jcnode)
            else:
                jcnode['cell'] = cell.id
                cnode = dict_to_model(CellNode, jcnode)
            cnode.save()
        resp = jsonify(cell=_cell_to_dict(cell))
        return resp
예제 #10
0
def api_cell_update(id, jcell):
    with database.database.atomic():
        cell = Cell.get(Cell.id == id)
        jnodes = jcell['nodes']
        del jcell['nodes']
        _update_model(Cell, cell, jcell)
        cell.save()
        cnids = [jcnode['id'] for jcnode in jnodes if 'id' in jcnode]
        for cnode in cell.nodes:
            if cnode.id not in cnids:
                cnode.delete_instance()
        for jcnode in jnodes:
            if 'id' in jcnode:
                cnode = CellNode.get(CellNode.id == jcnode['id'])
                _update_model(CellNode, cnode, jcnode)
            else:
                jcnode['cell'] = cell.id
                cnode = dict_to_model(CellNode, jcnode)
            cnode.save()
        resp = jsonify(cell=_cell_to_dict(cell))
        return resp
예제 #11
0
 def _save_cnode(self, nform, nid, idx, cell):
     cnode = CellNode()
     nform.form.populate_obj(cnode)
     cnode.id = nid
     cnode.no = idx
     cnode.cell = cell
     try:
         cnode.save()
         return True
     except IntegrityError as e:
         logger.error(str(e))
         if string.find(e.message, 'tcp') >= 0:
             nform.form.tcp_port.errors.append(e.message)
         elif string.find(e.message, 'udp') >= 0:
             nform.form.udp_port.errors.append(e.message)
         else:
             self.name.errors.append(e.message)
예제 #12
0
 def tearDown(self):
     CellNode.delete().execute()
     Cell.delete().execute()
     Node.delete().execute()
예제 #13
0
 def tearDown(self):
     CellNode.delete().execute()
     Cell.delete().execute()
     Node.delete().execute()
예제 #14
0
 def insert_cnode_by_no(self, no):
     cnode_list = self._pop_cnode(len(self.nodes) - no)
     cnode_list.insert(0, CellNode())
     self._push_cnode(cnode_list)