Пример #1
0
def api_node_detail(id):
    if request.method == 'GET':
        return api_node_show(id)
    elif request.method == 'PUT':
        return api_node_update(id)
    elif request.method == 'DELETE':
        Node.delete().where(Node.id == id).execute()
        return make_response('', 204)
Пример #2
0
def api_node_detail(id):
    if request.method == 'GET':
        return api_node_show(id)
    elif request.method == 'PUT':
        return api_node_update(id)
    elif request.method == 'DELETE':
        Node.delete().where(Node.id == id).execute()
        return make_response('', 204)
Пример #3
0
 def _push_cnode(self, cnode_list):
     node_list = Node.select()
     for cnode in cnode_list:
         nform = self.nodes.append_entry(cnode)
         nform['node'].choices = [(n.id, n.hostname) for n in node_list]
         if cnode._data.get('node') is not None:
             nform['node'].data = cnode.node.id
Пример #4
0
 def _push_cnode(self, cnode_list):
     node_list = Node.select()
     for cnode in cnode_list:
         nform = self.nodes.append_entry(cnode)
         nform['node'].choices = [(n.id, n.hostname) for n in node_list]
         if cnode._data.get('node') is not None:
             nform['node'].data = cnode.node.id
Пример #5
0
def _api_node_list():
    query = Node.select().dicts()
    node_list = []
    for node in query:
        node_list.append(node)
        node['url'] = url_for('api_node_detail', id=node['id'], _external=True)
    return jsonify(node=node_list)
Пример #6
0
def api_node_show(id):
    node = Node.select().where(Node.id == id).dicts().first()
    if node is not None:
        return jsonify(node=node)
    else:
        resp = jsonify(dict(status=404, error='Not Found', id=id))
        resp.status_code = 404
        return resp
Пример #7
0
def api_node_show(id):
    node = Node.select().where(Node.id == id).dicts().first()
    if node is not None:
        return jsonify(node=node)
    else:
        resp = jsonify(dict(status=404, error='Not Found', id=id))
        resp.status_code = 404
        return resp
Пример #8
0
def _api_node_list():
    query = Node.select().dicts()
    node_list = []
    for node in query:
        node_list.append(node)
        node['url'] = url_for('api_node_detail', id=node['id'],
                              _external=True)
    return jsonify(node=node_list)
Пример #9
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)
Пример #10
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)
Пример #11
0
def node_list():
    if request.method == 'GET':
        nodes = Node.select()
        return render_template('node_list.html', nodes=nodes)
    elif request.method == 'POST':
        form = NodeForm(request.form)
        if not (form.validate() and form.create()):
            return render_template('node_create.html', form=form)
        return redirect(url_for('node_list'))
Пример #12
0
def node_list():
    if request.method == 'GET':
        nodes = Node.select()
        return render_template('node_list.html', nodes=nodes)
    elif request.method == 'POST':
        form = NodeForm(request.form)
        if not (form.validate() and form.create()):
            return render_template('node_create.html', form=form)
        return redirect(url_for('node_list'))
Пример #13
0
def api_node_deploy(id):
    node = Node.get(Node.id == id)
    try:
        node.deploy_async(force=True)
    except DeployError as e:
        resp = jsonify(dict(message=str(e)))
        resp.status_code = 500
        abort(resp)
    val = model_to_dict(node)
    val['label'] = str(node)
    val['os_str'] = node.os_str()
    return jsonify(dict(node=val))
Пример #14
0
def api_node_deploy(id):
    node = Node.get(Node.id == id)
    try:
        node.deploy_async(force=True)
    except DeployError as e:
        resp = jsonify(dict(message=str(e)))
        resp.status_code = 500
        abort(resp)
    val = model_to_dict(node)
    val['label'] = str(node)
    val['os_str'] = node.os_str()
    return jsonify(dict(node=val))
Пример #15
0
def api_node_update(id):
    jdata = request.get_json()
    try:
        node = Node.get(Node.id == id)
        params = jdata['node']
        _update_model(Node, node, params)
        node.save()
        return jsonify(dict(node=model_to_dict(node)))
    except (AttributeError, ValueError, TypeError, KeyError) as e:
        resp = jsonify(dict(status=400, error=e.message, data=jdata))
        resp.status_code = 400
        return resp
Пример #16
0
def api_node_update(id):
    jdata = request.get_json()
    try:
        node = Node.get(Node.id == id)
        params = jdata['node']
        _update_model(Node, node, params)
        node.save()
        return jsonify(dict(node=model_to_dict(node)))
    except (AttributeError, ValueError, TypeError, KeyError) as e:
        resp = jsonify(dict(status=400, error=e.message, data=jdata))
        resp.status_code = 400
        return resp
Пример #17
0
 def create(self):
     node = Node()
     self.populate_obj(node)
     node.id = None
     try:
         node.check_and_save()
         node.deploy_async()
         return True
     except IntegrityError as e:
         logger.error(str(e))
         self.hostname.errors.append(e.message)
Пример #18
0
def node_detail(id):
    if request.method == 'GET':
        node = Node.get(Node.id == id)
        return render_template('node_show.html', node=node)
    elif request.method == 'POST':
        if request.form['operation'] == 'Update':
            form = NodeForm(request.form)
            if not form.validate():
                return render_template('node_update.html', form=form, id=id)
            form.update(id)
        elif request.form['operation'] == 'Delete':
            NodeForm.delete(id)
        else:
            abort(400)
        return redirect(url_for('node_list'))
Пример #19
0
def node_detail(id):
    if request.method == 'GET':
        node = Node.get(Node.id == id)
        return render_template('node_show.html', node=node)
    elif request.method == 'POST':
        if request.form['operation'] == 'Update':
            form = NodeForm(request.form)
            if not form.validate():
                return render_template('node_update.html', form=form, id=id)
            form.update(id)
        elif request.form['operation'] == 'Delete':
            NodeForm.delete(id)
        else:
            abort(400)
        return redirect(url_for('node_list'))
Пример #20
0
 def create(self):
     node = Node()
     self.populate_obj(node)
     node.id = None
     try:
         node.check_and_save()
         node.deploy_async()
         return True
     except IntegrityError as e:
         logger.error(str(e))
         self.hostname.errors.append(e.message)
Пример #21
0
def node_delete(id):
    node = Node.get(Node.id == id)
    form = NodeForm(obj=node)
    return render_template('node_delete.html', form=form, id=id)
Пример #22
0
def _exists_node(id):
    try:
        node = Node.get(Node.id == id)
    except Node.DoesNotExist:
        return False
    return True
Пример #23
0
 def _update_select(self, grpid):
     nodes0 = RasServer.select(
         RasServer.node).where(RasServer.group == grpid)
     nodes = Node.select().where(Node.id.not_in(nodes0))
     self.node.choices = [(n.id, n.hostname) for n in nodes]
Пример #24
0
 def update(self, id):
     node = Node().get(Node.id == id)
     self.populate_obj(node)
     node.check_and_save()
Пример #25
0
 def delete(cls, id):
     Node.delete().where(Node.id == id).execute()
Пример #26
0
 def tearDown(self):
     CellNode.delete().execute()
     Cell.delete().execute()
     Node.delete().execute()
Пример #27
0
def find_node_by_name(hostname):
    for hname in make_hostname_list(hostname):
        q = Node.select().where(Node.hostname == hname)
        if q.count() > 0:
            return q.first()
    return None
Пример #28
0
def index():
    if Node.select().count() > 0:
        return redirect(url_for('cell_list'))
    else:
        return redirect(url_for('node_list'))
Пример #29
0
 def tearDown(self):
     CellNode.delete().execute()
     Cell.delete().execute()
     Node.delete().execute()
Пример #30
0
def node_delete(id):
    node = Node.get(Node.id == id)
    form = NodeForm(obj=node)
    return render_template('node_delete.html', form=form, id=id)
Пример #31
0
def find_node_by_name(hostname):
    for hname in make_hostname_list(hostname):
        q = Node.select().where(Node.hostname == hname)
        if q.count() > 0:
            return q.first()
    return None
Пример #32
0
def index():
    if Node.select().count() > 0:
        return redirect(url_for('cell_list'))
    else:
        return redirect(url_for('node_list'))
Пример #33
0
 def delete(cls, id):
     Node.delete().where(Node.id == id).execute()
Пример #34
0
def get_tabs():
    if Node.select().count() > 0:
        return tabs.items()
    else:
        return collections.OrderedDict([(k, v) for k, v in tabs.items()
                                        if v[2]]).items()
Пример #35
0
 def update(self, id):
     node = Node().get(Node.id == id)
     self.populate_obj(node)
     node.check_and_save()
Пример #36
0
 def update_nodes(self):
     nodes = Node.select()
     for cnode in self.nodes:
         cnode['node'].choices = [(n.id, n.hostname) for n in nodes]
Пример #37
0
def get_tabs():
    if Node.select().count() > 0:
        return tabs.items()
    else:
        return collections.OrderedDict(
            [(k, v) for k, v in tabs.items() if v[2]]).items()
Пример #38
0
def _exists_node(id):
    try:
        node = Node.get(Node.id == id)
    except Node.DoesNotExist:
        return False
    return True
Пример #39
0
 def _update_select(self, grpid):
     nodes0 = RasServer.select(
         RasServer.node).where(RasServer.group == grpid)
     nodes = Node.select().where(Node.id.not_in(nodes0))
     self.node.choices = [(n.id, n.hostname) for n in nodes]
Пример #40
0
 def update_nodes(self):
     nodes = Node.select()
     for cnode in self.nodes:
         cnode['node'].choices = [(n.id, n.hostname) for n in nodes]