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

« back to all changes in this revision

Viewing changes to lib/ec2/amitools/bundlevolparameters.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/bundlemachineparameters'
 
12
 
 
13
# The Bundle Volume command line parameters.
 
14
class BundleVolParameters < BundleMachineParameters
 
15
  
 
16
  PREFIX_DESCRIPTION        = "The filename prefix for bundled AMI files. Defaults to \"image\"."
 
17
  EXCLUDE_DESCRIPTION       = ["A comma-separated list of absolute directory paths to exclude. This",
 
18
                               "option overrides the \"--all\" option."]
 
19
  ALL_DESCRIPTION           = ["Include all directories in the volume being bundled, including those",
 
20
                               "on remotely mounted filesystems."]
 
21
  SIZE_DESCRIPTION          = ["The size, in MB (1024 * 1024 bytes), of the image file to create.",
 
22
                               "The maximum size is 10240 MB."]
 
23
  VOLUME_DESCRIPTION        = "The absolute path to the mounted volume to be bundled. Defaults to \"/\"."
 
24
  FSTAB_DESCRIPTION         = "The absolute path to the fstab to be bundled into the image."
 
25
  GENERATE_FSTAB_DESCRIPTION= ["Inject a generated EC2 fstab. (Only use this if you are not rebundling",
 
26
                                "an existing instance.)"]
 
27
  INHERIT_DESCRIPTION       = ['Inherit instance metadata. Enabled by default.',
 
28
                               'Bundling will fail if inherit is enabled but instance data',
 
29
                               'is not accessible, for example not bundling an EC2 instance.']
 
30
  
 
31
  attr_accessor :all,
 
32
                :exclude,
 
33
                :prefix,
 
34
                :size,
 
35
                :volume,
 
36
                :fstab,
 
37
                :inherit,
 
38
                :generate_fstab
 
39
 
 
40
  class Error < RuntimeError
 
41
    class InvalidExcludedDirectory < Error
 
42
      def initialize( dir )
 
43
        super( "invalid excluded directory: #{dir}" )
 
44
      end
 
45
    end
 
46
  end
 
47
  
 
48
  def initialize( argv, name )    
 
49
    #
 
50
    # Function to add optional parameters. This will be run by the
 
51
    # parent class's initializer.
 
52
    #
 
53
      
 
54
    @inherit = true
 
55
    @fstab = nil
 
56
      
 
57
    add_optional_params_proc = lambda do
 
58
      on( '-a', '--all', *BundleVolParameters::ALL_DESCRIPTION ) do
 
59
        @all = true
 
60
      end
 
61
      
 
62
      on( '-e', '--exclude DIR1,DIR2,...', Array, *BundleVolParameters::EXCLUDE_DESCRIPTION ) do |p|
 
63
        @exclude = p
 
64
      end
 
65
      
 
66
      on( '-p', '--prefix PREFIX', String, PREFIX_DESCRIPTION ) do |p|
 
67
        @prefix = p
 
68
      end
 
69
      
 
70
      on( '-s', '--size MB', Integer,  *BundleVolParameters::SIZE_DESCRIPTION) do |p|
 
71
        @size = p
 
72
      end
 
73
      
 
74
      on( '--[no-]inherit', *BundleVolParameters::INHERIT_DESCRIPTION ) do |p|
 
75
        @inherit = p
 
76
      end
 
77
      
 
78
      on( '-v', '--volume PATH', String, VOLUME_DESCRIPTION ) do |volume|
 
79
        unless volume and File::exist?( volume ) and File::directory?( volume )
 
80
          raise Error::InvalidValue.new( 'volume', volume )
 
81
        end
 
82
        @volume = volume
 
83
      end
 
84
      
 
85
      on( '--fstab PATH', String, FSTAB_DESCRIPTION ) do |fstab|
 
86
        unless fstab and File::exist?( fstab ) and not File::directory?( fstab )
 
87
          raise Error::InvalidValue.new( 'fstab', fstab )
 
88
        end
 
89
        @fstab = fstab
 
90
      end
 
91
 
 
92
      on( '--generate-fstab', *GENERATE_FSTAB_DESCRIPTION ) do
 
93
        @generate_fstab = true
 
94
      end
 
95
 
 
96
    end
 
97
    
 
98
    super( argv, name, nil, add_optional_params_proc )
 
99
    
 
100
    #
 
101
    # Set defaults for optional parameters.
 
102
    #
 
103
    @exclude = [] unless @exclude
 
104
    @prefix = 'image' unless @prefix
 
105
    @size = MAX_SIZE_MB unless @size
 
106
    @volume = '/' unless @volume
 
107
 
 
108
    if @fstab != nil and @generate_fstab != nil
 
109
      raise Error::InvalidParameterCombination("--fstab and --generate-fstab conflict. Please do not supply both.")
 
110
    end
 
111
    
 
112
    if @generate_fstab
 
113
      @fstab = :default
 
114
      @fstab = :legacy if @arch == "i386"
 
115
    end
 
116
    #
 
117
    # Verify parameters.
 
118
    #
 
119
    unless @show_help or @manual
 
120
      @exclude.each do |dir|
 
121
        path = File::join( @volume, dir )
 
122
        unless File::exist?( path ) and File::directory?( path )
 
123
          raise Error::InvalidExcludedDirectory.new( dir ) 
 
124
        end
 
125
      end
 
126
    end
 
127
  end
 
128
end