Handles global secondary index for the table present state.

def _global_indexes_present(provisioned_indexes, global_indexes, changes_old,
                            changes_new, comments, name, region, key, keyid,
                            profile):
    '''Handles global secondary index for the table present state.'''
    ret = {'result': True}
    if provisioned_indexes:
        provisioned_gsi_config = dict((index['IndexName'], index) for index in provisioned_indexes)
    else:
        provisioned_gsi_config = {}
    provisioned_index_names = set(provisioned_gsi_config.keys())

    # Map of index name to given Salt config for this run. This loop is complicated
    # because global_indexes is made up of OrderedDicts and lists.
    gsi_config = {}
    if global_indexes:
        for index in global_indexes:
            # Each index config is a key that maps to a list of OrderedDicts.
            index_config = index.values()[0]
            index_name = None
            for entry in index_config:
                # Key by the name field in the index config.
                if entry.keys() == ['name']:
                    index_name = entry.values()[0]
            if not index_name:
                ret['result'] = False
                ret['comment'] = 'Index name not found for table {0}'.format(name)
                return ret
            gsi_config[index_name] = index

    existing_index_names, new_index_names, index_names_to_be_deleted = _partition_index_names(
        provisioned_index_names, set(gsi_config.keys()))

    if index_names_to_be_deleted:
        ret['result'] = False
        ret['comment'] = ('Deletion of GSIs ({0}) is not supported! Please do this '
                          'manually in the AWS console.'.format(', '.join(index_names_to_be_deleted)))
        return ret
    elif len(new_index_names) > 1:
        ret['result'] = False
        ret['comment'] = ('Creation of multiple GSIs ({0}) is not supported due to API '
                          'limitations. Please create them one at a time.'.format(new_index_names))
        return ret

    if new_index_names:
        # Given the length check above, new_index_names should have a single element here.
        index_name = next(iter(new_index_names))
        _add_global_secondary_index(ret, name, index_name, changes_old, changes_new, comments,
                                    gsi_config, region, key, keyid, profile)
        if not ret['result']:
            return ret

    if existing_index_names:
        _update_global_secondary_indexes(ret, changes_old, changes_new, comments,
                                         existing_index_names, provisioned_gsi_config, gsi_config,
                                         name, region, key, keyid, profile)
        if not ret['result']:
            return ret

    if 'global_indexes' not in changes_old and 'global_indexes' not in changes_new:
        comments.append('All global secondary indexes match')
    return ret