summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarm Weites <harm@weites.com>2014-10-08 15:12:17 +0200
committerHarm Weites <harm@weites.com>2014-10-08 15:12:17 +0200
commit81ae50df3813b56f4a7d5fdb9c9ec76d092e69da (patch)
treeda005e55cca4bfe6d7981045b3721733039031ca
parentaafe022b4f8ec74e5dfdef42ac963cbdc46a8535 (diff)
downloadcloud-init-81ae50df3813b56f4a7d5fdb9c9ec76d092e69da.tar.gz
fix: Take care of FreeBSD nic devicenames since they differ depending
on the platform involved. Xen/KVM (Azure?) use different drivers, which results in different device names.
-rw-r--r--cloudinit/distros/freebsd.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index b281b0d2..ee74cd2d 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -106,14 +106,34 @@ class Distro(distros.Distro):
val = None
return val
- # NOVA will inject something like eth0, rewrite that to use the
- # virtio-based BSD adapter.
+ # NOVA will inject something like eth0, rewrite that to use the FreeBSD
+ # adapter. Since this adapter is based on the used driver, we need to
+ # figure out which interfaces are available. On KVM platforms this is
+ # vtnet0, where Xen would use xn0.
def getnetifname(self, dev):
LOG.debug("Translating network interface %s", dev)
if dev.startswith('lo'):
return dev
+
n = re.search('\d+$', dev)
- return 'vtnet' + n.group(0)
+ index = n.group(0)
+
+ (out, err) = util.subp(['ifconfig', '-a'])
+ ifconfigoutput = [x for x in (out.strip()).splitlines() if len(x.split()) > 0]
+ for line in ifconfigoutput:
+ m = re.match('^\w+', line)
+ if m:
+ if m.group(0).startswith('lo'):
+ next
+ # Just settle with the first non-lo adapter we find, since it's
+ # rather unlikely there will be multiple nicdrivers involved.
+ bsddev = m.group(0)
+ break
+
+ # Replace the index with the one we're after.
+ bsddev = re.sub('\d+$', index, bsddev)
+ LOG.debug("Using network interface %s", bsddev)
+ return bsddev
def _read_system_hostname(self):
sys_hostname = self._read_hostname(filename=None)