Merge lp:~smoser/euca2ools/bundle-vol-copy-fs-info into lp:euca2ools

Proposed by Scott Moser
Status: Merged
Merge reported by: Mitch Garnaat
Merged at revision: not available
Proposed branch: lp:~smoser/euca2ools/bundle-vol-copy-fs-info
Merge into: lp:euca2ools
Diff against target: 160 lines (+83/-10)
2 files modified
bin/euca-bundle-vol (+43/-1)
euca2ools/euca2ools/__init__.py (+40/-9)
To merge this branch: bzr merge lp:~smoser/euca2ools/bundle-vol-copy-fs-info
Reviewer Review Type Date Requested Status
Mitch Garnaat (community) Approve
Review via email: mp+50167@code.launchpad.net

Description of the change

Mitch, This is the patch to bundle-vol that we're using in Ubuntu to copy the filesystem UUID and filesystem LABEL and filesystem TYPE to the new image.

To post a comment you must log in.
Revision history for this message
Mitch Garnaat (mitch-garnaat) wrote :

Merged upstream in r336.

Revision history for this message
Mitch Garnaat (mitch-garnaat) wrote :

Merged upstream in r336.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/euca-bundle-vol'
2--- bin/euca-bundle-vol 2011-01-14 14:47:13 +0000
3+++ bin/euca-bundle-vol 2011-02-17 15:19:33 +0000
4@@ -41,6 +41,8 @@
5 NotFoundError, CommandFailed, UnsupportedException
6 from subprocess import *
7 import platform
8+import tempfile
9+import stat
10
11 usage_string = \
12 """
13@@ -193,6 +195,37 @@
14 if os.path.exists(path):
15 os.remove(path)
16
17+def get_fs_info(path):
18+ fs_type = None
19+ uuid = None
20+ label = None
21+ devpth = None
22+ tmpd = None
23+ try:
24+ st_dev=os.stat(path).st_dev
25+ dev=os.makedev(os.major(st_dev),os.minor(st_dev))
26+ tmpd=tempfile.mkdtemp()
27+ devpth=("%s/dev" % tmpd)
28+ os.mknod(devpth,0400 | stat.S_IFBLK ,dev)
29+ except:
30+ raise
31+
32+ ret = { }
33+ pairs = { 'LABEL' : 'label', 'UUID' : 'uuid' , 'FS_TYPE' : 'fs_type' }
34+ for (blkid_n, my_n) in pairs.iteritems():
35+ cmd = [ 'blkid', '-s%s' % blkid_n, '-ovalue', devpth ]
36+ print cmd
37+ try:
38+ output = Popen(cmd, stdout=PIPE).communicate()[0]
39+ ret[my_n]=output.rstrip()
40+ except Exception, e:
41+ os.unlink(devpth)
42+ os.rmdir(tmpd)
43+ raise UnsupportedException("Unable to determine %s for %s" % (blkid_n, path))
44+
45+ os.unlink(devpth)
46+ os.rmdir(tmpd)
47+ return(ret)
48
49 def main():
50 euca = None
51@@ -355,9 +388,18 @@
52 if product_code_string:
53 product_codes = add_product_codes(product_code_string,
54 product_codes)
55+
56+ try:
57+ fsinfo = get_fs_info(volume_path)
58+ except UnsupportedException, e:
59+ print e
60+ sys.exit(1)
61 try:
62 image_path = euca.make_image(size_in_MB, excludes, prefix,
63- destination_path)
64+ destination_path,
65+ fs_type=fsinfo['fs_type'], uuid=fsinfo['uuid'],
66+ label=fsinfo['label'])
67+
68 except NotFoundError:
69 sys.exit(1)
70 except UnsupportedException:
71
72=== modified file 'euca2ools/euca2ools/__init__.py'
73--- euca2ools/euca2ools/__init__.py 2011-01-04 19:15:35 +0000
74+++ euca2ools/euca2ools/__init__.py 2011-02-17 15:19:33 +0000
75@@ -129,13 +129,40 @@
76 print 'Creating disk image...', image_path
77 Popen(dd_cmd, PIPE).communicate()[0]
78
79- def make_fs(self, image_path):
80- Util().check_prerequisite_command(self.MAKEFS_CMD)
81+ def make_fs(self, image_path, fs_type = None, uuid = None, label = None):
82+ mkfs_prog = self.MAKEFS_CMD
83+ if fs_type:
84+ mkfs_prog = "mkfs.%s" % fs_type
85+ else:
86+ fs_type = "ext3"
87+
88+ tunecmd = [ ]
89+ if fs_type.startswith("ext"):
90+ mkfs = [ mkfs_prog , '-F', image_path ]
91+ if uuid: mkfs.extend([ '-U', uuid ])
92+ if label: mkfs.extend([ '-L', label ])
93+ elif fs_type == "xfs":
94+ mkfs = [ mkfs_prog , image_path ]
95+ if label: mkfs.extend([ '-L', label ])
96+ tunecmd = [ 'xfs_admin', '-U', uuid ]
97+
98+ elif fs_type == "btrfs":
99+ if uuid: raise(UnsupportedException("btrfs with uuid not supported"))
100+ if label: mkfs.extend([ '-L', label ])
101+ else:
102+ raise(UnsupportedException("unsupported fs %s" % fs_type))
103+
104+
105+ Util().check_prerequisite_command(mkfs_prog)
106
107 if self.debug:
108- print 'Creating filesystem...'
109- makefs_cmd = Popen([self.MAKEFS_CMD, '-F', image_path],
110- PIPE).communicate()[0]
111+ print 'Creating filesystem with %s' % mkfs
112+
113+ makefs_cmd = Popen(mkfs,PIPE).communicate()[0]
114+
115+ if len(tunecmd):
116+ Util().check_prerequisite_command(tunecmd[0])
117+ tune_cmd = Popen(tunecmd,PIPE).communicate[0]
118
119 def add_fstab(
120 self,
121@@ -208,7 +235,7 @@
122 print 'Sorry. Solaris not supported yet'
123 raise UnsupportedException
124
125- def make_fs(self, image_path):
126+ def make_fs(self, image_path, fstype = None, uuid = None, label = None):
127 print 'Sorry. Solaris not supported yet'
128 raise UnsupportedException
129
130@@ -343,8 +370,11 @@
131
132 class UnsupportedException:
133
134- def __init__(self):
135- self.message = 'Not supported'
136+ def __init__(self, msg=None):
137+ if msg:
138+ self.message = 'Not supported: %s' % msg
139+ else:
140+ self.message = 'Not supported'
141
142
143 class CommandFailed:
144@@ -1131,6 +1161,7 @@
145 excludes,
146 prefix,
147 destination_path,
148+ fs_type = None, uuid = None, label = None
149 ):
150 image_file = '%s.img' % prefix
151 image_path = '%s/%s' % (destination_path, image_file)
152@@ -1140,7 +1171,7 @@
153 print 'Platform not fully supported.'
154 raise UnsupportedException
155 self.img.create_image(size_in_MB, image_path)
156- self.img.make_fs(image_path)
157+ self.img.make_fs(image_path, fs_type=fs_type, uuid=uuid, label=label)
158 return image_path
159
160 def create_loopback(self, image_path):

Subscribers

People subscribed via source and target branches