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

« back to all changes in this revision

Viewing changes to lib/ec2/amitools/bundlemachineparameters.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/bundleparameters'
 
12
 
 
13
# The Bundle command line parameters.
 
14
class BundleMachineParameters < BundleParameters
 
15
 
 
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"'
 
33
                                  ]
 
34
 
 
35
  attr_accessor :kernel_id
 
36
  attr_accessor :ramdisk_id
 
37
  attr_accessor :ancestor_ami_ids
 
38
  attr_accessor :block_device_mapping
 
39
 
 
40
  def initialize(argv, name, add_mandatory_parameters_proc = nil, add_optional_parameters_proc = nil )
 
41
    add_optional_params = lambda do
 
42
      
 
43
      add_optional_parameters_proc.call      
 
44
      on( '--kernel ID', KERNEL_DESCRIPTION ) do |p|
 
45
        @kernel_id = p
 
46
      end
 
47
      
 
48
      on( '--ramdisk ID', RAMDISK_DESCRIPTION ) do |p|
 
49
        @ramdisk_id = p
 
50
      end
 
51
      
 
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
 
60
        end
 
61
      end
 
62
      separator('')
 
63
    end
 
64
 
 
65
    super(argv, name, add_mandatory_parameters_proc, add_optional_params)
 
66
  end
 
67
end