diff --git a/hammer.py b/hammer.py index 0d42bb2694..d845a5d671 100755 --- a/hammer.py +++ b/hammer.py @@ -625,7 +625,7 @@ class VagrantEnv(object): def package(self): """Package Vagrant system into Vagrant box.""" - execute('vagrant halt', cwd=self.vagrant_dir, dry_run=self.dry_run, raise_error=False) + execute('vagrant halt', cwd=self.vagrant_dir, dry_run=self.dry_run, raise_error=False, attempts=3) box_path = os.path.join(self.vagrant_dir, 'kea-%s-%s.box' % (self.system, self.revision)) if os.path.exists(box_path): @@ -641,6 +641,8 @@ class VagrantEnv(object): execute('sudo rm -rf %s' % lxc_box_dir) os.mkdir(lxc_box_dir) lxc_container_path = os.path.join('/var/lib/lxc', self.name) + + # add vagrant universal key to accepted keys execute('sudo bash -c \'echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8ia' 'llvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ' '6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTB' @@ -649,13 +651,26 @@ class VagrantEnv(object): 'YSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYC' 'zRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"' '> %s/rootfs/home/vagrant/.ssh/authorized_keys\'' % lxc_container_path) + + # reset machine-id + execute('sudo rm -f %s/rootfs/var/lib/dbus/machine-id' % lxc_container_path) + #execute('sudo truncate -s 0 %s/rootfs/etc/machine-id' % lxc_container_path) + execute('sudo rm -f %s/rootfs/etc/machine-id' % lxc_container_path) + + # pack rootfs cmd = 'sudo bash -c "' cmd += 'cd %s ' cmd += '&& tar --numeric-owner --anchored --exclude=./rootfs/dev/log -czf %s/rootfs.tar.gz ./rootfs/*' cmd += '"' execute(cmd % (lxc_container_path, lxc_box_dir)) + + # copy lxc config from runtime container execute('sudo cp %s/config %s/lxc-config' % (lxc_container_path, lxc_box_dir)) + # remove mac address from eth0 - it should be dynamically assigned + execute("sudo sed -i '/lxc.net.0.hwaddr/d' %s/lxc-config" % lxc_box_dir) + # correct files ownership execute('sudo chown `id -un`:`id -gn` *', cwd=lxc_box_dir) + # and other metadata with open(os.path.join(lxc_box_dir, 'metadata.json'), 'w') as f: now = datetime.datetime.now() f.write('{\n') @@ -664,6 +679,7 @@ class VagrantEnv(object): f.write(' "built-on": "%s"\n' % now.strftime('%c')) f.write('}\n') + # pack vagrant box with metadata and config execute('tar -czf %s ./*' % box_path, cwd=lxc_box_dir) execute('sudo rm -rf %s' % lxc_box_dir) @@ -913,6 +929,31 @@ class VagrantEnv(object): dt // 60, dt % 60) log.info('') + def prepare_for_boxing(self): + if self.system not in ['debian', 'ubuntu', 'fedora', 'centos', 'rhel']: + return + + # setup a script that on first boot will set machine-id + cmd = 'bash -c \'cat <