summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-10-08 10:54:11 -0400
committerScott Moser <smoser@ubuntu.com>2014-10-08 10:54:11 -0400
commit735c3d961e00fe66a688997cdf9b39cf8d2a631b (patch)
tree9528e5df3a381e7522a0e0f64f43690cdf9319fa
parent15e5dbf3239b69a0eec24a7a86818d541ff5952e (diff)
parent58ec9ec076d34fffa72e8e406b3eaee2cbedfccf (diff)
downloadvyos-cloud-init-735c3d961e00fe66a688997cdf9b39cf8d2a631b.tar.gz
vyos-cloud-init-735c3d961e00fe66a688997cdf9b39cf8d2a631b.zip
freebsd: enable correct behavior on Ec2.
Take care of FreeBSD nic devicenames since they differ depending on the platform involved. Xen/KVM use different drivers, which results in different device names.
-rw-r--r--cloudinit/distros/freebsd.py26
-rw-r--r--config/cloud.cfg-freebsd2
2 files changed, 24 insertions, 4 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index b281b0d2..ee23fd20 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'):
+ continue
+ # 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)
diff --git a/config/cloud.cfg-freebsd b/config/cloud.cfg-freebsd
index 17924be8..5ac181ff 100644
--- a/config/cloud.cfg-freebsd
+++ b/config/cloud.cfg-freebsd
@@ -5,7 +5,7 @@ syslog_fix_perms: root:wheel
# This should not be required, but leave it in place until the real cause of
# not beeing able to find -any- datasources is resolved.
-datasource_list: ['ConfigDrive', 'OpenStack']
+datasource_list: ['ConfigDrive', 'OpenStack', 'Ec2']
# A set of users which may be applied and/or used by various modules
# when a 'default' entry is found it will reference the 'default_user'