~sergiusens/cloud-init/snappy_ssh

« back to all changes in this revision

Viewing changes to cloudinit/distros/freebsd.py

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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
            val = None
107
107
        return val
108
108
 
109
 
    # NOVA will inject something like eth0, rewrite that to use the
110
 
    # virtio-based BSD adapter.
 
109
    # NOVA will inject something like eth0, rewrite that to use the FreeBSD
 
110
    # adapter. Since this adapter is based on the used driver, we need to
 
111
    # figure out which interfaces are available. On KVM platforms this is
 
112
    # vtnet0, where Xen would use xn0.
111
113
    def getnetifname(self, dev):
112
114
        LOG.debug("Translating network interface %s", dev)
113
115
        if dev.startswith('lo'):
114
116
            return dev
 
117
 
115
118
        n = re.search('\d+$', dev)
116
 
        return 'vtnet' + n.group(0)
 
119
        index = n.group(0)
 
120
 
 
121
        (out, err) = util.subp(['ifconfig', '-a'])
 
122
        ifconfigoutput = [x for x in (out.strip()).splitlines() if len(x.split()) > 0]
 
123
        for line in ifconfigoutput:
 
124
            m = re.match('^\w+', line)
 
125
            if m:
 
126
                if m.group(0).startswith('lo'):
 
127
                    continue
 
128
                # Just settle with the first non-lo adapter we find, since it's
 
129
                # rather unlikely there will be multiple nicdrivers involved.
 
130
                bsddev = m.group(0)
 
131
                break
 
132
 
 
133
        # Replace the index with the one we're after.
 
134
        bsddev = re.sub('\d+$', index, bsddev)
 
135
        LOG.debug("Using network interface %s", bsddev)
 
136
        return bsddev
117
137
 
118
138
    def _read_system_hostname(self):
119
139
        sys_hostname = self._read_hostname(filename=None)