Checks if a route exists.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_vpc.route_exists destination_cidr_block='10.0.0.0/20' gateway_id='local' route_table_name='test'

def route_exists(destination_cidr_block, route_table_name=None, route_table_id=None,
                 gateway_id=None, instance_id=None, interface_id=None, tags=None,
                 region=None, key=None, keyid=None, profile=None, vpc_peering_connection_id=None):
    '''
    Checks if a route exists.

    .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt myminion boto_vpc.route_exists destination_cidr_block='10.0.0.0/20' gateway_id='local' route_table_name='test'

    '''

    if not any((route_table_name, route_table_id)):
        raise SaltInvocationError('At least one of the following must be specified: route table name or route table id.')

    if not any((gateway_id, instance_id, interface_id, vpc_peering_connection_id)):
        raise SaltInvocationError('At least one of the following must be specified: gateway id, instance id, '
                                  'interface id or VPC peering connection id.')

    try:
        conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
        filter_parameters = {'filters': {}}

        if route_table_id:
            filter_parameters['route_table_ids'] = [route_table_id]

        if route_table_name:
            filter_parameters['filters']['tag:Name'] = route_table_name

        if tags:
            for tag_name, tag_value in six.iteritems(tags):
                filter_parameters['filters']['tag:{0}'.format(tag_name)] = tag_value

        route_tables = conn.get_all_route_tables(**filter_parameters)

        if len(route_tables) != 1:
            raise SaltInvocationError('Found more than one route table.')

        route_check = {'destination_cidr_block': destination_cidr_block,
                       'gateway_id': gateway_id,
                       'instance_id': instance_id,
                       'interface_id': interface_id,
                       'vpc_peering_connection_id': vpc_peering_connection_id
                       }

        for route_match in route_tables[0].routes:

            route_dict = {'destination_cidr_block': route_match.destination_cidr_block,
                          'gateway_id': route_match.gateway_id,
                          'instance_id': route_match.instance_id,
                          'interface_id': route_match.interface_id,
                          'vpc_peering_connection_id': vpc_peering_connection_id
                          }
            route_comp = set(route_dict.items()) ^ set(route_check.items())
            if not route_comp:
                log.info('Route %s exists.', destination_cidr_block)
                return {'exists': True}

        log.warning('Route %s does not exist.', destination_cidr_block)
        return {'exists': False}
    except BotoServerError as e:
        return {'error': __utils__['boto.get_error'](e)}