Re: Ridding unpredictable predictable interface names
Martin Simons <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
On Tuesday, 12 October 2021 at 20:46:44 UTC+2 Nick Anderson wrote:
> Martin Simons writes:
>
> Dear Nick,
>
> Teh example polcy does not work for me, I have to find out how to work
> around 'with'.
>
> Upgrade to 3.18 :)
>
Well, unfortunately I do depend on the resolution of CFEngine
CommunityCFE-3446 Variable expanding in 3.7.5 no longer expands in 3.10 and
higher
:-)
This bug breaks my entire design of roles and components.
> ….
>
> I still struggle to follow your example. I hacked at the snippet you
> posted, and maybe I achieved what you were looking for, but I did use the
> with attribute.
>
May be we should simplify the example to the bare minimum and accept the
assumption that the lists of nics and macs match.
Not very pretty, but suppose you calculate the length op the list and next
to it create a long enough pseudo list containing integers (keys). The use
the eval function to determine wheather or not an nth element should be
processed.
Working on it in the background, have to join the wife for a moment or two.
bundle agent nic_mac_map {
vars:
"macs" slist => { "eth1" , "eth2", "eth5" };
"macs_string" string => join(",", "macs");
"mac_list_len" int => length("macs");
"nic[support]" string => "eth1";
"nic[admin]" string => "eth2";
"nic[life]" string => "eth5";
"nics" slist => getvalues("nic");
"nics_sort" slist => sort("nics", lex);
"nics_string" string => join(",", "nics_sort");
methods:
"map nics and macs" usebundle =>
match_nic_mac($(mac_list_len));
reports:
"$(this.bundle) macs sort: $(macs)";
"$(this.bundle) macs length: $(mac_list_len)";
"$(this.bundle) nics_sort: $(nics_sort)";
}
bundle agent match_nic_mac (mac_nth) {
#classes:
#"eth_$(nic)"
reports:
"$(this.bundle) mac: $(mac_nth)";
}
body common control {
bundlesequence => { "nic_mac_map", };
inputs => { "/var/cfengine/inputs/lib/3.7/stdlib.cf",
};
}
Listing 1: Example Policy
>
> bundle agent __main__{
> methods:
> "test_link";
>
> }
> bundle agent test_link {
> vars:
>
> "ip_link_all"
> string => execresult("/usr/sbin/ip link | grep 'ether' ", useshell);
>
> "ip_link_mac"
> slist => string_split($(ip_link_all), "\n", 99);
>
> reports:
>
> "$(this.bundle) nics_sort: $(oned.nics_sort)";
> "$(this.bundle) ip link all: $(ip_link_all)";
> "$(this.bundle) ip link: $(ip_link_mac)";
> }
> bundle agent oned {
> vars:
>
> ;
>
> "nic[support]" string => "eth1";
> "nic[admin]" string => "eth2";
> "nic[life]" string => "eth5";
>
> "nics" slist => getvalues("nic");
> "nics_sort" slist => sort("nics", lex);
> "nics_string" string => join(",", "nics_sort")
>
> "_iface_mac_count" int => length( "test_link.ip_link_mac" );
> "_iface_mac_count_minus_one" string => format( "%d", eval( "$(_iface_mac_count)-1", "math", "infix") );
> "_iface_mac_count_seq" slist => expandrange( "[0-$(_iface_mac_count_minus_one)]", 1);
>
> "ifac2mac[$(with)]"
> with => nth(nics_sort, $(_iface_mac_count_seq)),
> #string => nth( "test_link.ip_link_mac", $(_iface_mac_count_seq) );
> string => nth(string_split( nth( "test_link.ip_link_mac", $(_iface_mac_count_seq) ), "\s+", inf), 2);
> reports:
>
> "$(this.bundle) _iface_mac_count: $(_iface_mac_count)";
> "$(this.bundle) _iface_mac_count_minus_one: $(_iface_mac_count_minus_one)";
> "$(this.bundle) _iface_mac_count_seq: $(_iface_mac_count_seq)";
>
>
> "$(this.bundle) nics_sort: $(nics_sort)";
> "$(this.bundle) nics: $(nics)";
> }
>
>
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/9d51fa69-6ac3-4884-8aa4-84f7d133ce00n%40googlegroups.com.