~awstools-dev/ubuntu/maverick/ec2-ami-tools/maverick

« back to all changes in this revision

Viewing changes to lib/ec2/amitools/bundleimage.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-10-14 08:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20081014083525-c0n69wr7r7aqfb8w
Tags: 1.3-26357-0ubuntu2
* New upstream version.
* Update the debian copyright file.
* Added quilt patch system to make it easier to maintain. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008 Amazon.com, Inc. or its affiliates.  All Rights
 
2
# Reserved.  Licensed under the Amazon Software License (the
 
3
# "License").  You may not use this file except in compliance with the
 
4
# License. A copy of the License is located at
 
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
 
6
# file.  This file is distributed on an "AS IS" BASIS, WITHOUT
 
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 
8
# the License for the specific language governing permissions and
 
9
# limitations under the License.
 
10
 
 
11
require 'ec2/amitools/bundle'
 
12
require 'ec2/amitools/bundleimageparameters'
 
13
 
 
14
require 'getoptlong'
 
15
 
 
16
MAX_SIZE = 10 * 1024 * 1024 * 1024 # 10 GB in bytes.
 
17
NAME = 'ec2-bundle-image'
 
18
 
 
19
# The manual.
 
20
$manual=<<TEXT
 
21
#{NAME} is a command line tool that creates a bundled Amazon Machine \
 
22
Image (AMI) from a specified loopback filesystem image.
 
23
 
 
24
#{NAME} will:
 
25
- tar -S the AMI to preserve sparseness of the image file
 
26
- gzip the result
 
27
- encrypt it
 
28
- split it into parts
 
29
- generate a manifest file describing the bundled AMI
 
30
 
 
31
#{NAME} will bundle AMIs of up to 10GB.
 
32
TEXT
 
33
 
 
34
begin
 
35
  # Command line parameters.
 
36
  p = BundleImageParameters.new( ARGV, NAME )
 
37
rescue Exception => e
 
38
  STDERR.puts e.message
 
39
  STDERR.puts 'try --help' unless e.is_a? BundleParameters::Error::PromptTimeout
 
40
  exit 1
 
41
end
 
42
 
 
43
if p.show_help
 
44
    STDOUT.puts p.help
 
45
    exit 0
 
46
  end
 
47
  if p.manual
 
48
    STDOUT.puts $manual
 
49
    exit 0
 
50
  end
 
51
 
 
52
begin
 
53
  # Verify parameters.
 
54
  unless File.size( p.image_path ) <= MAX_SIZE
 
55
    raise "the specified image file #{p.image_path} is too large"
 
56
  end
 
57
 
 
58
  optional_args = {
 
59
    :kernel_id => p.kernel_id,
 
60
    :ramdisk_id => p.ramdisk_id,
 
61
    :product_codes => p.product_codes,
 
62
    :ancestor_ami_ids => p.ancestor_ami_ids,
 
63
    :block_device_mapping => p.block_device_mapping
 
64
  }
 
65
  STDOUT.puts 'Bundling image file...'
 
66
 
 
67
  Bundle.bundle_image( File::expand_path( p.image_path ),
 
68
                       p.user,
 
69
                       p.arch,
 
70
                       Bundle::ImageType::MACHINE,
 
71
                       p.destination,
 
72
                       p.user_pk_path,
 
73
                       p.user_cert_path,
 
74
                       p.ec2_cert_path,
 
75
                       p.prefix,
 
76
                       optional_args,
 
77
                       p.debug,
 
78
                       false
 
79
                     )
 
80
  
 
81
  STDOUT.puts( "#{NAME} complete." )
 
82
rescue Exception => e
 
83
  STDERR.puts "Error: #{e.message}"
 
84
  STDERR.puts e.backtrace if p.debug
 
85
  STDOUT.puts "#{NAME} failed."
 
86
  exit 1  
 
87
end