Cleanup disklabel.py
authorNikos Skalkotos <skalkoto@grnet.gr>
Mon, 3 Feb 2014 16:06:55 +0000 (18:06 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Mon, 3 Feb 2014 16:06:55 +0000 (18:06 +0200)
Remove --print-last-linux and change some other argument names

snf-image-helper/common.sh.in
snf-image-helper/disklabel.py
snf-image-helper/tasks/20FilesystemResizeUnmounted.in

index 3a5c2ec..dafcf55 100644 (file)
@@ -551,7 +551,7 @@ mount_all() {
             if [[ "$osfamily" =~ ^(open|net)bsd$ ]]; then
                 # OpenBSD DUIDs device naming
                 if [[ "${entry[1]}" =~ ^[a-f0-9]{16}\.[a-p]$ ]]; then
-                    duid="$(@scriptsdir@/disklabel.py --print-duid "$device")"
+                    duid="$(@scriptsdir@/disklabel.py --get-duid "$device")"
 
                     if [[ ! "${entry[1]}" =~ ^$duid ]]; then
                         warn "fstab refers to unknown DUID: \`$duid'"
index b5d566b..b0c4b5e 100755 (executable)
@@ -515,13 +515,10 @@ if __name__ == '__main__':
     parser.add_option("-l", "--list", action="store_true", dest="list",
                       default=False,
                       help="list the disklabel on the specified media")
-    parser.add_option("--print-last", action="store_true", dest="last_part",
-                      default=False,
+    parser.add_option("--get-last-partition", action="store_true",
+                      dest="last_part", default=False,
                       help="print the label of the last partition")
-    parser.add_option("--print-last-linux", action="store_true",
-                      dest="last_linux", default=False,
-                      help="print the linux number for the last partition")
-    parser.add_option("--print-duid", action="store_true", dest="duid",
+    parser.add_option("--get-duid", action="store_true", dest="duid",
                       default=False,
                       help="print the disklabel unique identifier")
     parser.add_option("-d", "--enlarge-disk", type="int", dest="disk_size",
@@ -550,12 +547,6 @@ if __name__ == '__main__':
     if options.last_part:
         print "%c" % chr(ord('a') + disklabel.get_last_partition_id())
 
-    if options.last_linux:
-        part_id = disklabel.get_last_partition_id()
-        # The linux kernel does not assign a partition for label 'c' that
-        # describes the whole disk
-        print part_id + (4 if part_id > 2 else 5)
-
     if options.disk_size is not None:
         disklabel.enlarge_disk(options.disk_size)
 
index 7cbc5e4..65c584c 100644 (file)
@@ -37,13 +37,19 @@ if [ ! -b "$SNF_IMAGE_DEV" ]; then
 fi
 
 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = openbsd ]; then
-   part="${SNF_IMAGE_DEV}$(@scriptsdir@/disklabel.py --print-last-linux "$SNF_IMAGE_DEV")"
+    bsd_part="$(@scriptsdir@/disklabel.py --get-last-partition "$SNF_IMAGE_DEV")"
+    if [ "$bsd_part" = "b" ]; then
+        warn "Last partition is swap space. Resizing ommited"
+        exit 0
+    fi
+
+    part="${SNF_IMAGE_DEV}$(disklabel2linux "$bsd_part")"
 
-   # If this fails the script will stop
-   $DUMPFS_OPENBSD "$part" > /dev/null
+    $DUMPFS_OPENBSD "$part" > /dev/null ||
+        { warn "Filesystem is not UFS. Resizing ommited"; exit 0; }
 
-   $GROWFS_OPENBSD -y "$part"
-   exit 0
+    $GROWFS_OPENBSD -y "$part"
+    exit 0
 fi
 
 if [ "$SNF_IMAGE_PROPERTY_OSFAMILY" = netbsd ]; then