bootstrap-vz/base/fs/partitions/abstractpartition.py
Anders Ingemann ff7c04c120 Support for partitions
MAJOR refactor. The volume is now abstracted into a model along with a partitionmap and partitions.
Volumes and partitions are now controlled via an FSM to ensure that commands are called in the proper sequence.
GRUB can now be installed properly onto loop devices by using dmsetup to fake a proper harddisk.
2013-10-27 18:11:12 +01:00

56 lines
1.7 KiB
Python

from common.tools import log_check_call
from abc import ABCMeta
from fysom import Fysom
class AbstractPartition(object):
__metaclass__ = ABCMeta
events = [{'name': 'create', 'src': 'nonexistent', 'dst': 'created'},
{'name': 'format', 'src': 'created', 'dst': 'formatted'},
{'name': 'mount', 'src': 'formatted', 'dst': 'mounted'},
{'name': 'unmount', 'src': 'mounted', 'dst': 'formatted'},
]
def __init__(self, size, filesystem, callbacks={}):
self.size = size
self.filesystem = filesystem
self.device_path = None
self.initial_state = 'nonexistent'
callbacks.update({'onbeforeformat': self._format,
'onbeforemount': self._mount,
'onbeforeunmount': self._unmount,
})
self.fsm = Fysom({'initial': 'nonexistent',
'events': self.events,
'callbacks': callbacks})
from common.fsm import attach_proxy_methods
attach_proxy_methods(self, self.events, self.fsm)
def state(self):
return self.fsm.current
def force_state(self, state):
self.fsm.current = state
def get_uuid(self):
[uuid] = log_check_call(['/sbin/blkid', '-s', 'UUID', '-o', 'value', self.device_path])
return uuid
def _format(self, e):
mkfs = '/sbin/mkfs.{fs}'.format(fs=self.filesystem)
log_check_call([mkfs, self.device_path])
def mount(self, destination):
self.fsm.mount(destination=destination)
def _mount(self, e):
log_check_call(['/bin/mount', '--types', self.filesystem, self.device_path, e.destination])
self.mount_dir = e.destination
def _unmount(self, e):
log_check_call(['/bin/umount', self.mount_dir])
del self.mount_dir