Example #1
0
    def load_all(cls, context, cluster_id=None, limit=None, marker=None,
                 sort=None, filters=None, project_safe=True):
        '''Retrieve all nodes of from database.'''
        records = db_api.node_get_all(context, cluster_id=cluster_id,
                                      filters=filters, sort=sort,
                                      limit=limit, marker=marker,
                                      project_safe=project_safe)

        return [cls._from_db_record(context, record) for record in records]
Example #2
0
    def load_all(cls, context, cluster_id=None, show_deleted=False,
                 limit=None, marker=None, sort_keys=None, sort_dir=None,
                 filters=None, project_safe=True):
        '''Retrieve all nodes of from database.'''

        records = db_api.node_get_all(context, cluster_id=cluster_id,
                                      show_deleted=show_deleted,
                                      limit=limit, marker=marker,
                                      sort_keys=sort_keys, sort_dir=sort_dir,
                                      filters=filters,
                                      project_safe=project_safe)

        return [cls._from_db_record(context, record) for record in records]
Example #3
0
    def pre_op(self, cluster_id, action):

        status = base.CHECK_OK
        reason = _('Scaling request validated.')

        cluster = db_api.cluster_get(action.context, cluster_id)
        nodes = db_api.node_get_all(action.context, cluster_id,
                                    filters={'status': 'ACTIVE'})
        current_size = len(nodes)
        count = self._calculate_adjustment_count(current_size)

        # Use action input if count is provided
        count = int(action.inputs.get('count', count))

        if count <= 0:
            status = base.CHECK_ERROR
            reason = _("Count (%(count)s) invalid for action %(action)s."
                       ) % {'count': count, 'action': action.action}

        # Check size constraints
        if action.action == consts.CLUSTER_SCALE_IN:
            new_size = current_size - count
            if (new_size < cluster.min_size):
                if self.best_effort:
                    count = current_size - cluster.min_size
                    reason = _('Do best effort scaling.')
                else:
                    status = base.CHECK_ERROR
                    reason = _('Attempted scaling below minimum size.')
        else:
            new_size = current_size + count
            if (new_size > cluster.max_size):
                if self.best_effort:
                    count = cluster.max_size - current_size
                    reason = _('Do best effort scaling.')
                else:
                    status = base.CHECK_ERROR
                    reason = _('Attempted scaling above maximum size.')

        pd = {'status': status, 'reason': reason}
        if status == base.CHECK_OK:
            if action.action == consts.CLUSTER_SCALE_IN:
                pd['deletion'] = {'count': count}
            else:
                pd['creation'] = {'count': count}

        action.data.update(pd)
        action.store(action.context)

        return
Example #4
0
 def get_all(cls, context, **kwargs):
     objs = db_api.node_get_all(context, **kwargs)
     return [cls._from_db_object(context, cls(), obj) for obj in objs]
Example #5
0
 def get_all(cls, context, **kwargs):
     objs = db_api.node_get_all(context, **kwargs)
     return [cls._from_db_object(context, cls(), obj) for obj in objs]