CMDB资产管理系统开发【day26】:批准资产入库
2024-08-30 23:38:53
刚才都是一条像内存,硬盘,网卡、多条的话如何操作
只有一条数据
下面的是有多条数据的
硬盘必须字段的验证
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 [disk] %s' % str(e))
'''编写except ValueError Exception as e不再抓异常'''
硬盘验证字段bug导致获取不到资产组件信息
客户端命令行拍错截图:
解决办法:
验证字段的时候:if not none 就可以了
资产表创建逻辑解析
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/'到这个页面,打开这个资产
然后记录一条日志
'''
创建资产成功创建记录截图
后台资产表截图如下:
内存capacity字段类型验证
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')
最新文章
- XFire最佳实践
- 【BZOJ-4059】Non-boring sequences 线段树 + 扫描线 (正解暴力)
- The Services(服务)
- UVa 11234 Expressions (二叉树重建&;由叶往根的层次遍历)
- POJ 1273 (基础最大流) Drainage Ditches
- ZOJ-2365 Strong Defence 贪心,BFS
- C#.net 创建XML
- [Introduction to programming in Java 笔记] 1.3.7 Converting to binary 十进制到二进制的转换
- 386. Lexicographical Numbers
- 3proxy 二级代理配置样例
- 剪切板 复制文本 ClipboardManager
- LINQ 基本子句之二 join
- web上传大文件的配置
- WLST Hangs Up Because of Java VM ClassLoader Deadlock
- [js]使用百度编辑器uediter时遇到的一些问题(span,div等被过滤)
- SecureCRT自动上传文件python脚本
- 细说@Html.ActionLink()的用法
- href=#与href=javascript:void(0)的区别
- PHP几种加密方式
- image 标签src