voxpupuli / puppet-network

Types and providers to manage network interfaces
https://forge.puppet.com/puppet/network
Apache License 2.0
66 stars 108 forks source link

Device by mac address? #151

Open jcpunk opened 8 years ago

jcpunk commented 8 years ago

Via my ENC I have access to all the device MAC address and the IP addresses that should be on those interfaces.

Can network_config be extended so that I can select a device based on its MAC rather than the interface name determined by udev?

rski commented 8 years ago

Basically the way this module works is by finding the interface configuration file, parsing it if it exists and dumping in it the new contents. If you take a look at any of the ruby files under lib/puppet/provider you'll see that they all implement functions like select_file, format_file etc. which do exactly this. The select_files depend entirely on the udev name, because that is how the configuration file names are determined (e.g. /etc/sysconfig/network-scripts/ifcfg-eth0). What this all means, is that even if you pass a MAC address you'd still have to have some logic in select_file to get the udev name from it.

However CentOS for example provides HWADDR:

HWADDR= where is the hardware address of the Ethernet device in the form AA:BB:CC:DD:EE:FF. This directive is useful for machines with multiple NICs to ensure that the interfaces are assigned the correct device names regardless of the configured load order for each NIC's module. This directive should not be used in conjunction with MACADDR.

So you could use HWADDR to assign the interface name yourself. Sorry this was about CentOS 5.

Systemd has predictable interface names so maybe this could be used to get the udev name from a mac address.

rski commented 8 years ago

You can also force interfaces MAC addresses to be given specific names with udev rules. I kind of feel like matching interface names to MAC addresses is a problem out of the scope of this module that can be handled more appropriately with other tools.

rski commented 8 years ago

One the other hand, you could just call ip and get the interface name from its output, which might just be the easiest thing to do in this case. @jyaworski @igalic is this something that would be nice to have in this module or is it just feature creep?

jyaworski commented 8 years ago

I'm inclined to say that this could be useful. I can see a few instances where you would want a spoofed MAC, and this could describe it.

igalic commented 8 years ago

i can see how this could be useful. i can also see how this would fix #92 and #99. questions: can we make it backwards compatible? can we make it so it actually fixes the above issues?

jcpunk commented 8 years ago

Facter seems to provide mac addresses, so perhaps if 'name' is a mac address of an interface on the system, then the name of the interface (eth0) could be swapped out under the hood?

jyaworski commented 8 years ago

@jcpunk is_mac_address sounds like it could fit the bill here.