~ubuntu-branches/ubuntu/maverick/euca2ools/maverick-updates

« back to all changes in this revision

Viewing changes to bin/euca-bundle-vol

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2010-03-05 16:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20100305165925-40rmhda8swzojyva
Tags: 1.2-0ubuntu5
* Cherry pick fixes from upstream, up to bzr r265, fixes:
  - LP: #522398 - throw exceptions instead of sys.exit(1)
  - LP: #522396 - fix version string
  - LP: #523332 - check rsync return code
  - LP: #516738 - upstream fix for image store
  - LP: #525137 - don't sys.exit(1)
  - LP: #526697 - merge upstream fix for this one
  - LP: #531076 - fix euca-describe-instances against one instance
  - LP: #526591 - fix config file parsing

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
# Author: Neil Soman neil@eucalyptus.com
34
34
 
35
35
import getopt, sys, os
36
 
from euca2ools import Euca2ool, FileValidationError, DirValidationError, CopyError, MetadataReadError, Util
 
36
from euca2ools import Euca2ool, FileValidationError, DirValidationError, CopyError, MetadataReadError, Util, NotFoundError, CommandFailed, UnsupportedException
37
37
from subprocess import * 
38
38
import platform
39
39
 
88
88
 
89
89
MAX_IMAGE_SIZE = 1024 * 10
90
90
 
91
 
version_string = """    euca-bundle-vol version: 1.0 (BSD)"""
92
91
 
93
 
def usage():
 
92
def usage(status=1):
94
93
    print usage_string
95
 
    sys.exit()
 
94
    sys.exit(status)
96
95
 
97
96
def version():
98
 
    print version_string
 
97
    print Util().version()
99
98
    sys.exit()
100
99
 
101
100
def check_root():
186
185
    kernel=None
187
186
    user=None
188
187
    ramdisk=None
189
 
    cert_path=euca.get_environ('EC2_CERT')
190
 
    private_key_path=euca.get_environ('EC2_PRIVATE_KEY')
 
188
    try:
 
189
        cert_path=euca.get_environ('EC2_CERT')
 
190
        private_key_path=euca.get_environ('EC2_PRIVATE_KEY')
 
191
        ec2cert_path=euca.get_environ('EUCALYPTUS_CERT')
 
192
        user_string = euca.get_environ('EC2_USER_ID')
 
193
    except NotFoundError:
 
194
        sys.exit(1)
 
195
 
191
196
    prefix='image'
192
197
    size_in_MB = 10*1024
193
198
    destination_path='/disk1'
194
 
    ec2cert_path=euca.get_environ('EUCALYPTUS_CERT')
195
199
    target_arch='x86_64'
196
200
    mapping = None
197
201
    excludes_string = None
204
208
    fstab_path = None
205
209
    generate_fstab = False
206
210
    product_code_string = None
207
 
    user_string = euca.get_environ("EC2_USER_ID")
208
211
    if user_string:
209
212
        try:
210
213
            user = int(user_string)
215
218
 
216
219
    for name, value in euca.opts:
217
220
        if name in ('-h', '--help'):
218
 
            usage()
 
221
            usage(0)
219
222
        elif name in ('-c', '--cert'):
220
223
            cert_path = value
221
224
        elif name in ('-k', '--privatekey'):
312
315
        if inherit:
313
316
            ramdisk, kernel, mapping, product_codes, ancestor_ami_ids = get_instance_metadata(euca, ramdisk, kernel, mapping)
314
317
        if product_code_string:
315
 
            product_codes = add_product_codes(product_code_string, product_codes)   
316
 
        image_path = euca.make_image(size_in_MB, excludes, prefix, destination_path)    
 
318
            product_codes = add_product_codes(product_code_string, product_codes)
 
319
        try: 
 
320
            image_path = euca.make_image(size_in_MB, excludes, prefix, destination_path)
 
321
        except NotFoundError:
 
322
            sys.exit(1)
 
323
        except UnsupportedException:
 
324
            sys.exit(1)
317
325
        image_path = os.path.normpath(image_path)
318
326
        if (image_path.find(volume_path) == 0):
319
327
            exclude_image = image_path.replace(volume_path, "", 1)
327
335
            print "Unable to copy files" 
328
336
            cleanup(image_path)
329
337
            sys.exit(1)
 
338
        except NotFoundError:
 
339
            cleanup(image_path)
 
340
            sys.exit(1)
 
341
        except CommandFailed:
 
342
            cleanup(image_path)
 
343
            sys.exit(1)
 
344
        except UnsupportedException:
 
345
            cleanup(image_path)
 
346
            sys.exit(1)
330
347
 
331
348
        image_size, sha_image_digest = euca.check_image(image_path, destination_path)
332
349
        if not prefix:
333
350
            prefix = euca.get_relative_filename(image_path)
334
 
        tgz_file = euca.tarzip_image(prefix, image_path, destination_path)
 
351
        try:
 
352
            tgz_file = euca.tarzip_image(prefix, image_path, destination_path)
 
353
        except NotFoundError:
 
354
            sys.exit(1)
 
355
        except CommandFailed:
 
356
            sys.exit(1)
 
357
 
335
358
        encrypted_file, key, iv, bundled_size = euca.encrypt_image(tgz_file)
336
359
        os.remove(tgz_file)
337
360
        parts, parts_digest = euca.split_image(encrypted_file)