diff options
author | Paul Meyer <paulmey@microsoft.com> | 2016-08-25 16:43:46 -0700 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-09-21 16:43:18 -0400 |
commit | 30d0adb71c9adadf437b2a1c69529ad9f44e75a8 (patch) | |
tree | 5d945776dbb13014cc167037dc7ff137f150ce2a /cloudinit | |
parent | 40a400e42603aa1b80d9f623bc779799b370c091 (diff) | |
download | vyos-cloud-init-30d0adb71c9adadf437b2a1c69529ad9f44e75a8.tar.gz vyos-cloud-init-30d0adb71c9adadf437b2a1c69529ad9f44e75a8.zip |
Allow ephemeral drive to be unpartitioned
If device has no partition table, the first line of output from `sgdisk
-p <device>` will be "Creating new GPT entries.", instead of something
like "Disk /dev/sdb: 266338304 sectors, 127.0 GiB".
Also, protect against localized output by adjusting subp calls that
parse sgdisk output to set LANG=C.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_disk_setup.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py index b642f1f8..39a23688 100644 --- a/cloudinit/config/cc_disk_setup.py +++ b/cloudinit/config/cc_disk_setup.py @@ -33,6 +33,8 @@ BLKID_CMD = util.which("blkid") BLKDEV_CMD = util.which("blockdev") WIPEFS_CMD = util.which("wipefs") +LANG_C_ENV = {'LANG': 'C'} + LOG = logging.getLogger(__name__) @@ -355,8 +357,11 @@ def get_mbr_hdd_size(device): def get_gpt_hdd_size(device): - out, _ = util.subp([SGDISK_CMD, '-p', device]) - return out.splitlines()[0].split()[2] + out, _ = util.subp([SGDISK_CMD, '-p', device], update_env=LANG_C_ENV) + for line in out.splitlines(): + if line.startswith("Disk"): + return line.split()[2] + raise Exception("Failed to get %s size from sgdisk" % (device)) def get_hdd_size(table_type, device): @@ -408,7 +413,7 @@ def check_partition_mbr_layout(device, layout): def check_partition_gpt_layout(device, layout): prt_cmd = [SGDISK_CMD, '-p', device] try: - out, _err = util.subp(prt_cmd) + out, _err = util.subp(prt_cmd, update_env=LANG_C_ENV) except Exception as e: raise Exception("Error running partition command on %s\n%s" % ( device, e)) |