Ejemplo n.º 1
0
    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': 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')
Ejemplo n.º 2
0
 def _create_disk_info(self):
     for disk_info in self.asset_data.get("disk_information"):
         # if not (nic_info.get("name") == "lo" or nic_info.get("ip_address") == "127.0.0.1"):
         disk_obj = models.Disk(
             asset=self.asset_obj,
             name=disk_info.get("name"),
             capacity=disk_info.get("capacity"),
         )
         disk_obj.save()
         logmsg = "新增硬盘,硬盘名:%s 容量(MB):%s" % (disk_obj.name,
                                             disk_obj.capacity)
         self.log_handler(2, detail=logmsg)
Ejemplo n.º 3
0
 def __create_disk_component(self):
     disk_info = self.data.get("disk")
     if disk_info:
         for disk in disk_info:
             try:
                 self.__verify_field(disk, "diskname", str)
                 self.__verify_field(disk, "disksize", str)
                 if not len(self.response["error"]):
                     data_set = {
                         "asset_id": self.asset_obj.id,
                         "sn": disk.get("diskname"),
                         "capacity": disk.get("disksize"),
                     }
                     obj = models.Disk(**data_set)
                     obj.save()
             except Exception as e:
                 self.response_msg("error", "ObjectCreationException",
                                   "Object [disk] %s" % str(e))
Ejemplo n.º 4
0
 def _create_disk(self, asset):
     """存储设备种类多,还有raid情况,需要根据实际情况具体处理。这里以简单地SATA硬盘为例,可能有
     多块硬盘。"""
     disk_list = self.data.get("physical_disk_driver")
     if not disk_list:  # 一条硬盘数据都没有
         return
     for disk_dict in disk_list:
         if not disk_dict.get("sn"):
             raise ValueError("未知的sn硬盘!")  # 根据sn确定具体某块硬盘
         disk = models.Disk()
         disk.asset = asset
         disk.sn = disk_dict.get("sn")
         disk.model = disk_dict.get("model")
         disk.manufacture = disk_dict.get("manufacturer")
         disk.slot = disk_dict.get("slot")
         disk.capacity = disk_dict.get("capacity", 0)
         iface = disk_dict.get("interface_type")
         if iface in ("SATA", "SAS", "SCSI", "SSD", "unknown"):
             disk.interface_type = iface
         disk.save()