~niedbalski/charms/trusty/swift-storage/fix-lp-1308557

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/storage/linux/utils.py

  • Committer: James Page
  • Date: 2014-04-16 08:34:53 UTC
  • mfrom: (24.1.17 swift-storage)
  • Revision ID: james.page@canonical.com-20140416083453-3n4gz51lk3p8tojd
[james-page,r=james-page,t=*]

Support for Icehouse on 12.04 and 14.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
from stat import S_ISBLK
3
3
 
4
4
from subprocess import (
5
 
    check_call
 
5
    check_call,
 
6
    check_output,
 
7
    call
6
8
)
7
9
 
8
10
 
22
24
 
23
25
    :param block_device: str: Full path of block device to clean.
24
26
    '''
25
 
    check_call(['sgdisk', '--zap-all', block_device])
 
27
    # sometimes sgdisk exits non-zero; this is OK, dd will clean up
 
28
    call(['sgdisk', '--zap-all', '--mbrtogpt',
 
29
          '--clear', block_device])
 
30
    dev_end = check_output(['blockdev', '--getsz', block_device])
 
31
    gpt_end = int(dev_end.split()[0]) - 100
 
32
    check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
 
33
                'bs=1M', 'count=1'])
 
34
    check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
 
35
                'bs=512', 'count=100', 'seek=%s'%(gpt_end)])