diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-05-23 16:20:08 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-05-23 16:20:08 +0000 |
commit | 8614b37bd70a0a9e1505a808442aa97147e04e96 (patch) | |
tree | 7f237d68a0ba04c7ba8e1f7a9934297856cde067 /morphlib | |
parent | 2089f74af895a4918670051e5d49188ed3b3f170 (diff) | |
parent | 7c848e43fae1416578372f7a9bdf6e5c38770894 (diff) | |
download | morph-8614b37bd70a0a9e1505a808442aa97147e04e96.tar.gz |
Merge remote-tracking branch 'origin/tiagogomes/upgrades2'
Conflicts:
morphlib/exts/nfsboot.write
Sorted out the conflict, and tested by deploying first devel
and then base to the same rawdisk, and things worked.
Diffstat (limited to 'morphlib')
-rwxr-xr-x | morphlib/exts/rawdisk.write | 54 | ||||
-rwxr-xr-x | morphlib/writeexts.py | 10 |
2 files changed, 55 insertions, 9 deletions
diff --git a/morphlib/exts/rawdisk.write b/morphlib/exts/rawdisk.write index a55473f2..a43a9cce 100755 --- a/morphlib/exts/rawdisk.write +++ b/morphlib/exts/rawdisk.write @@ -18,6 +18,7 @@ '''A Morph deployment write extension for raw disk images.''' +import cliapp import os import sys import time @@ -30,8 +31,10 @@ class RawDiskWriteExtension(morphlib.writeexts.WriteExtension): '''Create a raw disk image during Morph's deployment. + If the image already exists, it is upgraded. + The location command line argument is the pathname of the disk image - to be created. + to be created/upgraded. ''' @@ -40,9 +43,52 @@ class RawDiskWriteExtension(morphlib.writeexts.WriteExtension): raise cliapp.AppException('Wrong number of command line args') temp_root, location = args - - self.create_local_system(temp_root, location) - self.status(msg='Disk image has been created at %s' % location) + if os.path.isfile(location): + self.upgrade_local_system(location, temp_root) + else: + self.create_local_system(temp_root, location) + self.status(msg='Disk image has been created at %s' % location) + + def upgrade_local_system(self, raw_disk, temp_root): + mp = self.mount(raw_disk) + + version_label = self.get_version_label(mp) + self.status(msg='Updating image to a new version with label %s' % + version_label) + + version_root = os.path.join(mp, 'systems', version_label) + os.mkdir(version_root) + + old_orig = os.path.join(mp, 'systems', 'factory', 'orig') + new_orig = os.path.join(version_root, 'orig') + cliapp.runcmd( + ['btrfs', 'subvolume', 'snapshot', old_orig, new_orig]) + + cliapp.runcmd( + ['rsync', '-a', '--checksum', '--numeric-ids', '--delete', + temp_root + os.path.sep, new_orig]) + + self.create_run(version_root) + + if self.bootloader_is_wanted(): + self.install_kernel(version_root, temp_root) + self.install_extlinux(mp, version_label) + + self.unmount(mp) + + def get_version_label(self, mp): + version_label = os.environ.get('VERSION_LABEL') + + if version_label is None: + self.unmount(mp) + raise cliapp.AppException('VERSION_LABEL was not given') + + if os.path.exists(os.path.join(mp, 'systems', version_label)): + self.unmount(mp) + raise cliapp.AppException('VERSION_LABEL %s already exists' + % version_label) + + return version_label RawDiskWriteExtension().run() diff --git a/morphlib/writeexts.py b/morphlib/writeexts.py index f6465886..9e98747c 100755 --- a/morphlib/writeexts.py +++ b/morphlib/writeexts.py @@ -62,7 +62,7 @@ class WriteExtension(cliapp.Application): os.remove(raw_disk) raise try: - version_label = 'version1' + version_label = 'factory' version_root = os.path.join(mp, 'systems', version_label) os.makedirs(version_root) self.create_state(mp) @@ -71,7 +71,7 @@ class WriteExtension(cliapp.Application): self.create_run(version_root) if self.bootloader_is_wanted(): self.install_kernel(version_root, temp_root) - self.install_extlinux(mp) + self.install_extlinux(mp, version_label) except BaseException, e: sys.stderr.write('Error creating disk image') self.unmount(mp) @@ -222,7 +222,7 @@ class WriteExtension(cliapp.Application): cliapp.runcmd(['cp', '-a', try_path, kernel_dest]) break - def install_extlinux(self, real_root): + def install_extlinux(self, real_root, version_label): '''Install extlinux on the newly created disk image.''' self.status(msg='Creating extlinux.conf') @@ -231,9 +231,9 @@ class WriteExtension(cliapp.Application): f.write('default linux\n') f.write('timeout 1\n') f.write('label linux\n') - f.write('kernel /systems/version1/kernel\n') + f.write('kernel /systems/' + version_label + '/kernel\n') f.write('append root=/dev/sda ' - 'rootflags=subvol=systems/version1/run ' + 'rootflags=subvol=systems/' + version_label + '/run ' 'init=/sbin/init rw\n') self.status(msg='Installing extlinux') |