configure: Add function to enable the SSH daemon

The `configure.enable_sshd` function enables the SSH daemon in the
target system. It generates host keys and sets the daemon to start at
boot. This function is called by `configure.configure` if the VM
definition contains at least one network interface.
master
Dustin 2015-07-11 19:51:55 -05:00
parent aa97d4cd43
commit 4b40194c86
1 changed files with 12 additions and 0 deletions

View File

@ -75,6 +75,16 @@ def enable_console_login(mountpoint, driver):
f.write(line) f.write(line)
def enable_sshd(mountpoint):
cmd = ['chroot', mountpoint, 'ssh-keygen', '-A']
output = subprocess.check_output(cmd)
if output:
log.info(output.decode().strip())
path = os.path.join(mountpoint, 'etc/runlevels/default/sshd')
if not os.path.exists(path):
os.symlink('/etc/init.d/sshd', path)
def run_custom_script(mountpoint, script): def run_custom_script(mountpoint, script):
cmd = ['chroot', mountpoint, '/bin/sh'] cmd = ['chroot', mountpoint, '/bin/sh']
env = CUSTOM_SCRIPT_ENV.copy() env = CUSTOM_SCRIPT_ENV.copy()
@ -98,6 +108,8 @@ def configure(vm):
set_hostname(vm.mountpoint, vm.fqdn) set_hostname(vm.mountpoint, vm.fqdn)
if vm.console: if vm.console:
enable_console_login(vm.mountpoint, vm.console) enable_console_login(vm.mountpoint, vm.console)
if vm.net_ifaces:
enable_sshd(vm.mountpoint)
if vm.customize: if vm.customize:
run_custom_script(vm.mountpoint, vm.customize) run_custom_script(vm.mountpoint, vm.customize)