Forum: CFEngine Help
Subject: ifvarclass and "Unable to parse class expression"
Author: svenXY
Link to topic: https://cfengine.com/forum/read.php?3,23678,23678#msg-23678

Hi,

I'm currently trying to develop a bundle that will allow me to create secondary 
(virtual) IP4-Interfaces, but I'm already stuck when trying to find out which 
is the next "free" number.

Here's the code:


body common control
{
        version => "1.0.0";
        bundlesequence => { "nw_setup" };
}

bundle agent nw_setup {

  methods:
    "ok"  usebundle => network_iface("eth0", "192.168.1.1");

}

bundle agent network_iface (base_iface, addr4)
{

 # run execresult of "ip a s "
 # parse the result with regextract and find virtual interfaces (:0, :1, ...) 
that are already there
 # try to find the next "free" number"

  vars:
    "ipdata"  string => execresult("/sbin/ip address show ${base_iface}", 
"noshell");
    "ip4"     string => canonify("${addr4}");
    "virtuals" slist => {"0", "1", "2", "3", "4", "5", "6" };

  classes:

   "ok" expression => regextract(
                                "inet .* scope global secondary 
${base_iface}:(\d+)",
                                "${ipdata}",
                                "virtual_ifaces"
                                ),
      comment => "Extract interface last numbers like eth0:1 should be 1";


    # set the class if a secondary interface of this name already exists:
    "has_${base_iface}_${virtuals}" expression => regarray( "virtual_ifaces", 
"^${virtuals}$");

  vars:

    # the idea here is to find the number for the first virtual interface that 
does not yet 
    # exist and then set the class "has_next_interface" to prevent this from 
continuing the loop.

    !has_next_iface::
      "next_iface"
        string     => "${virtuals}",
        classes    => "has_next_interface",
        
        # the ifavarclass is the problem, I only get the error message as in 
the subject.
        ifvarclass => not(classify("has_${base_iface}_${virtuals}"));

  reports:
    linux::
      "the next virtual interface for ${base_iface} will be 
${base_iface}:$(next_iface}";


}

body classes if_repaired(x)
{
    promise_repaired => { "$(x)" };
}



The error message looks like broken utf-8 encoduings or so, maybe this helps.

Ideas? Hints?

Cheers,
Sven

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

Reply via email to