def do_host_upgrade(cc, args):
    """Perform software upgrade for a host."""
    system_type, system_mode = utils._get_system_info(cc)
    simplex = system_mode == constants.SYSTEM_MODE_SIMPLEX

    if simplex:
        warning_message = (
            '\n'
            'WARNING: THIS OPERATION WILL COMPLETELY ERASE ALL DATA FROM THE '
            'SYSTEM.\n'
            'Only proceed once the system data has been copied to another '
            'system.\n'
            'Are you absolutely sure you want to continue?  [yes/N]: ')
        confirm = input(warning_message)
        if confirm != 'yes':
            print("Operation cancelled.")
            return

    ihost = cc.ihost.upgrade(args.hostid, args.force)
    _print_ihost_show(ihost)
def do_upgrade_abort(cc, args):
    """Abort a software upgrade."""
    try:
        body = cc.upgrade.check_reinstall()
    except Exception:
        raise exc.CommandError('Error getting upgrade state')

    reinstall_necessary = body.get('reinstall_necessary', None)

    abort_required = False
    system_type, system_mode = utils._get_system_info(cc)

    is_cpe = system_type == constants.TS_AIO
    simplex = system_mode == constants.SYSTEM_MODE_SIMPLEX
    if simplex:
        if reinstall_necessary:
            warning_message = (
                '\n'
                'WARNING: THIS OPERATION WILL RESULT IN A COMPLETE SYSTEM '
                'OUTAGE.\n'
                'It will require this host to be reinstalled and the system '
                'restored with the previous version. '
                'The system will be restored to when the upgrade was started.'
                '\n\n'
                'Are you absolutely sure you want to continue? [yes/N]: ')
            abort_required = True
        else:
            warning_message = (
                '\n'
                'WARNING: This will stop the upgrade process. The system '
                'backup created during the upgrade-start will be removed.\n\n'
                'Continue [yes/N]: ')
    elif reinstall_necessary:
        warning_message = (
            '\n'
            'WARNING: THIS OPERATION WILL RESULT IN A COMPLETE SYSTEM '
            'OUTAGE.\n'
            'It will require every host in the system to be powered down and '
            'then reinstalled to recover. All instances will be lost, '
            'including their disks. You will only be able to recover '
            'instances if you have external backups for their data.\n'
            'This operation should be done as a last resort, if there is '
            'absolutely no other way to recover the system.\n\n'
            'Are you absolutely sure you want to continue? [yes/N]: ')
        abort_required = True
    else:
        if is_cpe:
            warning_message = (
                '\n'
                'WARNING: THIS OPERATION WILL IMPACT RUNNING INSTANCES.\n'
                'Any instances that have been migrated after the upgrade was '
                'started will be lost, including their disks. You will only '
                'be able to recover instances if you have external backups '
                'for their data.\n'
                'This operation should be done as a last resort, if there is '
                'absolutely no other way to recover the system.\n\n'
                'Are you absolutely sure you want to continue?  [yes/N]: ')
            abort_required = True
        else:
            warning_message = (
                '\n'
                'WARNING: By continuing this operation, you will be forced to '
                'downgrade any hosts that have been upgraded. The system will '
                'revert to the state when controller-0 was last active.\n\n'
                'Continue [yes/N]: ')

    confirm = raw_input(warning_message)
    if confirm != 'yes':
        print "Operation cancelled."
        return
    elif abort_required:
        confirm = raw_input("Type 'abort' to confirm: ")
        if confirm != 'abort':
            print "Operation cancelled."
            return

    data = dict()
    data['state'] = constants.UPGRADE_ABORTING

    patch = []
    for (k, v) in data.items():
        patch.append({'op': 'replace', 'path': '/' + k, 'value': v})
    try:
        upgrade = cc.upgrade.update(patch)
    except exc.HTTPNotFound:
        raise exc.CommandError('Upgrade UUID not found')
    _print_upgrade_show(upgrade)