~cbjchen/charms/trusty/cinder/fix_overwrite_config

« back to all changes in this revision

Viewing changes to hooks/cinder_utils.py

  • Committer: liang.chen at canonical
  • Date: 2014-11-29 14:58:42 UTC
  • Revision ID: liang.chen@canonical.com-20141129145842-xbynpade8si6eoqo
use disks with no filesystems or LVM

[cbjchen,r=]
The charm should use disks which do not
have previous filesystem or LVM even if
overwrite is set to "false"

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
    vg_found = False
316
316
    new_devices = []
317
317
    for device in devices:
318
 
        if (not is_lvm_physical_volume(device) or
319
 
                (is_lvm_physical_volume(device) and
320
 
                 list_lvm_volume_group(device) != volume_group)):
 
318
        if not is_lvm_physical_volume(device):
 
319
            # Unused device
 
320
            if overwrite is True or not has_partition_table(device):
 
321
                prepare_volume(device)
 
322
                new_devices.append(device)
 
323
        elif (is_lvm_physical_volume(device) and
 
324
              list_lvm_volume_group(device) != volume_group):
321
325
            # Existing LVM but not part of required VG or new device
322
326
            if overwrite is True:
323
 
                clean_storage(device)
 
327
                prepare_volume(device)
324
328
                new_devices.append(device)
325
 
                create_lvm_physical_volume(device)
326
329
        elif (is_lvm_physical_volume(device) and
327
330
                list_lvm_volume_group(device) == volume_group):
328
331
            # Mark vg as found
343
346
            extend_lvm_volume_group(volume_group, new_device)
344
347
 
345
348
 
 
349
def prepare_volume(device):
 
350
    clean_storage(device)
 
351
    create_lvm_physical_volume(device)
 
352
 
 
353
 
 
354
def has_partition_table(block_device):
 
355
    out = subprocess.check_output(['fdisk', '-l', block_device],
 
356
                                  stderr=subprocess.STDOUT)
 
357
    return "doesn't contain a valid partition" not in out
 
358
 
 
359
 
346
360
def clean_storage(block_device):
347
361
    '''Ensures a block device is clean.  That is:
348
362
        - unmounted