52
52
flags.DEFINE_integer('max_nbd_devices', 16,
53
53
'maximum number of possible nbd devices')
55
# NOTE(yamahata): DEFINE_list() doesn't work because the command may
56
# include ','. For example,
57
# mkfs.ext3 -O dir_index,extent -E stride=8,stripe-width=16
58
# --label %(fs_label)s %(target)s
60
# DEFINE_list() parses its argument by
61
# [s.strip() for s in argument.split(self._token)]
62
# where self._token = ','
63
# No escape nor exceptional handling for ','.
64
# DEFINE_list() doesn't give us what we need.
65
flags.DEFINE_multistring('virt_mkfs',
66
['windows=mkfs.ntfs --fast --label %(fs_label)s '
68
# NOTE(yamahata): vfat case
69
#'windows=mkfs.vfat -n %(fs_label)s %(target)s',
70
'linux=mkfs.ext3 -L %(fs_label)s -F %(target)s',
71
'default=mkfs.ext3 -L %(fs_label)s -F %(target)s'],
72
'mkfs commands for ephemeral device. The format is'
73
'<os_type>=<mkfs command>')
77
_DEFAULT_MKFS_COMMAND = None
80
for s in FLAGS.virt_mkfs:
81
# NOTE(yamahata): mkfs command may includes '=' for its options.
82
# So item.partition('=') doesn't work here
83
os_type, mkfs_command = s.split('=', 1)
85
_MKFS_COMMAND[os_type] = mkfs_command
86
if os_type == 'default':
87
_DEFAULT_MKFS_COMMAND = mkfs_command
90
def mkfs(os_type, fs_label, target):
91
mkfs_command = (_MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND) or
94
utils.execute(*mkfs_command.split())
56
97
def extend(image, size):
57
98
"""Increase image to size"""
149
190
LXC does not support qcow2 images yet.
192
out, err = utils.execute('mount', run_as_root=True)
193
for loop in out.splitlines():
194
if instance['name'] in loop:
195
device = loop.split()[0]
152
198
container_dir = '%s/rootfs' % target
153
199
utils.execute('umount', container_dir, run_as_root=True)
155
out, err = utils.execute('losetup', '-a', run_as_root=True)
156
for loop in out.splitlines():
157
if instance['name'] in loop:
158
device = loop.split(loop, ':')
159
_unlink_device(device, nbd)
200
_unlink_device(device, nbd)
201
except Exception, exn:
202
LOG.exception(_('Failed to remove container: %s'), exn)
162
205
def _link_device(image, nbd):
228
271
metadata_path = os.path.join(fs, "meta.js")
229
272
metadata = dict([(m.key, m.value) for m in metadata])
231
utils.execute('sudo', 'tee', metadata_path,
232
process_input=json.dumps(metadata))
274
utils.execute('tee', metadata_path,
275
process_input=json.dumps(metadata), run_as_root=True)
235
278
def _inject_key_into_fs(key, fs, execute=None):