Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates-src > by-pkgid > 7643f0c3f070d52835fec28a2433cbb9 > files > 6

euca2ools-1.3.1-10.fc13.src.rpm

Index: euca2ools-1.3/bin/euca-bundle-vol
===================================================================
--- euca2ools-1.3.orig/bin/euca-bundle-vol
+++ euca2ools-1.3/bin/euca-bundle-vol
@@ -41,6 +41,8 @@ from euca2ools import Euca2ool, FileVali
     NotFoundError, CommandFailed, UnsupportedException
 from subprocess import *
 import platform
+import tempfile
+import stat
 
 usage_string = \
     """
@@ -193,6 +195,37 @@ def cleanup(path):
     if os.path.exists(path):
         os.remove(path)
 
+def get_fs_info(path):
+    fs_type = None
+    uuid = None
+    label = None
+    devpth = None
+    tmpd = None
+    try:
+        st_dev=os.stat(path).st_dev
+        dev=os.makedev(os.major(st_dev),os.minor(st_dev))
+        tmpd=tempfile.mkdtemp()
+        devpth=("%s/dev" % tmpd)
+        os.mknod(devpth,0400 | stat.S_IFBLK ,dev)
+    except:
+        raise
+
+    ret = { }
+    pairs = { 'LABEL' : 'label', 'UUID' : 'uuid' , 'FS_TYPE' : 'fs_type' }
+    for (blkid_n, my_n) in pairs.iteritems():
+        cmd = [ 'blkid', '-s%s' % blkid_n, '-ovalue', devpth ]
+        print cmd
+        try:
+            output = Popen(cmd, stdout=PIPE).communicate()[0]
+            ret[my_n]=output.rstrip()
+        except Exception, e:
+            os.unlink(devpth)
+            os.rmdir(tmpd)
+            raise UnsupportedException("Unable to determine %s for %s" % (blkid_n, path))
+
+    os.unlink(devpth)
+    os.rmdir(tmpd)
+    return(ret)
 
 def main():
     euca = None
@@ -355,9 +388,17 @@ def main():
         if product_code_string:
             product_codes = add_product_codes(product_code_string,
                     product_codes)
+
+        try:
+            fsinfo = get_fs_info(volume_path)
+        except UnsupportedException, e:
+            print e
+            sys.exit(1)
         try:
             image_path = euca.make_image(size_in_MB, excludes, prefix,
-                    destination_path)
+                    destination_path,
+                    fs_type=fsinfo['fs_type'], uuid=fsinfo['uuid'],
+                    label=fsinfo['label'])
         except NotFoundError:
             sys.exit(1)
         except UnsupportedException:
Index: euca2ools-1.3/euca2ools/euca2ools/__init__.py
===================================================================
--- euca2ools-1.3.orig/euca2ools/euca2ools/__init__.py
+++ euca2ools-1.3/euca2ools/euca2ools/__init__.py
@@ -213,13 +213,40 @@ devpts          /dev/pts      devpts   g
             print 'Creating disk image...', image_path
         Popen(dd_cmd, PIPE).communicate()[0]
 
-    def make_fs(self, image_path):
-        Util().check_prerequisite_command(self.MAKEFS_CMD)
+    def make_fs(self, image_path, fs_type = None, uuid = None, label = None):
+        mkfs_prog = self.MAKEFS_CMD
+        if fs_type:
+            mkfs_prog = "mkfs.%s" % fs_type
+        else:
+            fs_type = "ext3"
+
+        tunecmd = [ ]
+        if fs_type.startswith("ext"):
+            mkfs = [ mkfs_prog , '-F', image_path ]
+            if uuid: mkfs.extend([ '-U', uuid ])
+            if label: mkfs.extend([ '-L', label ])
+        elif fs_type == "xfs":
+            mkfs = [ mkfs_prog , image_path ]
+            if label: mkfs.extend([ '-L', label ])
+            tunecmd = [ 'xfs_admin', '-U', uuid ]
+
+        elif fs_type == "btrfs":
+            if uuid: raise(UnsupportedException("btrfs with uuid not supported"))
+            if label: mkfs.extend([ '-L', label ])
+        else:
+            raise(UnsupportedException("unsupported fs %s" % fs_type))
+
+
+        Util().check_prerequisite_command(mkfs_prog)
 
         if self.debug:
-            print 'Creating filesystem...'
-        makefs_cmd = Popen([self.MAKEFS_CMD, '-F', image_path],
-                           PIPE).communicate()[0]
+            print 'Creating filesystem with %s' % mkfs
+
+        makefs_cmd = Popen(mkfs,PIPE).communicate()[0]
+
+        if len(tunecmd):
+            Util().check_prerequisite_command(tunecmd[0])
+            tune_cmd = Popen(tunecmd,PIPE).communicate()[0]
 
     def add_fstab(
         self,
@@ -292,7 +319,7 @@ class SolarisImage:
         print 'Sorry. Solaris not supported yet'
         raise UnsupportedException
 
-    def make_fs(self, image_path):
+    def make_fs(self, image_path, fs_type = None, uuid = None, label = None):
         print 'Sorry. Solaris not supported yet'
         raise UnsupportedException
 
@@ -427,8 +454,11 @@ class NotFoundError:
 
 class UnsupportedException:
 
-    def __init__(self):
-        self.message = 'Not supported'
+    def __init__(self, msg=None):
+        if msg:
+            self.message = 'Not supported: %s' % msg
+        else:
+            self.message = 'Not supported'
 
 
 class CommandFailed:
@@ -1215,6 +1245,7 @@ class Euca2ool:
         excludes,
         prefix,
         destination_path,
+        fs_type = None, uuid = None, label = None
         ):
         image_file = '%s.img' % prefix
         image_path = '%s/%s' % (destination_path, image_file)
@@ -1224,7 +1255,7 @@ class Euca2ool:
             print 'Platform not fully supported.'
             raise UnsupportedException
         self.img.create_image(size_in_MB, image_path)
-        self.img.make_fs(image_path)
+        self.img.make_fs(image_path, fs_type=fs_type, uuid=uuid, label=label)
         return image_path
 
     def create_loopback(self, image_path):