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/bundleparameters'
13
# The Bundle command line parameters.
14
class BundleMachineParameters < BundleParameters
16
KERNEL_DESCRIPTION = "Id of the default kernel to launch the AMI with."
17
RAMDISK_DESCRIPTION = "Id of the default ramdisk to launch the AMI with."
18
ANCESTOR_AMI_IDS_DESCRIPTION = "Lineage of this image. Comma separated list of AMI ids."
19
BDM_DESCRIPTION = ['Default block-device-mapping scheme to launch the AMI with. This scheme',
20
'defines how block devices may be exposed to an EC2 instance of this AMI',
21
'if the instance-type of the instance is entitled to the specified device.',
22
'The scheme is a comma-separated list of key=value pairs, where each key',
23
'is a "virtual-name" and each value, the corresponding native device name',
24
'desired. Possible virtual-names are:',
25
' - "ami": denotes the root file system device, as seen by the instance.',
26
' - "root": denotes the root file system device, as seen by the kernel.',
27
' - "swap": denotes the swap device, if present.',
28
' - "ephemeralN": denotes Nth ephemeral store; N is a non-negative integer.',
29
'Note that the contents of the AMI form the root file system. Samples of',
30
'block-device-mappings are:',
31
' - "ami=sda1,root=/dev/sda1,ephemeral0=sda2,swap=sda3"',
32
' - "ami=0,root=/dev/dsk/c0d0s0,ephemeral0=1"'
35
attr_accessor :kernel_id
36
attr_accessor :ramdisk_id
37
attr_accessor :ancestor_ami_ids
38
attr_accessor :block_device_mapping
40
def initialize(argv, name, add_mandatory_parameters_proc = nil, add_optional_parameters_proc = nil )
41
add_optional_params = lambda do
43
add_optional_parameters_proc.call
44
on( '--kernel ID', KERNEL_DESCRIPTION ) do |p|
48
on( '--ramdisk ID', RAMDISK_DESCRIPTION ) do |p|
52
on( '-B', '--block-device-mapping MAPS', String,
53
*BundleMachineParameters::BDM_DESCRIPTION ) do |p|
54
@block_device_mapping ||= {}
55
raise Error::InvalidValue.new( 'block-device-mapping', p ) if p.to_s.empty?
56
p.split(',').each do |mapping|
57
raise Error::InvalidValue.new( 'block-device-mapping', mapping ) unless mapping =~ /^\s*(\S)+\s*=\s*(\S)+\s*$/
58
virtual, device = mapping.split(/=/)
59
@block_device_mapping[virtual.strip] = device.strip
65
super(argv, name, add_mandatory_parameters_proc, add_optional_params)