freebsd: Use the proper virtio FreeBSD network interface name.
This commit is contained in:
parent
fc8df8eb06
commit
aafe022b4f
@ -106,6 +106,15 @@ class Distro(distros.Distro):
|
|||||||
val = None
|
val = None
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
# NOVA will inject something like eth0, rewrite that to use the
|
||||||
|
# virtio-based BSD adapter.
|
||||||
|
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)
|
||||||
|
|
||||||
def _read_system_hostname(self):
|
def _read_system_hostname(self):
|
||||||
sys_hostname = self._read_hostname(filename=None)
|
sys_hostname = self._read_hostname(filename=None)
|
||||||
return ('rc.conf', sys_hostname)
|
return ('rc.conf', sys_hostname)
|
||||||
@ -162,18 +171,18 @@ class Distro(distros.Distro):
|
|||||||
log_adduser_cmd = ['pw', 'useradd', '-n', name]
|
log_adduser_cmd = ['pw', 'useradd', '-n', name]
|
||||||
|
|
||||||
adduser_opts = {
|
adduser_opts = {
|
||||||
"homedir": '-d',
|
"homedir": '-d',
|
||||||
"gecos": '-c',
|
"gecos": '-c',
|
||||||
"primary_group": '-g',
|
"primary_group": '-g',
|
||||||
"groups": '-G',
|
"groups": '-G',
|
||||||
"passwd": '-h',
|
"passwd": '-h',
|
||||||
"shell": '-s',
|
"shell": '-s',
|
||||||
"inactive": '-E',
|
"inactive": '-E',
|
||||||
}
|
}
|
||||||
adduser_flags = {
|
adduser_flags = {
|
||||||
"no_user_group": '--no-user-group',
|
"no_user_group": '--no-user-group',
|
||||||
"system": '--system',
|
"system": '--system',
|
||||||
"no_log_init": '--no-log-init',
|
"no_log_init": '--no-log-init',
|
||||||
}
|
}
|
||||||
|
|
||||||
redact_opts = ['passwd']
|
redact_opts = ['passwd']
|
||||||
@ -246,17 +255,21 @@ class Distro(distros.Distro):
|
|||||||
nameservers = []
|
nameservers = []
|
||||||
searchdomains = []
|
searchdomains = []
|
||||||
dev_names = entries.keys()
|
dev_names = entries.keys()
|
||||||
for (dev, info) in entries.iteritems():
|
for (device, info) in entries.iteritems():
|
||||||
# Skip the loopback interface.
|
# Skip the loopback interface.
|
||||||
if dev.startswith('lo'):
|
if device.startswith('lo'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
dev = self.getnetifname(device)
|
||||||
|
|
||||||
LOG.info('Configuring interface %s', dev)
|
LOG.info('Configuring interface %s', dev)
|
||||||
|
|
||||||
if info.get('bootproto') == 'static':
|
if info.get('bootproto') == 'static':
|
||||||
LOG.debug('Configuring dev %s with %s / %s', dev, info.get('address'), info.get('netmask'))
|
LOG.debug('Configuring dev %s with %s / %s', dev,
|
||||||
|
info.get('address'), info.get('netmask'))
|
||||||
# Configure an ipv4 address.
|
# Configure an ipv4 address.
|
||||||
ifconfig = info.get('address') + ' netmask ' + info.get('netmask')
|
ifconfig = (info.get('address') + ' netmask ' +
|
||||||
|
info.get('netmask'))
|
||||||
|
|
||||||
# Configure the gateway.
|
# Configure the gateway.
|
||||||
self.updatercconf('defaultrouter', info.get('gateway'))
|
self.updatercconf('defaultrouter', info.get('gateway'))
|
||||||
@ -267,7 +280,7 @@ class Distro(distros.Distro):
|
|||||||
searchdomains.extend(info['dns-search'])
|
searchdomains.extend(info['dns-search'])
|
||||||
else:
|
else:
|
||||||
ifconfig = 'DHCP'
|
ifconfig = 'DHCP'
|
||||||
|
|
||||||
self.updatercconf('ifconfig_' + dev, ifconfig)
|
self.updatercconf('ifconfig_' + dev, ifconfig)
|
||||||
|
|
||||||
# Try to read the /etc/resolv.conf or just start from scratch if that
|
# Try to read the /etc/resolv.conf or just start from scratch if that
|
||||||
@ -276,7 +289,8 @@ class Distro(distros.Distro):
|
|||||||
resolvconf = ResolvConf(util.load_file(self.resolv_conf_fn))
|
resolvconf = ResolvConf(util.load_file(self.resolv_conf_fn))
|
||||||
resolvconf.parse()
|
resolvconf.parse()
|
||||||
except IOError:
|
except IOError:
|
||||||
util.logexc(LOG, "Failed to parse %s, use new empty file", self.resolv_conf_fn)
|
util.logexc(LOG, "Failed to parse %s, use new empty file",
|
||||||
|
self.resolv_conf_fn)
|
||||||
resolvconf = ResolvConf('')
|
resolvconf = ResolvConf('')
|
||||||
resolvconf.parse()
|
resolvconf.parse()
|
||||||
|
|
||||||
@ -323,6 +337,19 @@ class Distro(distros.Distro):
|
|||||||
util.logexc(LOG, "Failed to restore %s backup",
|
util.logexc(LOG, "Failed to restore %s backup",
|
||||||
self.login_conf_fn)
|
self.login_conf_fn)
|
||||||
|
|
||||||
|
def _bring_up_interface(self, device_name):
|
||||||
|
if device_name.startswith('lo'):
|
||||||
|
return
|
||||||
|
dev = self.getnetifname(device_name)
|
||||||
|
cmd = ['/etc/rc.d/netif', 'start', dev]
|
||||||
|
LOG.debug("Attempting to bring up interface %s using command %s",
|
||||||
|
dev, cmd)
|
||||||
|
# This could return 1 when the interface has already been put UP by the
|
||||||
|
# OS. This is just fine.
|
||||||
|
(_out, err) = util.subp(cmd, rcs=[0, 1])
|
||||||
|
if len(err):
|
||||||
|
LOG.warn("Error running %s: %s", cmd, err)
|
||||||
|
|
||||||
def install_packages(self, pkglist):
|
def install_packages(self, pkglist):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ NETWORKING=yes
|
|||||||
self.assertIn('/etc/rc.conf', write_bufs)
|
self.assertIn('/etc/rc.conf', write_bufs)
|
||||||
write_buf = write_bufs['/etc/rc.conf']
|
write_buf = write_bufs['/etc/rc.conf']
|
||||||
expected_buf = '''
|
expected_buf = '''
|
||||||
ifconfig_eth0="192.168.1.5 netmask 255.255.255.0"
|
ifconfig_vtnet0="192.168.1.5 netmask 255.255.255.0"
|
||||||
ifconfig_eth1="DHCP"
|
ifconfig_vtnet1="DHCP"
|
||||||
defaultrouter="192.168.1.254"
|
defaultrouter="192.168.1.254"
|
||||||
'''
|
'''
|
||||||
self.assertCfgEquals(expected_buf, str(write_buf))
|
self.assertCfgEquals(expected_buf, str(write_buf))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user