Exemple #1
0
    def lookup_nodes(self, gremlin):
        data = json.dumps({"GremlinQuery": gremlin})
        req = urllib.request.Request("http://%s/api/topology" % self.endpoint,
                                     data.encode(),
                                     {'Content-Type': 'application/json'})
        resp = urllib.request.urlopen(req)
        if resp.getcode() != 200:
            return

        data = resp.read()
        objs = json.loads(data.decode())
        return [Node.from_object(o) for o in objs]
Exemple #2
0
    def node_create(self, node_id=None, host=None, metadata=None):
        now = int(time() * 1000)
        if not node_id:
            node_id = str(uuid4())

        if not host:
            host = gethostname()

        data = json.dumps({
            "ID": node_id,
            "CreatedAt": now,
            "UpdatedAt": now,
            "Host": host,
            "Metadata": metadata,
            "Revision": 1
        })
        r = self.request("/api/node", method="POST", data=data)
        return Node.from_object(r)
Exemple #3
0
 def node_list(self):
     objs = self.request("/api/node")
     return [Node.from_object(o) for o in objs.values()]
Exemple #4
0
 def node_update(self, node_id=None, patches=[]):
     data = json.dumps(patches)
     path = "/api/node/%s" % node_id
     r = self.request(path, method="PATCH", data=data)
     return Node.from_object(r)