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.
Differential D25447
lib/flua: Add bindings for libifconfig freqlabs on Jun 25 2020, 11:08 AM. Authored by Tags None Referenced Files
Details 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. #!/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
Event TimelineComment Actions Without immediate users for this it's probably a bit early to commit this, but I like the notion. Comment Actions 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 :) Comment Actions Updated diff to include man page, example code, build as a lua module instead of embedded in flua. There is still quite a bit of functionality missing from libifconfig that makes this feel poorly fleshed out. Comment Actions From the first look the man page should be fine. Did you run igor and mandoc -Tlint against it? Comment Actions Avoid tracking stack index manually when we know the position relative to the top. We're usually using the index to set a field on a table immediately under a value on the top of the stack, so the index can be specified as -2 rather than the absolute index. Fixed empty media options table. I forgot to pop the option names off the stack and into the table after pushing the string. Further refinement of the media table format: rather than setting "<unknown type>", "<unknown subtype>", or "<unknown mode>", just leave the field out of the table and let the caller decide if/how they want to display the nil field. This idea stems from mode only really being a thing for wifi, and seeing "mode": "<unknown mode>" on every Ethernet interface for example is not ideal. Note to self: update the documentation for the mode table format in the man page, too. Comment Actions Changed the format of lagg ports to a table keyed by the interface name, so rather than "ports": [ { "lacp_state": [ "ACTIVITY", "AGGREGATION", "SYNC", "COLLECTING", "DISTRIBUTING" ], "flags": [ "ACTIVE", "COLLECTING", "DISTRIBUTING" ], "laggport": "igb0" }, { "lacp_state": [ "ACTIVITY", "AGGREGATION", "SYNC", "COLLECTING", "DISTRIBUTING" ], "flags": [ "ACTIVE", "COLLECTING", "DISTRIBUTING" ], "laggport": "igb1" } ], we now have "ports": { "igb0": { "lacp_state": [ "ACTIVITY", "AGGREGATION", "SYNC", "COLLECTING", "DISTRIBUTING" ], "flags": [ "ACTIVE", "COLLECTING", "DISTRIBUTING" ] }, "igb1": { "lacp_state": [ "ACTIVITY", "AGGREGATION", "SYNC", "COLLECTING", "DISTRIBUTING" ], "flags": [ "ACTIVE", "COLLECTING", "DISTRIBUTING" ] } }, Updated the man page to reflect recent changes to table formats. |