def _get_policy_object(platform,
                       filters=None,
                       pillar_key='acl',
                       pillarenv=None,
                       saltenv=None,
                       merge_pillar=True):
    '''
    Return an instance of the ``_Policy`` class given the filters config.
    '''
    policy = _Policy()
    policy_filters = []
    if not filters:
        filters = []
    for filter_ in filters:
        if not filter_ or not isinstance(filter_, dict):
            continue  # go to the next filter
        filter_name = filter_.keys()[0]
        filter_config = filter_.values()[0]
        header = capirca.lib.policy.Header()  # same header everywhere
        target_opts = [
            platform,
            filter_name
        ]
        filter_options = filter_config.pop('options', None)
        if filter_options:
            filter_options = _make_it_list({}, filter_name, filter_options)
            # make sure the filter options are sent as list
            target_opts.extend(filter_options)
        target = capirca.lib.policy.Target(target_opts)
        header.AddObject(target)
        filter_terms = []
        for term_ in filter_config.get('terms', []):
            if term_ and isinstance(term_, dict):
                term_name = term_.keys()[0]
                term_fields = term_.values()[0]
                term = _get_term_object(filter_name,
                                        term_name,
                                        pillar_key=pillar_key,
                                        pillarenv=pillarenv,
                                        saltenv=saltenv,
                                        merge_pillar=merge_pillar,
                                        **term_fields)
            filter_terms.append(term)
        policy_filters.append(
            (header, filter_terms)
        )
    policy.filters = policy_filters
    log.debug('Policy config:')
    log.debug(six.text_type(policy))
    platform_generator = _import_platform_generator(platform)
    policy_config = platform_generator(policy, 2)
    log.debug('Generating policy config for %s:', platform)
    log.debug(six.text_type(policy_config))
    return policy_config
def _get_policy_object ( platform , filters = None , pillar_key = 'acl' , pillarenv = None , saltenv = None , merge_pillar = True ) : policy = _Policy ( ) policy_filters = [ ] if not filters : filters = [ ] for filter_ in filters : if not filter_ or not isinstance ( filter_ , dict ) : continue filter_name = filter_ . keys ( ) [ 0 ] filter_config = filter_ . values ( ) [ 0 ] header = capirca . lib . policy . Header ( ) target_opts = [ platform , filter_name ] filter_options = filter_config . pop ( 'options' , None ) if filter_options : filter_options = _make_it_list ( { } , filter_name , filter_options ) target_opts . extend ( filter_options ) target = capirca . lib . policy . Target ( target_opts ) header . AddObject ( target ) filter_terms = [ ] for term_ in filter_config . get ( 'terms' , [ ] ) : if term_ and isinstance ( term_ , dict ) : term_name = term_ . keys ( ) [ 0 ] term_fields = term_ . values ( ) [ 0 ] term = _get_term_object ( filter_name , term_name , pillar_key = pillar_key , pillarenv = pillarenv , saltenv = saltenv , merge_pillar = merge_pillar , ** term_fields ) filter_terms . append ( term ) policy_filters . append ( ( header , filter_terms ) ) policy . filters = policy_filters log . debug ( 'Policy config:' ) log . debug ( six . text_type ( policy ) ) platform_generator = _import_platform_generator ( platform ) policy_config = platform_generator ( policy , 2 ) log . debug ( 'Generating policy config for %s:' , platform ) log . debug ( six . text_type ( policy_config ) ) return policy_config
Return an instance of the ``_Policy`` class given the filters config.