← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~paul-meyer/cloud-init:fix-raw-ephemeral-disk into cloud-init:master

 

Paul Meyer has proposed merging ~paul-meyer/cloud-init:fix-raw-ephemeral-disk into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~paul-meyer/cloud-init/+git/cloud-init/+merge/304033

When the ephemeral drive is unpartitioned, sgdisk output has an extra line (see below), which fails get_gpt_hdd_size(). This patch add flexibility to handle this case.

root@sshvm2:~# sgdisk -p /dev/sdb
Creating new GPT entries.
Disk /dev/sdb: 266338304 sectors, 127.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 22D20184-BA9D-4C3B-8BF0-B6A45A8396C6
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 266338270
Partitions will be aligned on 2048-sector boundaries
Total free space is 266338237 sectors (127.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
root@sshvm2:~# 

-- 
Your team cloud init development team is requested to review the proposed merge of ~paul-meyer/cloud-init:fix-raw-ephemeral-disk into cloud-init:master.
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index b642f1f..352cd98 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -356,7 +356,10 @@ 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]
+    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):

Follow ups