标签:info ica 管理系 逻辑 upd 网卡 ati model oat
只有一条数据
下面的是有多条数据的
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) ‘‘‘ 这里确实是验证了一个slot,首先获取数据,0是不成立的,插槽是0 这一段根本就不走,客户端操作,导致这一块就报错 ‘‘‘ 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‘: 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: 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‘)
except Exception as e: self.response_msg(‘error‘, ‘ObjectCreationException‘, ‘Object [ram] %s‘ % str(e)) ‘‘‘编写except ValueError Exception as e不再抓异常‘‘‘
客户端命令行拍错截图:
def _create_server(self): self.__create_server_info() self.__create_or_update_manufactory() self.__create_cpu_component() self.__create_disk_component() self.__create_nic_component() self.__create_ram_component() log_msg = "Asset [<a href=‘/admin/assets/asset/%s/‘ target=‘_blank‘>%s</a>] has been created!" % ( self.asset_obj.id, self.asset_obj) self.response_msg(‘info‘, ‘NewAssetOnline‘, log_msg) ‘‘‘ 如果上面的都获取成功,我就返回一条消息,创建资产成功, 你可以‘/admin/assets/asset/%s/‘到这个页面,打开这个资产 然后记录一条日志 ‘‘‘
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) ‘‘‘验证capacity必须是int,如果不是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_nic_component(self): nic_info = self.clean_data.get(‘nic‘) if nic_info: for nic_item in nic_info: try: self.__verify_field(nic_item, ‘macaddress‘, str) ‘‘‘IP地址可以没有,验证macaddress地址必须存在‘‘‘ if not len(self.response[‘error‘]): # no processing when there‘s no error happend data_set = { ‘asset_id‘: self.asset_obj.id, ‘name‘: nic_item.get(‘name‘), ‘sn‘: nic_item.get(‘sn‘), ‘macaddress‘: nic_item.get(‘macaddress‘), ‘ipaddress‘: nic_item.get(‘ipaddress‘), ‘bonding‘: nic_item.get(‘bonding‘), ‘‘‘这个网卡是绑定的,是客户端检测的,我服务器端只是检测这个字段‘‘‘ ‘model‘: nic_item.get(‘model‘), ‘netmask‘: nic_item.get(‘netmask‘), } obj = models.NIC(**data_set) obj.save() except Exception as e: self.response_msg(‘error‘, ‘ObjectCreationException‘, ‘Object [nic] %s‘ % str(e)) else: self.response_msg(‘error‘, ‘LackOfData‘, ‘NIC info is not provied in your reporting data‘)
标签:info ica 管理系 逻辑 upd 网卡 ati model oat
原文地址:https://www.cnblogs.com/luoahong/p/9225790.html