Пример #1
0
    def __create_cpu_component(self, ignore_errs=False):
        try:
            #验证客户端传过来的信息的数据类型合法后,创建资产信息
            self.__verify_field(self.clean_data, 'model', str)
            self.__verify_field(self.clean_data, 'cpu_count', int)
            self.__verify_field(self.clean_data, 'cpu_core_count', int)
            if not len(
                    self.response['error']
            ) or ignore_errs == True:  #no processing when there's no error happend
                data_set = {
                    'asset_id': self.asset_obj.id,
                    'cpu_model': self.clean_data.get('cpu_model'),
                    'cpu_count': self.clean_data.get('cpu_count'),
                    'cpu_core_count': self.clean_data.get('cpu_core_count'),
                }

                obj = models.CPU(**data_set)
                obj.save()
                log_msg = "Asset[%s] --> has added new [cpu] component with data [%s]" % (
                    self.asset_obj, data_set)
                self.response_msg('info', 'NewComponentAdded', log_msg)
                return obj
        except Exception as e:
            self.response_msg('error', 'ObjectCreationException',
                              'Object [cpu] %s' % str(e))
Пример #2
0
    def __create_cpu(self):
        try:
            self._type_validation(self.clean_data, 'model', str)
            self._type_validation(self.clean_data, 'cpu_count', int)
            self._type_validation(self.clean_data, 'cpu_core_count', int)
            if not len(self.response['error']):
                data_set = {
                    'asset_id': self.asset_obj.id,
                    'cpu_model': self.clean_data.get('cpu_model'),
                    'cpu_count': self.clean_data.get('cpu_count'),
                    'cpu_core_count': self.clean_data.get('cpu_core_count'),
                }

                obj = models.CPU(**data_set)
                obj.save()
        except Exception as e:
            print(e)
            self.response_msg('error', 'CreationException',
                              'Object [cpu] %s' % str(e))
Пример #3
0
 def __create_cpu_component(self, ignore_errs=False):
     try:
         self.__verify_field(self.clean_data, 'model', str)
         self.__verify_field(self.clean_data, 'cpu_count', str)
         self.__verify_field(self.clean_data, 'cpu_core_count', str)
         if not len(self.response['error']) or ignore_errs is True:
             data_set = {
                 'asset_id': self.asset_obj.id,
                 'model': self.clean_data.get('model'),
                 'cpu_count': self.clean_data.get('cpu_count'),
                 'cpu_core_count': self.clean_data.get('cpu_core_count'),
             }
             obj = models.CPU(**data_set)
             obj.save()
             self.response_msg('info',
                               'NewComponentAdded',
                               "Asset[%s] --> has added new [cpu] component with data [%s]" %
                               (self.asset_obj, data_set))
             return obj
     except Exception as e:
         self.response_msg('error', 'ObjectCreationException', 'Object [server] %s' % str(e))