def _write_cache_tier_defaults(self):
     if not self._cluster_info.get('cache_tier_defaults', None):
         return True
     cache_tier_defaults = self._cluster_info['cache_tier_defaults']
     LOG.info("CLUSTER INFO")
     LOG.info(cache_tier_defaults)
     name_list = []
     sets = db.vsm_settings_get_all(self._context)
     db_list = [s.name for s in sets]
     for setting in cache_tier_defaults:
         LOG.info(setting)
         name = setting.get('name', None)
         value = setting.get('default_value', None)
         if not name in db_list:
             try:
                 if not value.isdigit():
                     value = float(value)
             except ValueError:
                 value = None
             except AttributeError:
                 value = None
             if not value:
                 LOG.warn('The default value of %s should be digit. Load default value ...' % name)
                 value = FLAGS.get(name, None)
                 if not value:
                     LOG.warn('Failed to load the default value of %s.' % name)
                     try:
                         raise exception.GetNoneError
                     except exception.GetNoneError as e:
                         LOG.error("%s:%s" %(e.code, e.message))
                     ret = False
                     continue
             setting['value'] = value
             ref = db.vsm_settings_update_or_create(self._context, setting)
             name_list.append(name)
Beispiel #2
0
    def detail(self, req):
        """Get a detailed vsm setting list."""
        context = req.environ['vsm.context']

        settings = db.vsm_settings_get_all(context)
        LOG.info('vsm/api/v1/vsm_settings.py settings:%s' % settings)

        return self._view_builder.detail(req, settings)
    def index(self, req):
        """Get a vsm setting list."""
        context = req.environ['vsm.context']

        settings = db.vsm_settings_get_all(context)
        LOG.info('vsm/api/v1/vsm_settings.py settings:%s' % settings)

        return self._view_builder.index(req, settings)
 def _compute_pg_num(self, context, osd_num, replication_num):
     """compute pg_num"""
     try:
         pg_count_factor = 200
         settings = db.vsm_settings_get_all(context)
         for setting in settings:
             if setting['name'] == 'pg_count_factor':
                 pg_count_factor = int(setting['value'])
         
         pg_num = pg_count_factor * osd_num//replication_num
     except ZeroDivisionError,e:
         raise exc.HTTPBadRequest(explanation=str(e))
 def _compute_pg_num(self, context, osd_num, replication_num):
     """compute pg_num"""
     try:
         pg_count_factor = 200
         settings = db.vsm_settings_get_all(context)
         for setting in settings:
             if setting['name'] == 'pg_count_factor':
                 pg_count_factor = int(setting['value'])
         
         pg_num = pg_count_factor * osd_num//replication_num
     except ZeroDivisionError,e:
         raise exc.HTTPBadRequest(explanation=str(e))
Beispiel #6
0
 def _write_cache_tier_defaults(self):
     if not self._cluster_info.get('cache_tier_defaults', None):
         return True
     cache_tier_defaults = self._cluster_info['cache_tier_defaults']
     LOG.info("CLUSTER INFO")
     LOG.info(cache_tier_defaults)
     name_list = []
     sets = db.vsm_settings_get_all(self._context)
     db_list = [s.name for s in sets]
     for setting in cache_tier_defaults:
         LOG.info(setting)
         name = setting.get('name', None)
         value = setting.get('default_value', None)
         if not name in db_list:
             try:
                 if not value.isdigit():
                     value = float(value)
             except ValueError:
                 value = None
             except AttributeError:
                 value = None
             if not value:
                 LOG.warn(
                     'The default value of %s should be digit. Load default value ...'
                     % name)
                 value = FLAGS.get(name, None)
                 if not value:
                     LOG.warn('Failed to load the default value of %s.' %
                              name)
                     try:
                         raise exception.GetNoneError
                     except exception.GetNoneError as e:
                         LOG.error("%s:%s" % (e.code, e.message))
                     ret = False
                     continue
             setting['value'] = value
             ref = db.vsm_settings_update_or_create(self._context, setting)
             name_list.append(name)
 def settings_get_all(self, context):
     return db.vsm_settings_get_all(context)
Beispiel #8
0
    def _write_vsm_settings(self):
        """Writing vsm settings into DB.

           [settings]
           #format [key] [default_value]
           storage_group_near_full_threshold 65
           storage_group_full_threshold 85

        """
        ret = True
        setting_list = self._cluster_info['settings']
        name_list = list()
        sets = db.vsm_settings_get_all(self._context)
        db_list = [s.name for s in sets]
        LOG.debug('vsm settings already exists in db: %s' % db_list)

        for setting in setting_list:
            try:
                name = setting.get('name', None)
                value = setting.get('default_value', None)
                # The setting does not exist in db.
                if not name in db_list:
                    if not value or not value.isdigit():
                        LOG.warn(
                            'The default value of %s should be digit. Load default value ...'
                            % name)
                        value = FLAGS.get(name, None)
                        if not value:
                            LOG.warn(
                                'Failed to load the default value of %s.' %
                                name)
                            try:
                                raise exception.GetNoneError
                            except exception.GetNoneError as e:
                                LOG.error("%s:%s" % (e.code, e.message))
                            ret = False
                            continue
                    setting['value'] = value
                    ref = db.vsm_settings_update_or_create(
                        self._context, setting)
                    name_list.append(name)
            except:
                ret = False
                LOG.error('Failed to load setting %s.' % name)
                continue

        # load other default vsm settings from flags
        setting_list = name_list + db_list
        LOG.debug('settings loaded: %s' % setting_list)
        for ss in flags.vsm_settings_opts:

            if not ss.name in setting_list:
                try:
                    val = {
                        'name': ss.name,
                        'value': str(ss.default),
                        'default_value': str(ss.default)
                    }
                    ref = db.vsm_settings_update_or_create(self._context, val)
                except:
                    ret = False
                    LOG.error('Failed to load setting %s from flags.' % name)
                continue

        return ret
    def _write_vsm_settings(self):
        """Writing vsm settings into DB.

           [settings]
           #format [key] [default_value]
           storage_group_near_full_threshold 65
           storage_group_full_threshold 85

        """
        ret = True
        setting_list = self._cluster_info['settings']
        name_list = list()
        sets = db.vsm_settings_get_all(self._context)
        db_list = [s.name for s in sets]
        LOG.debug('vsm settings already exists in db: %s' % db_list)

        for setting in setting_list:
            try:
                name = setting.get('name', None)
                value = setting.get('default_value', None)
                # The setting does not exist in db.
                if not name in db_list:
                    if not value or not value.isdigit():
                        LOG.warn('The default value of %s should be digit. Load default value ...' % name)
                        value = FLAGS.get(name, None)
                        if not value:
                            LOG.warn('Failed to load the default value of %s.' % name)
                            try:
                                raise exception.GetNoneError
                            except exception.GetNoneError as e:
                                LOG.error("%s:%s" %(e.code, e.message))
                            ret = False
                            continue
                    setting['value'] = value
                    ref = db.vsm_settings_update_or_create(self._context,
                                                           setting)
                    name_list.append(name)
            except:
                ret = False
                LOG.error('Failed to load setting %s.' % name)
                continue

        # load other default vsm settings from flags
        setting_list = name_list + db_list
        LOG.debug('settings loaded: %s' % setting_list)
        for ss in flags.vsm_settings_opts:

            if not ss.name in setting_list:
                try:
                    val = {
                        'name': ss.name,
                        'value': str(ss.default),
                        'default_value': str(ss.default)
                    }
                    ref = db.vsm_settings_update_or_create(self._context,
                                                           val)
                except:
                    ret = False
                    LOG.error('Failed to load setting %s from flags.' % name)
                continue

        return ret
Beispiel #10
0
 def settings_get_all(self, context):
     return db.vsm_settings_get_all(context)