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)
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
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)
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
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)
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)
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'))
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))
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
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)
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'))
def node_delete(id): node = Node.get(Node.id == id) form = NodeForm(obj=node) return render_template('node_delete.html', form=form, id=id)
def _exists_node(id): try: node = Node.get(Node.id == id) except Node.DoesNotExist: return False return True
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]
def update(self, id): node = Node().get(Node.id == id) self.populate_obj(node) node.check_and_save()
def delete(cls, id): Node.delete().where(Node.id == id).execute()
def tearDown(self): CellNode.delete().execute() Cell.delete().execute() Node.delete().execute()
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
def index(): if Node.select().count() > 0: return redirect(url_for('cell_list')) else: return redirect(url_for('node_list'))
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()
def update_nodes(self): nodes = Node.select() for cnode in self.nodes: cnode['node'].choices = [(n.id, n.hostname) for n in nodes]
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()