コード例 #1
0
ファイル: core.py プロジェクト: seliencepuppet/python-demo
    def __create_ram_component(self):
        ram_info = self.clean_data.get('ram')
        if ram_info:
            for ram_item in ram_info:
                try:
                    self.__verify_field(ram_item, 'capacity', int)
                    if not len(
                            self.response['error']
                    ):  # no processing when there's no error happend
                        data_set = {
                            'asset_id': self.asset_obj.id,
                            'slot': ram_item.get("slot"),
                            'sn': ram_item.get('sn'),
                            'capacity': ram_item.get('capacity'),
                            'model': ram_item.get('model'),
                        }

                        obj = models.RAM(**data_set)
                        obj.save()

                except Exception as e:
                    self.response_msg('error', 'ObjectCreationException',
                                      'Object [ram] %s' % str(e))
        else:
            self.response_msg(
                'error', 'LackOfData',
                'RAM info is not provied in your reporting data')
コード例 #2
0
 def _create_ram_info(self):
     ram_obj = models.RAM(
         asset=self.asset_obj,
         capacity=self.asset_data.get("memory_information").get("capacity"))
     ram_obj.save()
     logmsg = "新增内存,容量:%s MB" % ram_obj.capacity
     self.log_handler(2, detail=logmsg)
コード例 #3
0
ファイル: asset_handler.py プロジェクト: bibapple/django_cmdb
 def _create_ram(self, asset):
     """创建内存,通常有多个内存"""
     ram_list = self.data.get("ram")
     if not ram_list:  # 万一一条内存数据都没有
         return
     for ram_dict in ram_list:
         if not ram_dict.get("slot"):
             raise ValueError("未知的内存插槽!")  # 使用虚机的时候,可能无法获取内存插槽,需要修改此处逻辑
         ram = models.RAM()
         ram.asset = asset
         ram.slot = ram_dict.get("slot")
         ram.sn = ram_dict.get("sn")
         ram.model = ram_dict.get("model")
         ram.manufacture = ram_dict.get("manufacturer")
         ram.capacity = ram_dict.get("capacity", 0)
         ram.save()
コード例 #4
0
ファイル: core.py プロジェクト: howudoing/SeriousCMDB
 def __create_ram_component(self):
     ram_info = self.data.get("ram")
     if ram_info:
         for ram_item in ram_info:
             try:
                 self.__verify_field(ram_item, 'capacity', int)
                 if not len(self.response["error"]):
                     data_set = {
                         "asset_id": self.asset_obj.id,
                         "model": ram_item.get("model"),
                         "slot": ram_item.get("slot"),
                         "sn": ram_item.get("sn"),
                         "capacity": ram_item.get("capacity"),
                     }
                     obj = models.RAM(**data_set)
                     obj.save()
             except Exception as e:
                 self.response_msg("error", "ObjectCreationException",
                                   "Object [ram] %s" % str(e))
     else:
         self.response_msg(
             "error", "LackOfData",
             "RAM info is not provided in your reporting data")