summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMate Lakat <mate.lakat@citrix.com>2012-10-23 16:00:31 +0100
committerMate Lakat <mate.lakat@citrix.com>2012-10-23 16:09:37 +0100
commit20b349337eccaa7e1f49742a70f90488af7993fa (patch)
tree1baac5a4bfd2a9ae79d97ab1cb40fbf813b3204d /nova/utils.py
parenta0fcd1248071ad66b610eac4903adf36b314390b (diff)
Move mkfs from libvirt.utils to utils
Related to blueprint xenapi-config-drive Move mkfs function to nova.utils, so configdrive module does not depend on the libvirt module. This way, the configdrive module could be used by other virt modules. Change-Id: Ibda2aacfa0b66bc087e397df1474b5dfbe86d923
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 015ff915a..f49f3bc43 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1328,3 +1328,24 @@ def ensure_tree(path):
raise
else:
raise
+
+
+def mkfs(fs, path, label=None):
+ """Format a file or block device
+
+ :param fs: Filesystem type (examples include 'swap', 'ext3', 'ext4'
+ 'btrfs', etc.)
+ :param path: Path to file or block device to format
+ :param label: Volume label to use
+ """
+ if fs == 'swap':
+ execute('mkswap', path)
+ else:
+ args = ['mkfs', '-t', fs]
+ #add -F to force no interactive excute on non-block device.
+ if fs in ['ext3', 'ext4']:
+ args.extend(['-F'])
+ if label:
+ args.extend(['-n', label])
+ args.append(path)
+ execute(*args)