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

只有一条数据

下面的是有多条数据的

硬盘必须字段的验证

    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. anaconda安装scrapy报错解决办法

    今天在用anaconda安装scrapy的时候遇见个坑,现在将解决办法发出来,供大家参考使用: 问题描述: anaconda安装scrapy,使用 conda install scrapy 命令.安装 ...

  2. MATLAB画图符号标注

    线型 说明 标记符 说明 颜色 说明 - 实线(默认) + 加号符 r 红色 -- 双划线 o 空心圆 g 绿色 : 虚线 * 星号 b 蓝色 :. 点划线 . 实心圆 c 青绿色 x 叉号符 m 洋 ...

  3. opencv-学习笔记(3)

    opencv-学习笔记(3) 这章讲了 图像加法 opencv测试效率 IPYTHON测试效率 图像加法 cv2.add() 要求,两图片必须大小类型相同 然后是图像混合cv2.addWeighted ...

  4. pxe+kickstart无人值守安装

    常用软件安装及使用目录 第1章 以前是怎么安装系统的 l 光盘(ISO文件,光盘的镜像文件)===>每一台物理机都得给一个光驱,如果用外置光驱的话,是不是每台机器都需要插一下 l U盘:ISO镜 ...

  5. android课程第一节(TextView控件使用)

    TextView控件使用 一.TextView基本使用(创建方式) 1.在程序中创建TextView对象 如下代码: @Override protected void onCreate(Bundle ...

  6. java线程安全— synchronized和volatile

    java线程安全— synchronized和volatile package threadsafe; public class TranditionalThreadSynchronized { pu ...

  7. 3dContactPointAnnotationTool开发日志(二四)

      添加了清空2d接触点的按钮,将输出的2d接触点的单位变成了像素,原点在图像的左下角.   对于obj文件的适配更加多样化了.

  8. 【week2】 词频统计效能分析

    效能统计工具:Jprofiler License Key:L-Larry_Lau@163.com#23874-hrwpdp1sh1wrn#0620 该性能分析工具对服务器进行监听,图一是线程变化图,当 ...

  9. c++读取文件夹及子文件夹数据

    这里有两种情况:读取文件夹下所有嵌套的子文件夹里的所有文件  和 读取文件夹下的指定子文件夹(或所有子文件夹里指定的文件名) <ps,里面和file文件有关的结构体类型和方法在 <io.h ...

  10. Spring Boot 运行原理

    Spring Boot并没有任何新的技术,全都是基于Spring4提供的技术,用优秀的设计,为Web开发提供了一套新的方式. 在HelloWorld中,我们没有进行任何显示的配置,但是程序还是运行起来 ...