vmdesc: Allow specifying mkfs arguments

In some cases, the default options selected by the `mkfs.*` utilities
are insufficient. To allow overriding them, volumes and partitions in
the VM description now support an optional `mkfsargs` item, which will
be passed along when creating new filesystems.
master
Dustin 2015-07-12 13:07:27 -05:00
parent b87d637951
commit faeccd5588
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import logging import logging
import os import os
import pyudev import pyudev
import shlex
import subprocess import subprocess
@ -201,7 +202,7 @@ def get_lv_blockdev(vg_name, lv_name):
return dev.device_node return dev.device_node
def mkfs(fstype, device, label=None): def mkfs(fstype, device, label=None, mkfsargs=None):
log.debug( log.debug(
'Creating {fstype} filesystem on {device} ' 'Creating {fstype} filesystem on {device} '
'with label "{label}"'.format( 'with label "{label}"'.format(
@ -216,6 +217,8 @@ def mkfs(fstype, device, label=None):
cmd = ['mkfs.{}'.format(fstype), '-q'] cmd = ['mkfs.{}'.format(fstype), '-q']
if label: if label:
cmd += ('-L', label) cmd += ('-L', label)
if mkfsargs:
cmd += shlex.split(mkfsargs)
cmd.append(device) cmd.append(device)
try: try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)

View File

@ -172,13 +172,14 @@ class VirtualMachine(object):
for idx, part in enumerate(self.partitions): for idx, part in enumerate(self.partitions):
try: try:
storage.mkfs(part['fstype'], partitions[idx], storage.mkfs(part['fstype'], partitions[idx],
part.get('label')) part.get('label'), part.get('mkfsargs'))
except KeyError: except KeyError:
pass pass
for vol in self.volumes: for vol in self.volumes:
try: try:
storage.mkfs(vol['fstype'], lv_block(vol['name']), vol['name']) storage.mkfs(vol['fstype'], lv_block(vol['name']), vol['name'],
vol.get('mkfsargs'))
except KeyError: except KeyError:
pass pass