bootstrap-vz/plugins/minimize_size/tasks.py
Anders Ingemann 83e1339145 New plugin: minimize_size
It binds folders from the host machine to temporary and cache folders in the image.
This way dynamic volumes will not grow in size when running `apt-get update` etc.
2014-01-05 02:25:28 +01:00

41 lines
1.2 KiB
Python

from base import Task
from common import phases
from common.tasks import bootstrap
from common.tasks import apt
import os
folders = ['tmp', 'var/lib/apt/lists']
class AddFolderMounts(Task):
description = 'Mounting folders for writing temporary and cache data'
phase = phases.os_installation
predecessors = [bootstrap.Bootstrap]
def run(self, info):
info.minimize_size_folder = os.path.join(info.workspace, 'minimize_size')
os.mkdir(info.minimize_size_folder)
for folder in folders:
temp_path = os.path.join(info.minimize_size_folder, folder.replace('/', '_'))
os.mkdir(temp_path)
full_path = os.path.join(info.root, folder)
info.volume.partition_map.root.add_mount(temp_path, full_path, ['--bind'])
class RemoveFolderMounts(Task):
description = 'Removing folder mounts for temporary and cache data'
phase = phases.system_cleaning
successors = [apt.AptClean]
def run(self, info):
import shutil
for folder in folders:
temp_path = os.path.join(info.minimize_size_folder, folder.replace('/', '_'))
full_path = os.path.join(info.root, folder)
info.volume.partition_map.root.remove_mount(full_path)
shutil.rmtree(temp_path)
os.rmdir(info.minimize_size_folder)
del info.minimize_size_folder