From 87707486cd157c7aa32699ea79468a8e5e301832 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:03:02 +0100 Subject: [PATCH] Add mountopts to classes and methods --- bootstrapvz/base/fs/partitionmaps/gpt.py | 4 ++-- bootstrapvz/base/fs/partitionmaps/msdos.py | 4 ++-- bootstrapvz/base/fs/partitions/abstract.py | 11 +++++++++-- bootstrapvz/base/fs/partitions/base.py | 4 ++-- bootstrapvz/base/fs/partitions/gpt.py | 4 ++-- bootstrapvz/base/fs/partitions/gpt_swap.py | 2 +- bootstrapvz/base/fs/partitions/msdos.py | 11 ++++++++++- bootstrapvz/base/fs/partitions/msdos_swap.py | 2 +- bootstrapvz/base/fs/partitions/unformatted.py | 2 +- bootstrapvz/common/tasks/filesystem.py | 5 ++++- 10 files changed, 34 insertions(+), 15 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/gpt.py b/bootstrapvz/base/fs/partitionmaps/gpt.py index c515715..1243a32 100644 --- a/bootstrapvz/base/fs/partitionmaps/gpt.py +++ b/bootstrapvz/base/fs/partitionmaps/gpt.py @@ -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 diff --git a/bootstrapvz/base/fs/partitionmaps/msdos.py b/bootstrapvz/base/fs/partitionmaps/msdos.py index 22e53fd..74f88fa 100644 --- a/bootstrapvz/base/fs/partitionmaps/msdos.py +++ b/bootstrapvz/base/fs/partitionmaps/msdos.py @@ -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 diff --git a/bootstrapvz/base/fs/partitions/abstract.py b/bootstrapvz/base/fs/partitions/abstract.py index d2f18cc..cbbad80 100644 --- a/bootstrapvz/base/fs/partitions/abstract.py +++ b/bootstrapvz/base/fs/partitions/abstract.py @@ -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): diff --git a/bootstrapvz/base/fs/partitions/base.py b/bootstrapvz/base/fs/partitions/base.py index 00d0063..76c8f3b 100644 --- a/bootstrapvz/base/fs/partitions/base.py +++ b/bootstrapvz/base/fs/partitions/base.py @@ -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 diff --git a/bootstrapvz/base/fs/partitions/gpt.py b/bootstrapvz/base/fs/partitions/gpt.py index c8b1f31..aa77b8a 100644 --- a/bootstrapvz/base/fs/partitions/gpt.py +++ b/bootstrapvz/base/fs/partitions/gpt.py @@ -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 diff --git a/bootstrapvz/base/fs/partitions/gpt_swap.py b/bootstrapvz/base/fs/partitions/gpt_swap.py index 3dd2c53..c7f7c28 100644 --- a/bootstrapvz/base/fs/partitions/gpt_swap.py +++ b/bootstrapvz/base/fs/partitions/gpt_swap.py @@ -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]) diff --git a/bootstrapvz/base/fs/partitions/msdos.py b/bootstrapvz/base/fs/partitions/msdos.py index ad1dd6d..90c0bf9 100644 --- a/bootstrapvz/base/fs/partitions/msdos.py +++ b/bootstrapvz/base/fs/partitions/msdos.py @@ -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) diff --git a/bootstrapvz/base/fs/partitions/msdos_swap.py b/bootstrapvz/base/fs/partitions/msdos_swap.py index 24c40d2..48afcfc 100644 --- a/bootstrapvz/base/fs/partitions/msdos_swap.py +++ b/bootstrapvz/base/fs/partitions/msdos_swap.py @@ -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]) diff --git a/bootstrapvz/base/fs/partitions/unformatted.py b/bootstrapvz/base/fs/partitions/unformatted.py index 73af32d..b71be91 100644 --- a/bootstrapvz/base/fs/partitions/unformatted.py +++ b/bootstrapvz/base/fs/partitions/unformatted.py @@ -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) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 014554f..3e4c821 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -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'],