示例#1
0
 def _api_install_json(self, request, id):
     """
     Expose JSON collection item when available
     """
     from noc.core.collection.base import Collection
     o = self.get_object_or_404(self.model, id=id)
     Collection.install(o.to_json())
     return True
示例#2
0
 def handle_install(self, install_files=None, remove=False, load=False):
     install_files = install_files or []
     for fp in install_files:
         if not os.path.isfile(fp):
             self.die("File not found: %s" % fp)
         with open(fp) as f:
             data = ujson.load(f)
         try:
             Collection.install(data)
             if load:
                 c = Collection(data["$collection"])
                 c.update_item(data)
         except ValueError as e:
             self.die("%s - %s" % (fp, (str(e))))
         if remove:
             os.unlink(fp)
示例#3
0
 def api_import(self, request, json):
     try:
         jdata = ujson.loads(json)
     except Exception as e:
         return {"status": False, "error": "Invalid JSON: %s" % e}
     try:
         if isinstance(jdata, list):
             for d in jdata:
                 Collection.install(d)
                 c = Collection(d["$collection"])
                 c.update_item(d)
         else:
             Collection.install(jdata)
             c = Collection(jdata["$collection"])
             c.update_item(jdata)
     except ValueError as e:
         return {"status": False, "error": str(e)}
     return {"status": True}