from parallels.core.actions.base.common_action import CommonAction
from parallels.core.logging import get_logger
from parallels.plesk.source.custom import messages


logger = get_logger(__name__)


class RemoveAgent(CommonAction):
    """Remove agent from source server"""

    def get_failure_message(self, global_context):
        """Get message for situation when action failed

        :type global_context: parallels.core.global_context.GlobalMigrationContext
        :rtype: str | unicode
        """
        return messages.ACTION_FAILED_REMOVE_AGENT

    def get_description(self):
        """Get short description of action as string

        :rtype: str | unicode
        """
        return messages.ACTION_DESCRIPTION_REMOVE_AGENT

    def filter_action(self, global_context):
        """Check whether we should run this action or not. By default True - action should be executed.

        Arguments:
        - global_context - registry with different objects that reused among different actions

        :type global_context: parallels.plesk.source.custom.global_context.CustomPanelGlobalMigrationContext
        :rtype: bool
        """
        return not global_context.agent_pool.is_empty()

    def run(self, global_context):
        """Run action

        :type global_context: parallels.plesk.source.custom.global_context.CustomPanelGlobalMigrationContext
        :rtype: None
        """
        global_context.agent_pool.remove_all()
