Class: VolBundler

Inherits:
BundleTool show all
Defined in:
lib/ec2/amitools/bundlevol.rb

Constant Summary

Constants inherited from AMITool

AMITool::BACKOFF_PERIOD, AMITool::MAX_TRIES, AMITool::PROMPT_TIMEOUT

Instance Method Summary collapse

Methods inherited from BundleTool

#get_parameters, #notify, #user_override

Methods inherited from AMITool

#get_parameters, #handle_early_exit_parameters, #interactive?, #interactive_prompt, #retry_s3, #run, #warn_confirm

Instance Method Details

#bundle_vol(p) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ec2/amitools/bundlevol.rb', line 108

def bundle_vol(p)
  name = p.prefix
  image_file = File::join( p.destination, name )
  volume = File::join( p.volume, "" ) # Add a trailing "/" if not present.

  #
  # We can't bundle unless we're root.
  #
  raise "You need to be root to run #{$0}" unless SysChecks::root_user?

  #
  # Extra parameter verification.
  #
  raise "the specified size #{p.size}MB is too large" unless p.size <= MAX_SIZE_MB
  raise "the specified image file #{image_file} already exists" if File::exist?( image_file )

  #
  # Create a list of files to be included in the image. This list will override any
  # files that are excluded by the security filtered files list. Files are only added if
  # they are under the volume root.
  #
  includes = []
  p.includes.each do |file|
    includes << file
  end
  #
  # Create list of directories to exclude from the image. Always exclude special
  # directories, directories specified by the user and the image file itself.
  #
  exclude = []
  unless p.all
    #
    # Exclude mounted non-local filesystems if they are under the volume root.
    #
    EC2::Platform::Current::Mtab.load.entries.values.each do |entry|
      unless EC2::Platform::Current::LOCAL_FS_TYPES.include? entry.fstype
        exclude << entry.mpoint if entry.mpoint.index(volume) == 0
      end
    end
  end
  EC2::Platform::Current::Image::EXCLUDES.each { |dir| exclude << dir }

  #
  # Exclude user specified excluded directories if they are under the volume root.
  #
  p.exclude.each do |dir|
    exclude << dir
  end

  #
  # Exclude the image file if it is under the volume root.
  #
  if image_file.index( volume ) == 0
    exclude << image_file
  end

  # If we are inheriting instance data but can't access it we want to fail early
  if p.inherit && !EC2::InstanceData.new.instance_data_accessible
    raise EC2FatalError.new(12, "Can't access instance metadata. If you are not bundling on an EC2 instance use --no-inherit.")
  end

  #
  # Create image from volume.
  #
  image = EC2::Platform::Current::Image.new(volume,
                                            image_file,
                                            p.size,
                                            exclude,
                                            includes,
                                            p.filter,
                                            p.fstab,
                                            p.part_type,
                                            p.arch,
                                            p.script,
                                            @debug,
                                            p.grub_config)
  image.make

  $stdout.puts 'Image file created: %s' % [image_file]
  $stdout.puts 'Volume cloning done.'
  if p.clone_only
    $stdout.puts 'Not bundling image file since "--clone-only" flag was specified.'
  else
    #
    # Bundle the created image file.
    #
    $stdout.puts 'Bundling image file...'
    optional_args = {
      :kernel_id => p.kernel_id,
      :ramdisk_id => p.ramdisk_id,
      :product_codes => p.product_codes,
      :ancestor_ami_ids => p.ancestor_ami_ids,
      :block_device_mapping => p.block_device_mapping
    }
    Bundle.bundle_image(image_file,
                        p.user,
                        p.arch,
                        Bundle::ImageType::VOLUME,
                        p.destination,
                        p.user_pk_path,
                        p.user_cert_path,
                        p.ec2_cert_path,
                        nil, # prefix
                        optional_args,
                        @debug,
                        p.inherit)
  end
  $stdout.puts("#{BUNDLE_VOL_NAME} complete.")
end

#get_manualObject

——————————————————————————# Overrides ——————————————————————————#



222
223
224
# File 'lib/ec2/amitools/bundlevol.rb', line 222

def get_manual()
  BUNDLE_VOL_MANUAL
end

#get_nameObject



226
227
228
# File 'lib/ec2/amitools/bundlevol.rb', line 226

def get_name()
  BUNDLE_VOL_NAME
end

#main(p) ⇒ Object



230
231
232
# File 'lib/ec2/amitools/bundlevol.rb', line 230

def main(p)
  bundle_vol(p)
end