← Back to team overview

cloud-init team mailing list archive

Re: How to handle platform diferences in cloudinit.net module

 



scott said:

> As a first-pass answer, I think the goal woudl be really to get stuff into the cloudinit/net/ module that > then had sane methodds that did the right thing. I do realize that freebsd did/does have lots of "if"s sprinkled throughout.
>
> I think we would like to better abstract / design this.


given similar uses in other parts of the code, i started with something like this:

https://git.launchpad.net/~i.galic/cloud-init/commit/?h=refactor/net-fbsd&id=65d8328a5a12b1a435d4386c0963774ea08c319e

After a weekend of not looking at this code, i believe i have now come up with a slightly better approach.

From my understanding, `net` is used to gather and setup the low level state of the network. For this it uses `/sys/classes/net/*` and `ip` on linux, and would use `ifconfig` and `route` on freebsd.

We can leave most of the high-level function declarations in `net` as they are, and, on-load, dispatch an import of their actual implementation:

```
import util
net_class = None
if util.system()['vendor'] is not 'freebsd':
   from net.linux import Linux
   net_class = Linux
else:
   from net.freebsd import FreeBSD
   net_class = FreeBSD

def is_up(interface)
   return net_class.is_up(interface)

# etc…
```

the `distro` classes would still hold the distro specific configuration mechanisms (/etc/network/interfaces vs /etc/sysconf/network vs /etc/rc.conf, etc…)

(Furthermore, FreeBSD should also return FreeBSD as distro ;)



Follow ups

References