On 05/22/2012 04:03 PM, no-re...@cfengine.com wrote:
> Forum: CFEngine Help
> Subject: Replace underscores in interface names (creating routes)
> Author: alan.hatch
> Link to topic: https://cfengine.com/forum/read.php?3,26010,26010#msg-26010
>
> We are using interface aliases with periods that are being converted into 
> underscores in certain cases.  I am trying to create a file called 
> route-bond0.748 using only cfengine goodness so servers on two different 
> administrative networks talk accross the correct interface:
>
> bundle agent test_linux {
>
> vars:
>
>       "local_ip_addresses" slist =>  { @(sys.ip_addresses) };
>      "nics" slist =>  getindices("sys.ipv4");
>      "interfaces" slist =>  { @(sys.interfaces) };
>
>
> classes:
>
>      "core_ip_dc1_$(nics)"          expression =>  
> regcmp("(10\.152\.48\..*)","$(sys.ipv4[$(nics)])");
>      "core_ip_dc2_$(nics)"           expression =>  
> regcmp("(10\.154\.48\..*)","$(sys.ipv4[$(nics)])");
>
> reports:
>
>      test01lp::
>
>          "NICS: $(nics)";
>
>          "INTERFACE: $(interfaces)";
>
>          "ROUTE: 10.152.48.0/24 via $(sys.ipv4[$(nics)]) dev $(nics)"
>              ifvarclass =>  "core_ip_dc2_$(nics)";
>
>          "ROUTE: 10.154.48.0/24 via $(sys.ipv4[$(nics)]) dev $(nics)"
>              ifvarclass =>  "core_ip_dc1_$(nics)";
>
> }
>
> Which shows:
>
> R: NICS: bond0_724
> R: NICS: bond0_748
> R: INTERFACE: bond0.724
> R: INTERFACE: bond0.748
> R: ROUTE: 10.152.48.0/24 via 10.154.48.9 dev bond0_748
>
> So I can access the actual interface name in a list, but the same entry in 
> the required associative array has an underscore.
>
> I need to be able to create the file named "route-interface"  at a minimum. 
> Changing the interface names is probably not an option.
>
> Any help would be appreciated.

It looks like $(nics) and $(interfaces) are in the same order, but I 
don't think there is any guarantee that they will remain that way.

You could create an array with the canonized version of the interface 
which should be the same as the index of sys.ipv4, but I think order is 
guaranteed this way.

Here is an example
https://gist.github.com/2772554


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to