Re: Ridding unpredictable predictable interface names
Martin Simons <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Dear Nick,
Teh example polcy does not work for me, I have to find out how to work
around 'with'.
So it boils down to the fact that I want to create, what you would call a
dictionary in Pythonese.
Manually:
eth_map = { "eth1" : "52:54:00:40:13:98", "eth2" : "52:54:00:40:13:99",
"eth5" : "52:54:00:40:13:9a" }
or automated:
keys_list = [ "eth1" , "eth2", "eth5" ]
values_list = ["52:54:00:40:13:98", "52:54:00:40:13:99",
"52:54:00:40:13:9a" ]
zip_iterator = zip(keys_list, values_list)
a_dictionary = dict(zip_iterator)
print(a_dictionary)
or in CFEngine if it were done manually in an array ( a data container
would be possible too):
"eth_map[eth1]" string => "52:54:00:40:13:98";
"eth_map[eth2]" string => "52:54:00:40:13:99";
"eth_map[eth5]" string => "52:54:00:40:13:9a";
Any subsequent policy using an editing template would work.
> How do you know that mac 52:54:00:64:0d:0d should be mapped to eth2"
The policy is presented with the interface names in sorted order.
The name of the role is 'oned', the nics come from oned.nics_sort.
ip link fetches the mac addresses from the hypervisor.
Like this:
"ip_link_all" string =>
execresult("/usr/sbin/ip link | grep 'ether' ", useshell);
"ip_link_mac" slist =>
string_split($(ip_link_all), "\n", 99);
So my solutions would be to build a python module to do the job. :-(
The entire policy set is below.
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");
reports:
"$(this.bundle) nics_sort: $(nics_sort)";
"$(this.bundle) nics: $(nics)";
}
body common control {
bundlesequence => { "oned", "test_link", };
inputs => { "/var/cfengine/inputs/lib/3.7/stdlib.cf",
"/root/classify.cf",
"/root/oned.cf", };
}
On Tuesday, 12 October 2021 at 17:09:55 UTC+2 Nick Anderson wrote:
> Martin Simons <[email protected]> writes:
>
> I have two lists that I want to pair, like this: macs slist => {
>> '52:54:00:64:0d:0c', '52:54:00:64:0d:0d ' }; Interfaces slist => { 'eth1',
>> 'eth2' }; I want an array or container like this: persistent[eth1] string
>> => '52:54:00:64:0d:0c'; persistent[eth2] string => '52:54:00:64:0d:0d'; I
>> looked over the functions again and again but I do not get it right. How do
>> I pair those into an array?
>>
> I don't think that there are any native functions that deal with mapping
> mac addresses to interface names, only interface names and IP addresses (
> iprange()
> <https://docs.cfengine.com/docs/3.18/reference-functions-iprange.html>).
> sys.hardware_mac
> <https://docs.cfengine.com/docs/3.18/reference-special-variables-sys.html#sys-hardware_mac-interface_name>
> maps mac addresses to interface names.
> Listing 1: Example Policy
>
> bundle agent __main__{
> reports:
> "$(with)" with => storejson( "sys.hardware_mac" );}
>
>
> R: {
> "docker0": "02:42:3f:46:7c:ce",
> "enx5cff35c6864b": "5c:ff:35:c6:86:4b",
> "tun0": "00:00:00:00:00:00",
> "vboxnet0": "0a:00:27:00:00:00"
> }
>
> Are you able to use that directly?
>
> If not, you need some way to link the mac address to the name, it's not
> clear to me from above what that mapping data looks like. How do you know
> that mac 52:54:00:64:0d:0d should be mapped to eth2?
>
--
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/7668af69-99a2-4925-ae40-7857dec57967n%40googlegroups.com.