示例#1
0
文件: base.py 项目: ammoam/eNMS
 def update(self, **kwargs: Any) -> None:
     relation = relationships[self.__tablename__]
     modified = False
     for property, value in kwargs.items():
         if not hasattr(self, property):
             continue
         property_type = property_types.get(property, None)
         if property in relation:
             if relation[property]["list"]:
                 value = objectify(relation[property]["model"], value)
             else:
                 value = fetch(relation[property]["model"], id=value)
         if property_type == "bool":
             value = value not in (False, "false")
         old_value = getattr(self, property)
         if old_value != value:
             if (
                 isinstance(value, list)
                 and old_value
                 and set(value) == set(old_value)
             ):
                 continue
             modified = True
             setattr(self, property, value)
     if modified:
         self.last_modified = controller.get_time()
示例#2
0
 def topology_import(self, file):
     book = open_workbook(file_contents=file.read())
     status = "Topology successfully imported."
     for obj_type in ("device", "link"):
         try:
             sheet = book.sheet_by_name(obj_type)
         except XLRDError:
             continue
         properties = sheet.row_values(0)
         for row_index in range(1, sheet.nrows):
             values = {}
             for index, property in enumerate(properties):
                 if not property:
                     continue
                 func = db.field_conversion[property_types.get(
                     property, "str")]
                 values[property] = func(sheet.row_values(row_index)[index])
             try:
                 db.factory(obj_type, **values).serialized
             except Exception as exc:
                 info(f"{str(values)} could not be imported ({str(exc)})")
                 status = "Partial import (see logs)."
         db.session.commit()
     for pool in db.fetch_all("pool"):
         pool.compute_pool()
     self.log("info", status)
     return status
示例#3
0
文件: base.py 项目: gaecom/eNMS
 def update(self, **kwargs):
     relation = relationships[self.__tablename__]
     for property, value in kwargs.items():
         if not hasattr(self, property):
             continue
         property_type = property_types.get(property, None)
         if property in relation:
             if relation[property]["list"]:
                 value = db.objectify(relation[property]["model"], value)
             elif value:
                 value = db.fetch(relation[property]["model"], id=value)
         if property_type == "bool":
             value = value not in (False, "false")
         setattr(self, property, value)
示例#4
0
 def update(self, **kwargs):
     relation = relationships[self.__tablename__]
     for property, value in kwargs.items():
         if not hasattr(self, property):
             continue
         property_type = property_types.get(property, None)
         if property in relation:
             if relation[property]["list"]:
                 value = db.objectify(relation[property]["model"], value)
             elif value:
                 value = db.fetch(relation[property]["model"], id=value)
         if property_type == "bool":
             value = value not in (False, "false")
         setattr(self, property, value)
     if not kwargs.get("update_pools") or not self.pool_model:
         return
     for pool in db.fetch_all("pool", rbac=None):
         if pool.manually_defined or not pool.compute(self.class_type):
             continue
         match = pool.object_match(self)
         if match and self not in getattr(pool, f"{self.class_type}s"):
             getattr(pool, f"{self.class_type}s").append(self)
         if self in getattr(pool, f"{self.class_type}s") and not match:
             getattr(pool, f"{self.class_type}s").remove(self)