mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
Remove duplicate tasks from filesystem task
This commit is contained in:
parent
43c9bdb14e
commit
355f29c23c
2 changed files with 28 additions and 89 deletions
|
@ -2,6 +2,7 @@ from manifest import Manifest
|
||||||
from tasks import packages
|
from tasks import packages
|
||||||
from tasks import host
|
from tasks import host
|
||||||
from tasks import filesystem
|
from tasks import filesystem
|
||||||
|
from common.tasks import filesystem as common_filesystem
|
||||||
from common.tasks import bootstrap
|
from common.tasks import bootstrap
|
||||||
from common.tasks import locale
|
from common.tasks import locale
|
||||||
from common.tasks import apt
|
from common.tasks import apt
|
||||||
|
@ -23,15 +24,15 @@ def tasks(tasklist, manifest):
|
||||||
host.CheckPackages())
|
host.CheckPackages())
|
||||||
tasklist.add(filesystem.FormatVolume())
|
tasklist.add(filesystem.FormatVolume())
|
||||||
if manifest.volume['filesystem'].lower() == 'xfs':
|
if manifest.volume['filesystem'].lower() == 'xfs':
|
||||||
tasklist.add(filesystem.AddXFSProgs())
|
tasklist.add(common_filesystem.AddXFSProgs())
|
||||||
if manifest.volume['filesystem'].lower() in ['ext2', 'ext3', 'ext4']:
|
if manifest.volume['filesystem'].lower() in ['ext2', 'ext3', 'ext4']:
|
||||||
tasklist.add(filesystem.TuneVolumeFS())
|
tasklist.add(filesystem.TuneVolumeFS())
|
||||||
tasklist.add(filesystem.CreateMountDir(),
|
tasklist.add(common_filesystem.CreateMountDir(),
|
||||||
filesystem.MountVolume())
|
filesystem.MountVolume())
|
||||||
if manifest.bootstrapper['tarball']:
|
if manifest.bootstrapper['tarball']:
|
||||||
tasklist.add(bootstrap.MakeTarball())
|
tasklist.add(bootstrap.MakeTarball())
|
||||||
tasklist.add(bootstrap.Bootstrap(),
|
tasklist.add(bootstrap.Bootstrap(),
|
||||||
filesystem.MountSpecials(),
|
common_filesystem.MountSpecials(),
|
||||||
locale.GenerateLocale(),
|
locale.GenerateLocale(),
|
||||||
locale.SetTimezone(),
|
locale.SetTimezone(),
|
||||||
apt.DisableDaemonAutostart(),
|
apt.DisableDaemonAutostart(),
|
||||||
|
@ -57,9 +58,9 @@ def tasks(tasklist, manifest):
|
||||||
apt.PurgeUnusedPackages(),
|
apt.PurgeUnusedPackages(),
|
||||||
apt.AptClean(),
|
apt.AptClean(),
|
||||||
apt.EnableDaemonAutostart(),
|
apt.EnableDaemonAutostart(),
|
||||||
filesystem.UnmountSpecials(),
|
common_filesystem.UnmountSpecials(),
|
||||||
filesystem.UnmountVolume(),
|
filesystem.UnmountVolume(),
|
||||||
filesystem.DeleteMountDir())
|
common_filesystem.DeleteMountDir())
|
||||||
|
|
||||||
|
|
||||||
def rollback_tasks(tasklist, tasks_completed, manifest):
|
def rollback_tasks(tasklist, tasks_completed, manifest):
|
||||||
|
@ -69,6 +70,6 @@ def rollback_tasks(tasklist, tasks_completed, manifest):
|
||||||
if task in completed and counter not in completed:
|
if task in completed and counter not in completed:
|
||||||
tasklist.add(counter())
|
tasklist.add(counter())
|
||||||
|
|
||||||
counter_task(filesystem.CreateMountDir, filesystem.DeleteMountDir)
|
counter_task(common_filesystem.CreateMountDir, common_filesystem.DeleteMountDir)
|
||||||
counter_task(filesystem.MountVolume, filesystem.UnmountVolume)
|
counter_task(filesystem.MountVolume, filesystem.UnmountVolume)
|
||||||
counter_task(filesystem.MountSpecials, filesystem.UnmountSpecials)
|
counter_task(common_filesystem.MountSpecials, common_filesystem.UnmountSpecials)
|
||||||
|
|
|
@ -2,8 +2,8 @@ from base import Task
|
||||||
from common import phases
|
from common import phases
|
||||||
from common.exceptions import TaskError
|
from common.exceptions import TaskError
|
||||||
from common.tools import log_check_call
|
from common.tools import log_check_call
|
||||||
from bootstrap import Bootstrap
|
from common.filesystem import filesystem
|
||||||
import os
|
|
||||||
|
|
||||||
class FormatVolume(Task):
|
class FormatVolume(Task):
|
||||||
description = 'Formatting the volume'
|
description = 'Formatting the volume'
|
||||||
|
@ -21,53 +21,26 @@ class FormatVolume(Task):
|
||||||
log_check_call(['parted', '-a', 'optimal', '-s', '/dev/loop0', "--", "mkpart", "primary", "ext4", "32k", "-1"])
|
log_check_call(['parted', '-a', 'optimal', '-s', '/dev/loop0', "--", "mkpart", "primary", "ext4", "32k", "-1"])
|
||||||
log_check_call(['parted', '-s', '/dev/loop0', "--", "set", "1", "boot", "on"])
|
log_check_call(['parted', '-s', '/dev/loop0', "--", "set", "1", "boot", "on"])
|
||||||
|
|
||||||
|
|
||||||
#log_check_call(['kpartx','-a','-v', info.manifest.bootstrapper['image_file']])
|
|
||||||
log_check_call(['kpartx', '-a', '-v', '/dev/loop0'])
|
log_check_call(['kpartx', '-a', '-v', '/dev/loop0'])
|
||||||
mkfs = ['/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']), '-m', '1', '-v', '/dev/mapper/loop0p1']
|
mkfs = ['/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']), '-m', '1', '-v', '/dev/mapper/loop0p1']
|
||||||
log_check_call(mkfs)
|
log_check_call(mkfs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TuneVolumeFS(Task):
|
class TuneVolumeFS(Task):
|
||||||
description = 'Tuning the bootstrap volume filesystem'
|
description = 'Tuning the bootstrap volume filesystem'
|
||||||
phase = phases.volume_preparation
|
phase = phases.volume_preparation
|
||||||
after = [FormatVolume]
|
after = [FormatVolume]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
#dev_path = info.bootstrap_device['path']
|
|
||||||
#dev_path = info.manifest.bootstrapper['image_file']
|
|
||||||
dev_path = '/dev/mapper/loop0p1'
|
dev_path = '/dev/mapper/loop0p1'
|
||||||
# Disable the time based filesystem check
|
# Disable the time based filesystem check
|
||||||
log_check_call(['/sbin/tune2fs', '-i', '0', dev_path])
|
log_check_call(['/sbin/tune2fs', '-i', '0', dev_path])
|
||||||
|
|
||||||
|
|
||||||
class AddXFSProgs(Task):
|
|
||||||
description = 'Adding `xfsprogs\' to the image packages'
|
|
||||||
phase = phases.preparation
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
include, exclude = info.img_packages
|
|
||||||
include.add('xfsprogs')
|
|
||||||
|
|
||||||
|
|
||||||
class CreateMountDir(Task):
|
|
||||||
description = 'Creating mountpoint for the bootstrap volume'
|
|
||||||
phase = phases.volume_mounting
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
import os
|
|
||||||
mount_dir = info.manifest.bootstrapper['mount_dir']
|
|
||||||
info.root = mount_dir
|
|
||||||
# Works recursively, fails if last part exists, which is exaclty what we want.
|
|
||||||
os.makedirs(mount_dir)
|
|
||||||
|
|
||||||
|
|
||||||
class MountVolume(Task):
|
class MountVolume(Task):
|
||||||
description = 'Mounting the bootstrap volume'
|
description = 'Mounting the bootstrap volume'
|
||||||
phase = phases.volume_mounting
|
phase = phases.volume_mounting
|
||||||
after = [CreateMountDir]
|
after = [filesystem.CreateMountDir]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
with open('/proc/mounts') as mounts:
|
with open('/proc/mounts') as mounts:
|
||||||
|
@ -78,53 +51,17 @@ class MountVolume(Task):
|
||||||
|
|
||||||
log_check_call(['/bin/mount', '-t', info.manifest.volume['filesystem'], '/dev/mapper/loop0p1', info.root])
|
log_check_call(['/bin/mount', '-t', info.manifest.volume['filesystem'], '/dev/mapper/loop0p1', info.root])
|
||||||
|
|
||||||
class MountSpecials(Task):
|
|
||||||
description = 'Mounting special block devices'
|
|
||||||
phase = phases.os_installation
|
|
||||||
after = [Bootstrap]
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
log_check_call(['/bin/mount', '--bind', '/dev', '{root}/dev'.format(root=info.root)])
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/mount', '-t', 'proc', 'none', '/proc'])
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/mount', '-t', 'sysfs', 'none', '/sys'])
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/mount', '-t', 'devpts', 'none', '/dev/pts'])
|
|
||||||
|
|
||||||
|
|
||||||
class UnmountSpecials(Task):
|
|
||||||
description = 'Unmunting special block devices'
|
|
||||||
phase = phases.volume_unmounting
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/umount', '/dev/pts'])
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/umount', '/sys'])
|
|
||||||
log_check_call(['/usr/sbin/chroot', info.root, '/bin/umount', '/proc'])
|
|
||||||
log_check_call(['/bin/umount', '{root}/dev'.format(root=info.root)])
|
|
||||||
|
|
||||||
|
|
||||||
class UnmountVolume(Task):
|
class UnmountVolume(Task):
|
||||||
description = 'Unmounting the bootstrap volume'
|
description = 'Unmounting the bootstrap volume'
|
||||||
phase = phases.volume_unmounting
|
phase = phases.volume_unmounting
|
||||||
after = [UnmountSpecials]
|
after = [filesystem.UnmountSpecials]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
log_check_call(['/bin/umount', info.root])
|
log_check_call(['/bin/umount', info.root])
|
||||||
#log_check_call(['partx','-d','/dev/loop0'])
|
|
||||||
#log_check_call(['/sbin/losetup', '-d', '/dev/loop0'])
|
|
||||||
log_check_call(['kpartx', '-d', info.manifest.bootstrapper['image_file']])
|
log_check_call(['kpartx', '-d', info.manifest.bootstrapper['image_file']])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DeleteMountDir(Task):
|
|
||||||
description = 'Deleting mountpoint for the bootstrap volume'
|
|
||||||
phase = phases.volume_unmounting
|
|
||||||
after = [UnmountVolume]
|
|
||||||
|
|
||||||
def run(self, info):
|
|
||||||
import os
|
|
||||||
os.rmdir(info.root)
|
|
||||||
del info.root
|
|
||||||
|
|
||||||
|
|
||||||
class ModifyFstab(Task):
|
class ModifyFstab(Task):
|
||||||
description = 'Adding root volume to the fstab'
|
description = 'Adding root volume to the fstab'
|
||||||
phase = phases.system_modification
|
phase = phases.system_modification
|
||||||
|
@ -142,6 +79,7 @@ class ModifyFstab(Task):
|
||||||
if info.manifest.virtualization == 'virtio':
|
if info.manifest.virtualization == 'virtio':
|
||||||
device = '/dev/vda1'
|
device = '/dev/vda1'
|
||||||
|
|
||||||
fstab.write((device+' / {filesystem} {mount_opts} 1 1\n'
|
fstab.write('{device} / {filesystem} {mount_opts} 1 1\n'
|
||||||
.format(filesystem=info.manifest.volume['filesystem'].lower(),
|
.format(device=device,
|
||||||
mount_opts=','.join(mount_opts))))
|
filesystem=info.manifest.volume['filesystem'].lower(),
|
||||||
|
mount_opts=','.join(mount_opts)))
|
||||||
|
|
Loading…
Add table
Reference in a new issue