Page MenuHomeFreeBSD

/usr/libexec/flua: Add bindings for libifconfig
Changes PlannedPublic

Authored by freqlabs on Thu, Jun 25, 11:08 AM.

Details

Reviewers
kevans
emaste
kp
Summary

Add Lua bindings for libifconfig to flua.

Throwing this on phab to see if anyone has a use case for it. Otherwise, I don't have plans to commit it yet. libifconfig really should have more features. I should probably start an examples directory for flua, too.

Test Plan
#!/usr/libexec/flua

ifcfg = require('ifconfig').open()
ucl = require('ucl')

ifaces = ifcfg:foreach_iface(function(_, iface, ifs)
    local name = iface:name()
    ifs[name] = {
        media = ifcfg:get_media(name),
        status = ifcfg:get_status(name),
        capabilities = ifcfg:get_capability(name),
        groups = ifcfg:get_groups(name),
        metric = ifcfg:get_metric(name),
        mtu = ifcfg:get_mtu(name),
        nd6 = ifcfg:get_nd6(name),
        lagg_status = ifcfg:get_lagg_status(name),
        laggdev = ifcfg:get_laggport_laggdev(name),
        addresses = ifcfg:foreach_ifaddr(iface, function(_, addr, addrs)
            table.insert(addrs, ifcfg:addr_info(addr))
            return addrs
        end, {})
    }
    return ifs
end, {})

function yaml(obj)
    print(ucl.to_format(obj, "yaml"))
end

yaml(ifaces)

ifcfg:get_status("usb")
print(ifcfg:error())

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

freqlabs created this revision.Thu, Jun 25, 11:08 AM
freqlabs requested review of this revision.Thu, Jun 25, 11:08 AM
kevans added a reviewer: kp.Thu, Jun 25, 11:39 AM

Tossing kp in the mix for the giggles of it

Perhaps useful for network testing purposes?

pstef added a subscriber: pstef.Thu, Jun 25, 2:39 PM

I can see some potential for automation and orchestration.

kp added a comment.Thu, Jun 25, 6:35 PM

Without immediate users for this it's probably a bit early to commit this, but I like the notion.
If nothing else it gives a bit more sample code of how we can wrap things in Lua, and I could also see use cases for base-system scripting where we may want something other than shell to do things in.

freqlabs planned changes to this revision.Fri, Jun 26, 3:35 AM

Thanks for the feedback. Definitely early days for all this. I'm continuing the work over on gitlab to avoid too much phabricator spam for the time being :)
https://gitlab.com/freqlabs/lua-libifconfig

linimon retitled this revision from flua: Add bindings for libifconfig to /usr/libexec/flua: Add bindings for libifconfig.Fri, Jun 26, 7:57 AM