刚才都是一条像内存,硬盘,网卡、多条的话如何操作

只有一条数据

下面的是有多条数据的

硬盘必须字段的验证

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

  

CMDB资产管理系统开发【day26】:批准资产入库的更多相关文章

  1. CMDB资产管理系统开发【day25】:表结构设计2

    表结构设计1详细注释代码 # _*_coding:utf-8_*_ __author__ = 'luoahong' from assets.myauth import UserProfile from ...

  2. CMDB资产管理系统开发【day25】:表结构设计1

    资产表 # _*_coding:utf-8_*_ __author__ = 'jieli' from assets.myauth import UserProfile from django.db i ...

  3. CMDB资产管理系统开发【day25】:windows客户端开发

    1.目录结构 PS Y:\MadkingClient> tree /f 卷 netgame 的文件夹 PATH 列表 卷序列号为 ACE3-896E Y:. ├─bin │ NedStark.p ...

  4. CMDB资产管理系统开发【day26】:admin action

    本节目标 审核写到数据库,我就单独写一个如下的 页面 单机go后就跳转到如下图界面,我们这节课的目标就是写一个这样的页面 asset\admin.py部分代码 注释如下: class NewAsset ...

  5. CMDB资产管理系统开发【day26】:数据正式存入待存区

    1.from表单提交 1.数据提交到哪里呢? 提交到assets/new_assets_approval.html这了 2.Yes, I'm sure提交了什么?          为什么没有下拉框了 ...

  6. CMDB资产管理系统开发【day26】:CMDB上节回顾

    一.上节知识点回顾 服务器设计了一个表结构 开发了一个客户端 二.后台创建缓存区表 客户端连接服务器,在服务器的下面看报错信息 因为URL都没有写,所以我找不到呀 1.在MadKing\url.py ...

  7. CMDB资产管理系统开发【day26】:02-数据写入待存区

    一.资产自动回报数据及个更新流程图 二.表结构注释(NewAssetApprovalZone) class NewAssetApprovalZone(models.Model): "&quo ...

  8. CMDB资产管理系统开发【day26】:Django admin

    想实现的是一个表里面的字段 选择性的出现在菜单栏 1.如何自定义菜单 自定义菜单前 在asset\admin.py里添加如下代码: class NewAssetApprovalZoneAdmin(ad ...

  9. CMDB资产管理系统开发【day26】:实现资产自动更新

    1.需求分析 1.比对分析 比对的时候以那个数据源为主? old [1,2,3 ] db数据库 new [2,3,4 ] 客户端汇报过来的 当然以客户端汇报过来的数据为主 2.更新分析 不同的表到底拿 ...

随机推荐

  1. jupyter notebook 使用cmd命令窗口打开

    第一步:将文件路径改为你需要使用文件所在的路径 第二部:   jupyter notebook

  2. LeetCode 96——不同的二叉搜索树

    1. 题目 2. 解答 以 \(1, 2, \cdots, n\) 构建二叉搜索树,其中,任意数字都可以作为根节点来构建二叉搜索树.当我们将某一个数字作为根节点后,其左边数据将构建为左子树,右边数据将 ...

  3. Python3 标准库:calendar,time

    1.calendar import calendar print(calendar.month(2008,8)) #某个月 print(calendar.calendar(2008)) #某年 pri ...

  4. 自测之Lesson3:makefile

    题目:编写一个makefile文件,要求编译当前目录内的所有.c文件. 完成代码: .PHONY:clean all SRC=$(wildcard *.c) BIN=$(SRC:%.c=%) all: ...

  5. 2019寒假训练营寒假作业(三) MOOC的网络空间安全概论笔记部分

    目录 第五章 网络攻防技术 5.1:网络信息收集技术--网络踩点 信息收集的必要性及内容 网络信息收集技术 网络踩点(Footprinting) 网络踩点常用手段 5.2:网络信息收集技术 --网络扫 ...

  6. IT启示录

    引用电影<夏洛特烦恼>中夏洛的一句话:"一直以来,我根本就不知道自己想要什么".可以说在写这篇博客之前我仍然没有考虑清楚之后的道路,即使早已明确了走游戏开发的道理,却不 ...

  7. Crash使用参考

    整理自man 8 crash 1.简介 Crash工具可以用来分析一个正在运行的内核,也可以用来分析一个内核的crash dump文件,这里说的是内核代码异常产生的crash dump文件,不是应用层 ...

  8. react项目开发入门

    v16.2.0 在html头部引入react相关js文件 <!-- react核心库--><script src="../static/react/react.produc ...

  9. C#中Console.ReadLine()和Console.Read()有何区别?

    Console.Read 表示从控制台读取字符串,不换行. Console.ReadLine 表示从控制台读取字符串后进行换行. Console.Read() Console.ReadLine()方法 ...

  10. SQL Server的全局变量

    SQL Service中的全部变量不需要用户参与定义,在任何程序均可随时调用.并且全部变量是以@@开头 全局变量名称 描述 @@CONNECTIONS 返回 SQL Server 自上次启动以来尝试的 ...