<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def stopall(self, sudo=False, quiet=True):
    '''stop ALL instances. This command is only added to the command group
       as it doesn't make sense to call from a single instance

       Parameters
       ==========
       sudo: if the command should be done with sudo (exposes different set of
             instances)

    '''
    from spython.utils import run_command, check_install
    check_install()

    subgroup = 'instance.stop'

    if 'version 3' in self.version():
        subgroup = ["instance", "stop"]

    cmd = self._init_command(subgroup)
    cmd = cmd + ['--all']
    output = run_command(cmd, sudo=sudo, quiet=quiet)

    if output['return_code'] != 0:
        message = '%s : return code %s' %(output['message'], 
                                          output['return_code'])
        bot.error(message)
        return output['return_code']

    return output['return_code']