puppetlabs/facter — pull request #267 by apenney (2012-07-22 17:47:56+00:00)
Title: Rework Facter::Util::IP and ipaddress/ipaddress6/interfaces facts (WIP)

Hi,

I'm issuing this pull request now despite this being in a work in progress as this has turned into a lot of changes to some pretty fundamental stuff, some of wish had no tests so it's not easy to tell if I've broken something. I'm looking for feedback about my general idea - reworking Util::IP to be more flexible in the face of operating systems that require different commands for ipv4 and ipv6 as well as unifying a bunch of code that was scattered throughout the ipaddress/ipaddress6 facts.

Most of the work was focused on building a Facter::Util::IP.ipaddress that can take an interface and ipversion and spit out an appropriate ipaddress. To do this I built a nested hash table that allows us to specify different commands, regexps, and tokens per operating system and per ipversion. This was specifically to support Windows, which uses two different commands/formats depending on if you're looking at ipv4 or ipv6.

Most of the rest of the changes you'll see are just to support that and move things to using .ipaddress where appropriate. There's still work more to be done and I'd like to continue killing REGEX_MAP and moving the macaddress/netmask stuff that's still in there to the other hash so it's all unified again.

I wanted to take a breather at this point and make sure this approach is OK and that it's ok for a fact like ipaddress to just simply be a call out to helper util stuff like it is right now.

The code badly needs testing on osx, windows, hp-ux and sunos, to see what it actually does rather than what the tests think it does. I'm still struggling to work out how to iterate over a list of platforms, all of which have different exec/interfaces and stub out the replies from these in a clean fashion. If I can't work out how to (there's a commented out ipaddress test in spec/unit/util/ip_spec.rb) I'll just make one test per OS by hand if I need to, so as to expand coverage.

Any feedback is greatly appreciated, even if it's that this is all the wrong direction. I had a blast and learnt a ton pulling this together.