コード例 #1
0
ファイル: core.py プロジェクト: LeonYanwj/LeonCMDB
    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
                        if not models.NIC.objects.filter(macaddress=nic_item.get('macaddress')):
                            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')
コード例 #2
0
ファイル: core.py プロジェクト: qyt2018/lyanadmin
    def __create_nic(self):
        nic_info = self.clean_data.get('nic')
        if nic_info:
            for nic_item in nic_info:
                try:
                    self._type_validation(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:
                    print(e)
                    self.response_msg('error', 'CreationException',
                                      'Object [nic] %s' % str(e))
        else:
            self.response_msg('error', 'LackOfData', '提交的内容没有 NIC 信息')