mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
factor AbstractPartition.Mount out into separate module and make it serializable
This commit is contained in:
parent
ad52df37bd
commit
e8d6e7f602
4 changed files with 52 additions and 39 deletions
|
@ -1,6 +1,5 @@
|
|||
from abc import ABCMeta
|
||||
from abc import abstractmethod
|
||||
import os.path
|
||||
from bootstrapvz.common.tools import log_check_call
|
||||
from bootstrapvz.common.fsm_proxy import FSMProxy
|
||||
|
||||
|
@ -19,42 +18,6 @@ class AbstractPartition(FSMProxy):
|
|||
{'name': 'unmount', 'src': 'mounted', 'dst': 'formatted'},
|
||||
]
|
||||
|
||||
class Mount(object):
|
||||
"""Represents a mount into the partition
|
||||
"""
|
||||
def __init__(self, source, destination, opts):
|
||||
"""
|
||||
:param str,AbstractPartition source: The path from where we mount or a partition
|
||||
:param str destination: The path of the mountpoint
|
||||
:param list opts: List of options to pass to the mount command
|
||||
"""
|
||||
self.source = source
|
||||
self.destination = destination
|
||||
self.opts = opts
|
||||
|
||||
def mount(self, prefix):
|
||||
"""Performs the mount operation or forwards it to another partition
|
||||
|
||||
:param str prefix: Path prefix of the mountpoint
|
||||
"""
|
||||
mount_dir = os.path.join(prefix, self.destination)
|
||||
# If the source is another partition, we tell that partition to mount itself
|
||||
if isinstance(self.source, AbstractPartition):
|
||||
self.source.mount(destination=mount_dir)
|
||||
else:
|
||||
log_check_call(['mount'] + self.opts + [self.source, mount_dir])
|
||||
self.mount_dir = mount_dir
|
||||
|
||||
def unmount(self):
|
||||
"""Performs the unmount operation or asks the partition to unmount itself
|
||||
"""
|
||||
# If its a partition, it can unmount itself
|
||||
if isinstance(self.source, AbstractPartition):
|
||||
self.source.unmount()
|
||||
else:
|
||||
log_check_call(['umount', self.mount_dir])
|
||||
del self.mount_dir
|
||||
|
||||
def __init__(self, size, filesystem, format_command):
|
||||
"""
|
||||
:param Bytes size: Size of the partition
|
||||
|
@ -143,7 +106,8 @@ class AbstractPartition(FSMProxy):
|
|||
:param list opts: Any options that should be passed to the mount command
|
||||
"""
|
||||
# Create a new mount object, mount it if the partition is mounted and put it in the mounts dict
|
||||
mount = self.Mount(source, destination, opts)
|
||||
from mount import Mount
|
||||
mount = Mount(source, destination, opts)
|
||||
if self.fsm.current == 'mounted':
|
||||
mount.mount(self.mount_dir)
|
||||
self.mounts[destination] = mount
|
||||
|
|
49
bootstrapvz/base/fs/partitions/mount.py
Normal file
49
bootstrapvz/base/fs/partitions/mount.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
from abstract import AbstractPartition
|
||||
import os.path
|
||||
from bootstrapvz.common.tools import log_check_call
|
||||
|
||||
|
||||
class Mount(object):
|
||||
"""Represents a mount into the partition
|
||||
"""
|
||||
def __init__(self, source, destination, opts):
|
||||
"""
|
||||
:param str,AbstractPartition source: The path from where we mount or a partition
|
||||
:param str destination: The path of the mountpoint
|
||||
:param list opts: List of options to pass to the mount command
|
||||
"""
|
||||
self.source = source
|
||||
self.destination = destination
|
||||
self.opts = opts
|
||||
|
||||
def mount(self, prefix):
|
||||
"""Performs the mount operation or forwards it to another partition
|
||||
|
||||
:param str prefix: Path prefix of the mountpoint
|
||||
"""
|
||||
mount_dir = os.path.join(prefix, self.destination)
|
||||
# If the source is another partition, we tell that partition to mount itself
|
||||
if isinstance(self.source, AbstractPartition):
|
||||
self.source.mount(destination=mount_dir)
|
||||
else:
|
||||
log_check_call(['mount'] + self.opts + [self.source, mount_dir])
|
||||
self.mount_dir = mount_dir
|
||||
|
||||
def unmount(self):
|
||||
"""Performs the unmount operation or asks the partition to unmount itself
|
||||
"""
|
||||
# If its a partition, it can unmount itself
|
||||
if isinstance(self.source, AbstractPartition):
|
||||
self.source.unmount()
|
||||
else:
|
||||
log_check_call(['umount', self.mount_dir])
|
||||
del self.mount_dir
|
||||
|
||||
def __getstate__(self):
|
||||
state = self.__dict__.copy()
|
||||
state['__class__'] = self.__module__ + '.' + self.__class__.__name__
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
for key in state:
|
||||
self.__dict__[key] = state[key]
|
|
@ -13,6 +13,7 @@ supported_classes = ['bootstrapvz.base.manifest.Manifest',
|
|||
'bootstrapvz.base.fs.partitionmaps.gpt.GPTPartitionMap',
|
||||
'bootstrapvz.base.fs.partitionmaps.msdos.MSDOSPartitionMap',
|
||||
'bootstrapvz.base.fs.partitionmaps.none.NoPartitions',
|
||||
'bootstrapvz.base.fs.partitions.mount.Mount',
|
||||
'bootstrapvz.base.fs.partitions.gpt.GPTPartition',
|
||||
'bootstrapvz.base.fs.partitions.gpt_swap.GPTSwapPartition',
|
||||
'bootstrapvz.base.fs.partitions.msdos.MSDOSPartition',
|
||||
|
|
|
@ -39,7 +39,6 @@ volume:
|
|||
os.close(handle)
|
||||
build_server.download(bootstrap_info.volume.image_path, image_path)
|
||||
build_server.delete(bootstrap_info.volume.image_path)
|
||||
# image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
||||
|
||||
try:
|
||||
image = tools.images.VirtualBoxImage(manifest, image_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue