Exemple #1
0
    def GET(self):
        if not 'user' in session or session.user is None:
            f = register_form()
            return render.login(f)

        i = web.input(id=None)
        if i.id is None or not i.id.isdigit():
            return render.error("No cluster id specified or invalid one.")

        db = open_db()
        where = "id = $id"
        sql_vars = {"id": int(i.id)}
        ret = db.select("clusters", what="graph", vars=sql_vars, where=where)
        rows = list(ret)
        if len(rows) == 0:
            return render.error("Invalid cluster id.")

        g_text = rows[0]["graph"]
        g = CGraph()
        g.fromDict(json.loads(g_text))
        json_graph = graph2json(g)
        return json_graph
Exemple #2
0
    def GET(self):
        if not 'user' in session or session.user is None:
            f = register_form()
            return render.login(f)

        i = web.input(id=None)
        if i.id is None or not i.id.isdigit():
            return render.error("No cluster id specified or invalid one.")

        db = open_db()
        where = "id = $id"
        sql_vars = {"id": int(i.id)}
        ret = db.select("clusters", what="graph", vars=sql_vars, where=where)
        rows = list(ret)
        if len(rows) == 0:
            return render.error("Invalid cluster id.")

        g_text = rows[0]["graph"]
        g = CGraph()
        g.fromDict(json.loads(g_text))

        for node in list(g.nodes()):
            if node.name.startswith("New node "):
                g.renameNode(node.name,
                             node.name.replace("New node ", "Cluster "))
            else:
                data = get_sample_data(node.name)
                tmp = "%s%s"
                if data["description"] is not None:
                    tmp %= (data["description"], " - " + data["hash"])
                else:
                    tmp %= (data["hash"], "")
                g.renameNode(node.name, tmp)

        dot = g.toGml()
        return dot