diff options
author | Antonio Terceiro <terceiro@debian.org> | 2019-02-19 14:59:49 -0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-12-15 17:15:47 +0200 |
commit | 65228997d85a889c821772035724f5547fc12464 (patch) | |
tree | e16384a2f2a4d2608a3c402565b5157bf377a282 | |
parent | 6ab9cc3c5f3bc68957a8547391de3793a443fadf (diff) | |
download | vmdb2-65228997d85a889c821772035724f5547fc12464.tar.gz |
Add: step to create /etc/fstab
-rw-r--r-- | vmdb/plugins/fstab.mdwn | 12 | ||||
-rw-r--r-- | vmdb/plugins/fstab_plugin.py | 61 | ||||
-rw-r--r-- | without-tests | 1 |
3 files changed, 74 insertions, 0 deletions
diff --git a/vmdb/plugins/fstab.mdwn b/vmdb/plugins/fstab.mdwn new file mode 100644 index 0000000..a2c8eef --- /dev/null +++ b/vmdb/plugins/fstab.mdwn @@ -0,0 +1,12 @@ +Step: `fstab` +----------------------------------------------------------------------------- + +Create `/etc/fstab` inside the the image. + +Step keys: + +* `fstab` — REQUIRED; value is the tag for the root filesystem. + +Example (in the .vmdb file): + + - fstab: root diff --git a/vmdb/plugins/fstab_plugin.py b/vmdb/plugins/fstab_plugin.py new file mode 100644 index 0000000..da985bc --- /dev/null +++ b/vmdb/plugins/fstab_plugin.py @@ -0,0 +1,61 @@ +# Copyright 2019 Antonio Terceiro +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# =*= License: GPL-3+ =*= + +import os + +import cliapp + +import vmdb + + +class FstabPlugin(cliapp.Plugin): + + def enable(self): + self.app.step_runners.add(FstabStepRunner()) + + +class FstabStepRunner(vmdb.StepRunnerInterface): + + def get_required_keys(self): + return ['fstab'] + + def run(self, step, setting, state): + tag = step['fstab'] + chroot = state.tags.get_mount_point(tag) + + filesystems = [] + + for tag in state.tags.get_tags(): + device = state.tags.get_dev(tag) + mount_point = state.tags.get_target_mount_point(tag) + fstype = state.tags.get_fstype(tag) + output = vmdb.runcmd(['blkid', '-c', '/dev/null', '-o', 'value', '-s', 'UUID', device]) + if output: + uuid = output.decode().strip() + filesystems.append({ + 'uuid': uuid, + 'mount_point': mount_point, + 'fstype': fstype, + }) + else: + raise Exception('Unknown UUID for device {} (to be mounted on {})'.format(device, mount_point)) + + fstab_path = os.path.join(chroot, 'etc/fstab') + line = "UUID={uuid} {mount_point} {fstype} errors=remount-ro 0 1\n" + with open(fstab_path, 'w') as fstab: + for entry in filesystems: + fstab.write(line.format(**entry)) diff --git a/without-tests b/without-tests index eb3c686..d15cfe3 100644 --- a/without-tests +++ b/without-tests @@ -11,6 +11,7 @@ vmdb/plugins/chroot_plugin.py vmdb/plugins/debootstrap_plugin.py vmdb/plugins/echo_plugin.py vmdb/plugins/error_plugin.py +vmdb/plugins/fstab_plugin.py vmdb/plugins/grub_plugin.py vmdb/plugins/kernel_plugin.py vmdb/plugins/lvm2_plugin.py |