Beispiel #1
0
    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)
                    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')
Beispiel #2
0
    def _create_nic(self, asset):
        """
        创建网卡。可能有多个网卡,甚至虚拟网卡。
        :param asset:
        :return:
        """
        nic_list = self.data.get("nic")
        if not nic_list:
            return

        for nic_dict in nic_list:
            if not nic_dict.get('mac'):
                raise ValueError("网卡缺少MAC地址!")
            if not nic_dict.get("model"):
                raise ValueError("网卡型号未知!")

            nic = models.NIC()
            nic.asset = asset
            nic.name = nic_dict.get('name')
            nic.model = nic_dict.get('model')
            nic.mac = nic_dict.get('mac')
            nic.ip_address = nic_dict.get('ip_address')
            if nic_dict.get('net_mask'):
                if len(nic_dict.get('net_mask')) > 0:
                    nic.net_mask = nic_dict.get('net_mask')[0]

            nic.save()
Beispiel #3
0
    def _create_nic(self, asset):
        """
        创建网卡。可能有多个网卡,甚至虚拟网卡。
        :param asset:
        :return:
        """
        nic_list = self.data['nic']
        if not nic_list:
            return

        for nic_dict in nic_list:
            if not nic_dict.get('mac'):
                print('网卡缺少mac地址!')
                # continue
                # pass
                raise KeyError('网卡缺少mac地址!')
            if not nic_dict.get('model'):
                print('显卡型号未知')
                # continue
                # pass
                raise KeyError('显卡型号未知')
            nic = models.NIC()
            nic.asset = asset
            nic.name = nic_dict.get('name', )
            nic.model = nic_dict.get('model')
            nic.mac = nic_dict.get('mac')
            nic.ip_address = nic_dict.get('ip_address')
            if nic_dict.get('net_mask'):
                if len(nic_dict.get('net_mask')) > 0:
                    nic.net_mask = nic_dict.get('net_mask')[0]
            nic.save()
Beispiel #4
0
 def _create_nic(self, asset):
     nic_list = self.data.get('nic')
     if not nic_list:
         return
     for nic_dict in nic_list:
         if not nic_dict.get('mac'):
             raise ValueError('网卡缺少mac地址')
         if not nic_dict.get('model'):
             raise ValueError('网卡型号未知')
         nic = models.NIC()
         nic.asset = asset
         nic.name = nic_dict.get('name')
         nic.model = nic_dict.get('model')
         nic.mac = nic_dict.get('mac')
         nic.ip_address = nic_dict.get('ip_address')
         if nic_dict.get('net_mask'):
             if len(nic_dict.get('net_mask')) > 0:
                 nic.net_mask = nic_dict.get('net_mask')[0]
         nic.save()
Beispiel #5
0
 def _create_nic(self,asset):
     '''
     创建网卡
     :param asset:
     :return:
     '''
     nic_list = self.data.get('nic')
     if not nic_list:
         return
     for nic_dict in nic_list:
         nic = models.NIC()
         nic.mac = nic_dict.get('mac','网卡缺少mac地址')
         nic.model = nic_dict.get('model','网卡型号未知')
         nic.asset = asset
         nic.name = nic_dict.get('name')
         nic.model = nic_dict.get('model')
         nic.ip_addr = nic_dict.get('ip_addr')
         nic.net_mask = nic_dict.get('netmask')
         nic.save()