diff options
-rwxr-xr-x | morphlib/exts/ssh.configure | 23 | ||||
-rwxr-xr-x | morphlib/writeexts.py | 25 |
2 files changed, 45 insertions, 3 deletions
diff --git a/morphlib/exts/ssh.configure b/morphlib/exts/ssh.configure index 6012f298..2f3167e7 100755 --- a/morphlib/exts/ssh.configure +++ b/morphlib/exts/ssh.configure @@ -24,6 +24,7 @@ import os import sys import shutil import glob +import re import logging import morphlib @@ -63,6 +64,22 @@ class SshConfigurationExtension(cliapp.Application): if authkey: self.check_dir(dest, mode) self.comb_auth_key(authkey, dest) + + # Fills the known_hosts file + key = 'root_known_host_*_key.pub' + src = os.path.join(os.environ['SSH_KEY_DIR'], key) + known_hosts_keys = glob.glob(src) + if known_hosts_keys: + self.check_dir(dest, mode) + known_hosts_path = os.path.join(dest, 'known_hosts') + with open(known_hosts_path, "a") as known_hosts_file: + for filename in known_hosts_keys: + hostname = re.search('root_known_host_(.+?)_key.pub', + filename).group(1) + known_hosts_file.write(hostname + " ") + with open(filename, "r") as f: + shutil.copyfileobj(f, known_hosts_file) + else: self.status(msg="No SSH key directory found.") pass @@ -94,10 +111,12 @@ class SshConfigurationExtension(cliapp.Application): for key in keys: shutil.copy(key, dest) - os.chmod(dest, 0600) + path = os.path.join(dest, os.path.basename(key)) + os.chmod(path, 0600) for key in pubkeys: shutil.copy(key, dest) - os.chmod(dest, 0644) + path = os.path.join(dest, os.path.basename(key)) + os.chmod(path, 0644) def copy_rename_keys(self, keys, pubkeys, dest, new, snip): '''Copies SSH keys to new VM and renames them''' diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index 9caab839..aea08085 100755 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -65,7 +65,8 @@ class WriteExtension(cliapp.Application): self.create_factory(mp, temp_root) self.create_fstab(mp) self.create_factory_run(mp) - self.install_extlinux(mp) + if self.bootloader_is_wanted(): + self.install_extlinux(mp) except BaseException, e: sys.stderr.write('Error creating disk image') self.unmount(mp) @@ -229,6 +230,28 @@ class WriteExtension(cliapp.Application): else: return [] + def bootloader_is_wanted(self): + '''Does the user request a bootloader? + + The user may set $BOOTLOADER to yes, no, or auto. If not + set, auto is the default and means that the bootloader will + be installed on x86-32 and x86-64, but not otherwise. + + ''' + + def is_x86(arch): + return (arch == 'x86_64' or + (arch.startswith('i') and arch.endswith('86'))) + + value = os.environ.get('BOOTLOADER', 'auto') + if value == 'auto': + if is_x86(os.uname()[-1]): + value = 'yes' + else: + value = 'no' + + return value == 'yes' + def parse_autostart(self): '''Parse $AUTOSTART to determine if VMs should be started.''' |