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
parent
b87d637951
commit
faeccd5588
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
import os
|
||||
import pyudev
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
|
||||
|
@ -201,7 +202,7 @@ def get_lv_blockdev(vg_name, lv_name):
|
|||
return dev.device_node
|
||||
|
||||
|
||||
def mkfs(fstype, device, label=None):
|
||||
def mkfs(fstype, device, label=None, mkfsargs=None):
|
||||
log.debug(
|
||||
'Creating {fstype} filesystem on {device} '
|
||||
'with label "{label}"'.format(
|
||||
|
@ -216,6 +217,8 @@ def mkfs(fstype, device, label=None):
|
|||
cmd = ['mkfs.{}'.format(fstype), '-q']
|
||||
if label:
|
||||
cmd += ('-L', label)
|
||||
if mkfsargs:
|
||||
cmd += shlex.split(mkfsargs)
|
||||
cmd.append(device)
|
||||
try:
|
||||
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||
|
|
|
@ -172,13 +172,14 @@ class VirtualMachine(object):
|
|||
for idx, part in enumerate(self.partitions):
|
||||
try:
|
||||
storage.mkfs(part['fstype'], partitions[idx],
|
||||
part.get('label'))
|
||||
part.get('label'), part.get('mkfsargs'))
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
for vol in self.volumes:
|
||||
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:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue