~raxnetworking/nova/bare_bones_melange

« back to all changes in this revision

Viewing changes to nova/virt/disk.py

  • Committer: Rajaram Mallya
  • Date: 2011-09-14 11:46:48 UTC
  • mfrom: (1265.2.302 nova)
  • Revision ID: rajarammallya@gmail.com-20110914114648-a12n6zr1uctd3wxu
Merged from nova trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
flags.DEFINE_integer('max_nbd_devices', 16,
53
53
                     'maximum number of possible nbd devices')
54
54
 
 
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
 
59
#
 
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 '
 
67
                          '%(target)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>')
 
74
 
 
75
 
 
76
_MKFS_COMMAND = {}
 
77
_DEFAULT_MKFS_COMMAND = None
 
78
 
 
79
 
 
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)
 
84
    if os_type:
 
85
        _MKFS_COMMAND[os_type] = mkfs_command
 
86
    if os_type == 'default':
 
87
        _DEFAULT_MKFS_COMMAND = mkfs_command
 
88
 
 
89
 
 
90
def mkfs(os_type, fs_label, target):
 
91
    mkfs_command = (_MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND) or
 
92
                    '') % locals()
 
93
    if mkfs_command:
 
94
        utils.execute(*mkfs_command.split())
 
95
 
55
96
 
56
97
def extend(image, size):
57
98
    """Increase image to size"""
148
189
 
149
190
    LXC does not support qcow2 images yet.
150
191
    """
 
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]
 
196
 
151
197
    try:
152
198
        container_dir = '%s/rootfs' % target
153
199
        utils.execute('umount', container_dir, run_as_root=True)
154
 
    finally:
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)
160
203
 
161
204
 
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])
230
273
 
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)
233
276
 
234
277
 
235
278
def _inject_key_into_fs(key, fs, execute=None):