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'
973542
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):
    '''
    

    '''

    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)}
1064955
def check_route_name_conflict(namespace):
    

    route_by_name = {}
    for route in namespace.routes:
        route_name = fmt_func(route.name, version=route.version)
        if route_name in route_by_name:
            other_route = route_by_name[route_name]
            raise RuntimeError(
                'There is a name conflict between {!r} and {!r}'.format(other_route, route))
        route_by_name[route_name] = route
832525
def command_exists?(command)
      ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exist? File.join(d, command) }
    end
958472
def _add_new_route(dcidr, router_ip, vpc_info, con, route_table_id):
    
    try:
        instance, eni = find_instance_and_eni_by_ip(vpc_info, router_ip)
        # Only set the route if the RT is associated with any of the subnets
        # used for the cluster.
        rt_subnets           = \
                    set(vpc_info['rt_subnet_lookup'].get(route_table_id, []))
        cluster_node_subnets = \
                    set(vpc_info['cluster_node_subnets'])
        if not rt_subnets or not rt_subnets.intersection(cluster_node_subnets):
            logging.debug("--- skipping adding route in RT '%s' "
                          "%s -> %s (%s, %s) since RT's subnets (%s) are not "
                          "part of the cluster (%s)." %
                          (route_table_id, dcidr, router_ip, instance.id,
                           eni.id,
                           ", ".join(rt_subnets) if rt_subnets else "none",
                           ", ".join(cluster_node_subnets)))
            return

        logging.info("--- adding route in RT '%s' "
                     "%s -> %s (%s, %s)" %
                     (route_table_id, dcidr, router_ip, instance.id, eni.id))
        con.create_route(route_table_id         = route_table_id,
                         destination_cidr_block = dcidr,
                         instance_id            = instance.id,
                         interface_id           = eni.id)
        CURRENT_STATE.routes[dcidr] = \
                                    (router_ip, str(instance.id), str(eni.id))
        _rt_state_update(route_table_id, dcidr, router_ip, instance.id, eni.id,
                         msg="Added route")

    except Exception as e:
        logging.error("*** failed to add route in RT '%s' "
                      "%s -> %s (%s)" %
                      (route_table_id, dcidr, router_ip, e.message))
        _rt_state_update(route_table_id, dcidr,
                         msg="[ERROR add route: %s]" % e.message)
166684
def exists(self, relpath, rsc=None, useFilepath=None):
        
        path = self.find(relpath, rsc, useFilepath)
        if path.startswith(':'):
            return QtCore.QResource(path).isValid()
        else:
            return os.path.exists(path)
391519
def ensure_path_exists(self):
        # type: (LocalDestinationPath) -> None
        
        if self._is_dir is None:
            raise RuntimeError('is_dir not set')
        if self._is_dir:
            self._path.mkdir(mode=0o750, parents=True, exist_ok=True)
        else:
            if self._path.exists() and self._path.is_dir():
                raise RuntimeError(
                    ('destination path {} already exists and is a '
                     'directory').format(self._path))
            else:
                # ensure parent path exists and is created
                self._path.parent.mkdir(
                    mode=0o750, parents=True, exist_ok=True)
633383
def exists(self):
        
        try:
            self.stat()
        except OSError as e:
            if e.errno not in (ENOENT, ENOTDIR):
                raise
            return False
        return True
371950
def key_exists(key_id, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    try:
        key = conn.describe_key(key_id)
        # TODO: add to context cache
        r['result'] = True
    except boto.exception.BotoServerError as e:
        if isinstance(e, boto.kms.exceptions.NotFoundException):
            r['result'] = False
            return r
        r['error'] = __utils__['boto.get_error'](e)
    return r
321317
def exists(vpc_id=None, name=None, cidr=None, tags=None, region=None, key=None,
           keyid=None, profile=None):
    '''
    

    '''

    try:
        vpc_ids = _find_vpcs(vpc_id=vpc_id, vpc_name=name, cidr=cidr, tags=tags,
                             region=region, key=key, keyid=keyid, profile=profile)
    except BotoServerError as err:
        boto_err = __utils__['boto.get_error'](err)
        if boto_err.get('aws', {}).get('code') == 'InvalidVpcID.NotFound':
            # VPC was not found: handle the error and return False.
            return {'exists': False}
        return {'error': boto_err}

    return {'exists': bool(vpc_ids)}
1265886
def _check_rule(rule, _rule):
    '''
    
    '''

    # We need to alter what Boto returns if no ports are specified
    # so that we can compare rules fairly.
    #
    # Boto returns None for from_port and to_port where we're required
    # to pass in "-1" instead.
    if _rule.get('from_port') is None:
        _rule['from_port'] = -1
    if _rule.get('to_port') is None:
        _rule['to_port'] = -1

    if (rule['ip_protocol'] == _rule['ip_protocol'] and
            six.text_type(rule['from_port']) == six.text_type(_rule['from_port']) and
            six.text_type(rule['to_port']) == six.text_type(_rule['to_port'])):
        _cidr_ip = _rule.get('cidr_ip')
        if _cidr_ip and _cidr_ip == rule.get('cidr_ip'):
            return True
        _owner_id = _rule.get('source_group_owner_id')
        if _owner_id and _owner_id == rule.get('source_group_owner_id'):
            return True
        _group_id = _rule.get('source_group_group_id')
        if _group_id and _group_id == rule.get('source_group_group_id'):
            return True
        _group_name = _rule.get('source_group_name')
        if _group_name and _group_id == rule.get('source_group_name'):
            return True
    return False
1185548
def exists(self, name):
        
        with self.pipe as pipe:
            return pipe.exists(self.redis_key(name))
993911
def path_exists(self, dest, weight=None):
        
        try:
            return bool(self.shortest_path_length(dest, weight))
        except KeyError:
            return False
1366200
def check_path_exists_foreach(path_params, func):
    
    @wraps(func)
    def wrapper(*args):
        self = args[0]
        params = args[1]

        if not self.in_transaction:
            for name in path_params:
                value = getattr(params, name)
                paths = value if type(value) == list else [value]
                resolved = []
                for path in paths:
                    path = self.resolve_path(path)
                    if not self.client.exists(path):
                        self.show_output("Path %s doesn't exist", path)
                        return False
                    resolved.append(path)

                if type(value) == list:
                    setattr(params, name, resolved)
                else:
                    setattr(params, name, resolved[0])

        return func(self, params)

    return wrapper
377452
def is_cidr_in_cidr(small_cidr, big_cidr):
    
    # The default route (0.0.0.0/0) is handled differently, since every route
    # would always be contained in there. Instead, only a small CIDR of
    # "0.0.0.0/0" can match against it. Other small CIDRs will always result in
    # 'False' (not contained).
    if small_cidr == "0.0.0.0/0":
        return big_cidr == "0.0.0.0/0"
    else:
        if big_cidr == "0.0.0.0/0":
            return False

    s = ipaddress.IPv4Network(unicode(small_cidr))
    b = ipaddress.IPv4Network(unicode(big_cidr))
    return s.subnet_of(b)
822021
def network_route_exists?(network, nat_server_ip)
      routes = routes_show()
      matchdata = routes.match(route_regex(network, nat_server_ip))
      matchdata != nil
    end
130164
def policy_exists(policy_name,
                  region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        conn.get_policy(_get_policy_arn(policy_name,
                    region=region, key=key, keyid=keyid, profile=profile))
        return True
    except boto.exception.BotoServerError:
        return False
78348
def exists(self):
        """"""

        try:
            self.s3_object.load()
            return True
        except botocore.exceptions.ClientError: return False