Exemplo n.º 1
0
 def create(cls, context, values):
     values = cls._transpose_metadata(values)
     obj = db_api.node_create(context, values)
     # NOTE: We need an extra DB call to make sure the profile is loaded
     #       and bound to the node created.
     obj = db_api.node_get(context, obj.id)
     return cls._from_db_object(context, cls(), obj)
Exemplo n.º 2
0
    def do_del_nodes(self):
        nodes = self.inputs.get('nodes', [])

        node_ids = copy.deepcopy(nodes)
        errors = []
        for node_id in node_ids:
            try:
                node = db_api.node_get(self.context, node_id)
            except exception.NodeNotFound:
                errors.append(_('Node [%s] is not found.') % node_id)
                continue
            if ((node.cluster_id is None) or
                    (node.cluster_id != self.cluster.id)):
                nodes.remove(node_id)

        if len(errors) > 0:
            return self.RES_ERROR, ''.join(errors)

        reason = _('Completed deleting nodes.')
        if len(nodes) == 0:
            return self.RES_OK, reason

        # For deleting nodes from cluster, set destroy to false
        data = {
            'deletion': {
                'destroy_after_delete': False,
            }
        }
        self.data.update(data)
        result, new_reason = self._delete_nodes(nodes)

        if result != self.RES_OK:
            reason = new_reason
        return result, reason
Exemplo n.º 3
0
    def load(cls, context, node_id=None, node=None, show_deleted=False):
        '''Retrieve a node from database.'''
        if node is None:
            node = db_api.node_get(context, node_id, show_deleted=show_deleted)
            if node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_db_record(context, node)
Exemplo n.º 4
0
    def load(cls, context, node_id=None, node=None, project_safe=True):
        '''Retrieve a node from database.'''
        if node is None:
            node = db_api.node_get(context, node_id, project_safe=project_safe)
            if node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_db_record(context, node)
Exemplo n.º 5
0
    def load(cls, context, node_id=None, node=None, show_deleted=False):
        '''Retrieve a node from database.'''
        if node is None:
            node = db_api.node_get(context, node_id, show_deleted=show_deleted)
            if node is None:
                raise exception.NodeNotFound(node=node_id)

        return cls._from_db_record(context, node)
Exemplo n.º 6
0
    def del_nodes(self, node_ids):
        '''Remove nodes from current cluster.'''

        deleted = []
        for node_id in node_ids:
            node = db_api.node_get(node_id)
            if node and node.leave(self):
                deleted.append(node_id)
        return deleted
Exemplo n.º 7
0
    def do_del_nodes(self):
        """Handler for the CLUSTER_DEL_NODES action.

        :returns: A tuple containing the result and the corresponding reason.
        """
        # Check if deletion policy is attached to the action, if is,
        # get grace_period value
        pd = self.data.get('deletion', None)
        grace_period = None
        if pd is not None:
            grace_period = self.data['deletion'].get('grace_period')
        else:  # if not, deleting nodes from cluster, don't destroy them
            data = {
                'deletion': {
                    'destroy_after_deletion': False,
                }
            }
            self.data.update(data)
        nodes = self.inputs.get('candidates', [])

        node_ids = copy.deepcopy(nodes)
        errors = []
        for node_id in node_ids:
            try:
                node = db_api.node_get(self.context, node_id)
            except exception.NodeNotFound:
                errors.append(_('Node [%s] is not found.') % node_id)
                continue
            if ((not node.cluster_id) or (node.cluster_id != self.cluster.id)):
                nodes.remove(node_id)

        if len(errors) > 0:
            return self.RES_ERROR, ''.join(errors)

        reason = _('Completed deleting nodes.')
        if len(nodes) == 0:
            return self.RES_OK, reason

        if grace_period is not None:
            self._wait_before_deletion(grace_period)
        result, new_reason = self._delete_nodes(nodes)

        if result != self.RES_OK:
            reason = new_reason
        else:
            self.cluster.desired_capacity -= len(nodes)
            self.cluster.store(self.context)

        return result, reason
Exemplo n.º 8
0
    def do_del_nodes(self):
        """Handler for the CLUSTER_DEL_NODES action.

        :returns: A tuple containing the result and the corresponding reason.
        """
        # Check if deletion policy is attached to the action, if is,
        # get grace_period value
        pd = self.data.get('deletion', None)
        grace_period = None
        if pd is not None:
            grace_period = self.data['deletion']['grace_period']
        else:  # if not, deleting nodes from cluster, don't destroy them
            data = {
                'deletion': {
                    'destroy_after_deletion': False,
                }
            }
            self.data.update(data)
        nodes = self.inputs.get('candidates', [])

        node_ids = copy.deepcopy(nodes)
        errors = []
        for node_id in node_ids:
            try:
                node = db_api.node_get(self.context, node_id)
            except exception.NodeNotFound:
                errors.append(_('Node [%s] is not found.') % node_id)
                continue
            if ((node.cluster_id is None) or
                    (node.cluster_id != self.cluster.id)):
                nodes.remove(node_id)

        if len(errors) > 0:
            return self.RES_ERROR, ''.join(errors)

        reason = _('Completed deleting nodes.')
        if len(nodes) == 0:
            return self.RES_OK, reason

        if grace_period is not None:
            self._wait_before_deletion(grace_period)
        result, new_reason = self._delete_nodes(nodes)

        if result != self.RES_OK:
            reason = new_reason
        return result, reason
Exemplo n.º 9
0
    def do_del_nodes(self):
        """Handler for the CLUSTER_DEL_NODES action.

        :returns: A tuple containing the result and the corresponding reason.
        """
        nodes = self.inputs.get('nodes', [])

        node_ids = copy.deepcopy(nodes)
        errors = []
        for node_id in node_ids:
            try:
                node = db_api.node_get(self.context, node_id)
            except exception.NodeNotFound:
                errors.append(_('Node [%s] is not found.') % node_id)
                continue
            if ((node.cluster_id is None)
                    or (node.cluster_id != self.cluster.id)):
                nodes.remove(node_id)

        if len(errors) > 0:
            return self.RES_ERROR, ''.join(errors)

        reason = _('Completed deleting nodes.')
        if len(nodes) == 0:
            return self.RES_OK, reason

        # For deleting nodes from cluster, set destroy to false
        data = {
            'deletion': {
                'destroy_after_delete': False,
            }
        }
        self.data.update(data)
        result, new_reason = self._delete_nodes(nodes)

        if result != self.RES_OK:
            reason = new_reason
        return result, reason
Exemplo n.º 10
0
 def get(cls, context, node_id, **kwargs):
     obj = db_api.node_get(context, node_id, **kwargs)
     return cls._from_db_object(context, cls(), obj)
Exemplo n.º 11
0
 def get(cls, context, node_id, **kwargs):
     obj = db_api.node_get(context, node_id, **kwargs)
     return cls._from_db_object(context, cls(), obj)