Add mountopts to classes and methods

This commit is contained in:
Michael Gerlach 2016-12-10 16:03:02 +01:00
parent 0a5a3e153b
commit 87707486cd
10 changed files with 34 additions and 15 deletions

View file

@ -41,7 +41,7 @@ class GPTPartitionMap(AbstractPartitionMap):
if 'boot' in data:
self.boot = GPTPartition(Sectors(data['boot']['size'], sector_size),
data['boot']['filesystem'], data['boot'].get('format_command', None),
'boot', last_partition())
data['boot'].get('mountopts', None), 'boot', last_partition())
if self.boot.previous is not None:
# No need to pad if this is the first partition
self.boot.pad_start += partition_gap
@ -57,7 +57,7 @@ class GPTPartitionMap(AbstractPartitionMap):
self.root = GPTPartition(Sectors(data['root']['size'], sector_size),
data['root']['filesystem'], data['root'].get('format_command', None),
'root', last_partition())
data['root'].get('mountopts', None), 'root', last_partition())
if self.root.previous is not None:
self.root.pad_start += partition_gap
self.root.size -= partition_gap

View file

@ -28,7 +28,7 @@ class MSDOSPartitionMap(AbstractPartitionMap):
if 'boot' in data:
self.boot = MSDOSPartition(Sectors(data['boot']['size'], sector_size),
data['boot']['filesystem'], data['boot'].get('format_command', None),
last_partition())
data['boot'].get('mountopts', None), 'boot', last_partition())
self.partitions.append(self.boot)
# Offset all partitions by 1 sector.
@ -46,7 +46,7 @@ class MSDOSPartitionMap(AbstractPartitionMap):
self.root = MSDOSPartition(Sectors(data['root']['size'], sector_size),
data['root']['filesystem'], data['root'].get('format_command', None),
last_partition())
data['root'].get('mountopts', None), 'root', last_partition())
if self.root.previous is not None:
self.root.pad_start += partition_gap
self.root.size -= partition_gap

View file

@ -19,7 +19,7 @@ class AbstractPartition(FSMProxy):
{'name': 'unmount', 'src': 'mounted', 'dst': 'formatted'},
]
def __init__(self, size, filesystem, format_command):
def __init__(self, size, filesystem, format_command, mountopts):
"""
:param Bytes size: Size of the partition
:param str filesystem: Filesystem the partition should be formatted with
@ -28,6 +28,8 @@ class AbstractPartition(FSMProxy):
self.size = size
self.filesystem = filesystem
self.format_command = format_command
# List of mount options
self.mountopts = mountopts
# Initialize the start & end padding to 0 sectors, may be changed later
self.pad_start = Sectors(0, size.sector_size)
self.pad_end = Sectors(0, size.sector_size)
@ -80,7 +82,12 @@ class AbstractPartition(FSMProxy):
def _before_mount(self, e):
"""Mount the partition
"""
log_check_call(['mount', '--types', self.filesystem, self.device_path, e.destination])
if self.mountopts is None:
mount_command = ['mount', '--types', self.filesystem, self.device_path, e.destination]
else:
mount_command = ['mount', '--options', ",".join(self.mountopts), '--types', self.filesystem, self.device_path, e.destination]
# Mount the partition
log_check_call(mount_command)
self.mount_dir = e.destination
def _after_mount(self, e):

View file

@ -20,7 +20,7 @@ class BasePartition(AbstractPartition):
{'name': 'unmap', 'src': 'mapped', 'dst': 'unmapped'},
]
def __init__(self, size, filesystem, format_command, previous):
def __init__(self, size, filesystem, format_command, mountopts, previous):
"""
:param Bytes size: Size of the partition
:param str filesystem: Filesystem the partition should be formatted with
@ -34,7 +34,7 @@ class BasePartition(AbstractPartition):
self.flags = []
# Path to symlink in /dev/disk/by-uuid (manually maintained by this class)
self.disk_by_uuid_path = None
super(BasePartition, self).__init__(size, filesystem, format_command)
super(BasePartition, self).__init__(size, filesystem, format_command, mountopts)
def create(self, volume):
"""Creates the partition

View file

@ -6,7 +6,7 @@ class GPTPartition(BasePartition):
"""Represents a GPT partition
"""
def __init__(self, size, filesystem, format_command, name, previous):
def __init__(self, size, filesystem, format_command, mountopts, name, previous):
"""
:param Bytes size: Size of the partition
:param str filesystem: Filesystem the partition should be formatted with
@ -15,7 +15,7 @@ class GPTPartition(BasePartition):
:param BasePartition previous: The partition that preceeds this one
"""
self.name = name
super(GPTPartition, self).__init__(size, filesystem, format_command, previous)
super(GPTPartition, self).__init__(size, filesystem, format_command, mountopts, previous)
def _before_create(self, e):
# Create the partition and then set the name of the partition afterwards

View file

@ -11,7 +11,7 @@ class GPTSwapPartition(GPTPartition):
:param Bytes size: Size of the partition
:param BasePartition previous: The partition that preceeds this one
"""
super(GPTSwapPartition, self).__init__(size, 'swap', None, 'swap', previous)
super(GPTSwapPartition, self).__init__(size, 'swap', None, None, 'swap', previous)
def _before_format(self, e):
log_check_call(['mkswap', self.device_path])

View file

@ -4,4 +4,13 @@ from base import BasePartition
class MSDOSPartition(BasePartition):
"""Represents an MS-DOS partition
"""
pass
def __init__(self, size, filesystem, format_command, mountopts, name, previous):
"""
:param Bytes size: Size of the partition
:param str filesystem: Filesystem the partition should be formatted with
:param list format_command: Optional format command, valid variables are fs, device_path and size
:param str name: The name of the partition
:param BasePartition previous: The partition that preceeds this one
"""
self.name = name
super(MSDOSPartition, self).__init__(size, filesystem, format_command, mountopts, previous)

View file

@ -11,7 +11,7 @@ class MSDOSSwapPartition(MSDOSPartition):
:param Bytes size: Size of the partition
:param BasePartition previous: The partition that preceeds this one
"""
super(MSDOSSwapPartition, self).__init__(size, 'swap', None, previous)
super(MSDOSSwapPartition, self).__init__(size, 'swap', None, None, 'swap', previous)
def _before_format(self, e):
log_check_call(['mkswap', self.device_path])

View file

@ -17,4 +17,4 @@ class UnformattedPartition(BasePartition):
:param Bytes size: Size of the partition
:param BasePartition previous: The partition that preceeds this one
"""
super(UnformattedPartition, self).__init__(size, None, None, previous)
super(UnformattedPartition, self).__init__(size, None, None, None, previous)

View file

@ -187,7 +187,10 @@ class FStab(Task):
fstab_lines = []
for mount_point in mount_points:
partition = mount_point['partition']
mount_opts = ['defaults']
if partition.mountopts is None:
mount_opts = ['defaults']
else:
mount_opts = partition.mountopts
fstab_lines.append('UUID={uuid} {mountpoint} {filesystem} {mount_opts} {dump} {pass_num}'
.format(uuid=partition.get_uuid(),
mountpoint=mount_point['path'],