def __create_disk_component(self): disk_info = self.clean_data.get('physical_disk_driver') if disk_info: for disk_item in disk_info: try: self.__verify_field(disk_item, 'slot', str) self.__verify_field(disk_item, 'capacity', float) # self.__verify_field(disk_item, 'iface_type', str) self.__verify_field(disk_item, 'model', str) if not len(self.response['error']): # no processing when there's no error happend data_set = { 'asset_id': self.asset_obj.id, 'sn': disk_item.get('sn'), 'slot': disk_item.get('slot'), 'capacity': float(disk_item.get('capacity')), 'model': disk_item.get('model'), 'iface_type': disk_item.get('iface_type'), } obj = models.Disk(**data_set) obj.save() except Exception as e: self.response_msg('error', 'ObjectCreationException', 'Object [disk] %s' % str(e)) else: self.response_msg('error', 'LackOfData', 'Disk info is not provied in your reporting data')
def __create_disk(self): disk_info = self.clean_data.get('physical_disk_driver') if disk_info: for disk_item in disk_info: try: #self._type_validation(disk_item,'slot',str) self._type_validation(disk_item, 'capacity', float) self._type_validation(disk_item, 'iface_type', str) self._type_validation(disk_item, 'model', str) if not len(self.response['error'] ): #no processing when there's no error happend data_set = { 'asset_id': self.asset_obj.id, 'sn': disk_item.get('sn'), 'slot': disk_item.get('slot'), 'capacity': disk_item.get('capacity'), 'model': disk_item.get('model'), 'iface_type': disk_item.get('iface_type'), 'manufactory': disk_item.get('manufactory'), } obj = models.Disk(**data_set) obj.save() except Exception as e: print(e) self.response_msg('error', 'CreationException', 'Object [disk] %s' % str(e)) else: self.response_msg('error', 'LackData', '提交的内容没有 DISK 信息')