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')
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)
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()
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")