Re: Ridding unpredictable predictable interface names

"'Nick Anderson' via help-cfengine" <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Martin Simons <[email protected]> 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 :)

....

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.

,----
| bundle agent __main__
| {
|       methods:
|       "test_link";
|       "oned";
| 
| }
| 
| 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)";
| 
| }
`----
Listing 1: Example Policy

,----
| R: test_link nics_sort: eth1
| R: test_link nics_sort: eth2
| R: test_link nics_sort: eth5
| R: test_link ip link all:     link/ether 90:2e:16:33:11:53 brd ff:ff:ff:ff:ff:ff
|     link/ether cc:6b:1e:a1:db:b7 brd ff:ff:ff:ff:ff:ff
|     link/ether 02:42:3f:46:7c:ce brd ff:ff:ff:ff:ff:ff
|     link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
|     link/ether 5c:ff:35:c6:86:4b brd ff:ff:ff:ff:ff:ff
|     link/ether 86:41:e3:36:98:ae brd ff:ff:ff:ff:ff:ff link-netnsid 1
| R: test_link ip link:     link/ether 90:2e:16:33:11:53 brd ff:ff:ff:ff:ff:ff
| R: test_link ip link:     link/ether cc:6b:1e:a1:db:b7 brd ff:ff:ff:ff:ff:ff
| R: test_link ip link:     link/ether 02:42:3f:46:7c:ce brd ff:ff:ff:ff:ff:ff
| R: test_link ip link:     link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
| R: test_link ip link:     link/ether 5c:ff:35:c6:86:4b brd ff:ff:ff:ff:ff:ff
| R: test_link ip link:     link/ether 86:41:e3:36:98:ae brd ff:ff:ff:ff:ff:ff link-netnsid 1
| R: oned _iface_mac_count: 6
| R: oned _iface_mac_count_minus_one: 5
| R: oned _iface_mac_count_seq: 0
| R: oned _iface_mac_count_seq: 1
| R: oned _iface_mac_count_seq: 2
| R: oned _iface_mac_count_seq: 3
| R: oned _iface_mac_count_seq: 4
| R: oned _iface_mac_count_seq: 5
| R: oned nics_sort: eth1
| R: oned nics_sort: eth2
| R: oned nics_sort: eth5
| R: oned nics: eth1
| R: oned nics: eth2
| R: oned nics: eth5
| Variable name                            Variable value                                               Meta tags                                Comment                                 
| default:oned._iface_mac_count            6                                                            source=promise                                                                   
| default:oned._iface_mac_count_minus_one  5                                                            source=promise                                                                   
| default:oned._iface_mac_count_seq         {"0","1","2","3","4","5"}                                   source=promise                                                                   
| default:oned.ifac2mac[eth1]              90:2e:16:33:11:53                                            source=promise                                                                   
| default:oned.ifac2mac[eth2]              cc:6b:1e:a1:db:b7                                            source=promise                                                                   
| default:oned.ifac2mac[eth5]              86:41:e3:36:98:ae                                            source=promise                                                                   
| default:oned.nic[admin]                  eth2                                                         source=promise                                                                   
| default:oned.nic[life]                   eth5                                                         source=promise                                                                   
| default:oned.nic[support]                eth1                                                         source=promise                                                                   
| default:oned.nics                         {"eth1","eth2","eth5"}                                      source=promise                                                                   
| default:oned.nics_sort                    {"eth1","eth2","eth5"}                                      source=promise                                                                   
| default:oned.nics_string                 eth1,eth2,eth5                                               source=promise                                                                   
`----

-- 
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/875yu2cc8e.fsf%40northern.tech.

-- 
Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech

-- 
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/875yu2cc8e.fsf%40northern.tech.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.