Example #1
0
    def save(self, *args, **kwargs):
        """Perform the action on the selected nodes.

        This method returns a tuple containing 3 elements: the number of
        nodes for which the action was successfully performed, the number of
        nodes for which the action could not be performed because that
        transition was not allowed and the number of nodes for which the
        action could not be performed because the user does not have the
        required permission.
        """
        action_name = self.cleaned_data['action']
        system_ids = self.cleaned_data['system_id']
        action_class = ACTIONS_DICT.get(action_name)
        not_actionable = 0
        not_permitted = 0
        done = 0
        for system_id in system_ids:
            node = Node.objects.get(system_id=system_id)
            if node.status in action_class.actionable_statuses:
                action_instance = action_class(node=node, user=self.user)
                if action_instance.inhibit() is not None:
                    not_actionable += 1
                else:
                    if action_instance.is_permitted():
                        # Do not let execute() raise a redirect exception
                        # because this action is part of a bulk operation.
                        action_instance.execute(allow_redirect=False)
                        done += 1
                    else:
                        not_permitted += 1
            else:
                not_actionable += 1
        return done, not_actionable, not_permitted
Example #2
0
    def save(self, *args, **kwargs):
        """Perform the action on the selected nodes.

        This method returns a tuple containing 3 elements: the number of
        nodes for which the action was successfully performed, the number of
        nodes for which the action could not be performed because that
        transition was not allowed and the number of nodes for which the
        action could not be performed because the user does not have the
        required permission.
        """
        action_name = self.cleaned_data['action']
        system_ids = self.cleaned_data['system_id']
        action_class = ACTIONS_DICT.get(action_name)
        not_actionable = 0
        not_permitted = 0
        done = 0
        for system_id in system_ids:
            node = Node.objects.get(system_id=system_id)
            if node.status in action_class.actionable_statuses:
                action_instance = action_class(node=node, user=self.user)
                if action_instance.inhibit() is not None:
                    not_actionable += 1
                else:
                    if action_instance.is_permitted():
                        # Do not let execute() raise a redirect exception
                        # because this action is part of a bulk operation.
                        action_instance.execute(allow_redirect=False)
                        done += 1
                    else:
                        not_permitted += 1
            else:
                not_actionable += 1
        return done, not_actionable, not_permitted
Example #3
0
    def _node_actions(self, params, node_type):
        # Only admins can perform controller actions
        if (not reload_object(self.user).is_superuser and node_type in [
                NODE_TYPE.RACK_CONTROLLER, NODE_TYPE.REGION_CONTROLLER,
                NODE_TYPE.REGION_AND_RACK_CONTROLLER
        ]):
            return []

        actions = OrderedDict()
        for name, action in ACTIONS_DICT.items():
            if (action.node_permission == NODE_PERMISSION.ADMIN
                    and not reload_object(self.user).is_superuser):
                continue
            elif node_type in action.for_type:
                actions[name] = action
        return self.dehydrate_actions(actions)
Example #4
0
    def _node_actions(self, params, node_type):
        # Only admins can perform controller actions
        if (not self.user.is_superuser and node_type in [
                NODE_TYPE.RACK_CONTROLLER, NODE_TYPE.REGION_CONTROLLER,
                NODE_TYPE.REGION_AND_RACK_CONTROLLER]):
            return []

        actions = OrderedDict()
        for name, action in ACTIONS_DICT.items():
            admin_condition = (
                node_type == NODE_TYPE.MACHINE and
                action.machine_permission == NodePermission.admin and
                not self.user.is_superuser)
            if admin_condition:
                continue
            elif node_type in action.for_type:
                actions[name] = action
        return self.dehydrate_actions(actions)