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.
11
require 'ec2/amitools/bundlemachineparameters'
13
# The Bundle Volume command line parameters.
14
class BundleVolParameters < BundleMachineParameters
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.']
40
class Error < RuntimeError
41
class InvalidExcludedDirectory < Error
43
super( "invalid excluded directory: #{dir}" )
48
def initialize( argv, name )
50
# Function to add optional parameters. This will be run by the
51
# parent class's initializer.
57
add_optional_params_proc = lambda do
58
on( '-a', '--all', *BundleVolParameters::ALL_DESCRIPTION ) do
62
on( '-e', '--exclude DIR1,DIR2,...', Array, *BundleVolParameters::EXCLUDE_DESCRIPTION ) do |p|
66
on( '-p', '--prefix PREFIX', String, PREFIX_DESCRIPTION ) do |p|
70
on( '-s', '--size MB', Integer, *BundleVolParameters::SIZE_DESCRIPTION) do |p|
74
on( '--[no-]inherit', *BundleVolParameters::INHERIT_DESCRIPTION ) do |p|
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 )
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 )
92
on( '--generate-fstab', *GENERATE_FSTAB_DESCRIPTION ) do
93
@generate_fstab = true
98
super( argv, name, nil, add_optional_params_proc )
101
# Set defaults for optional parameters.
103
@exclude = [] unless @exclude
104
@prefix = 'image' unless @prefix
105
@size = MAX_SIZE_MB unless @size
106
@volume = '/' unless @volume
108
if @fstab != nil and @generate_fstab != nil
109
raise Error::InvalidParameterCombination("--fstab and --generate-fstab conflict. Please do not supply both.")
114
@fstab = :legacy if @arch == "i386"
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 )