Method: Fog::Compute::AWS::Real#register_image

Defined in:
lib/fog/compute/requests/aws/register_image.rb

#register_image(name, description, location, block_devices = [], options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/compute/requests/aws/register_image.rb', line 38

def register_image(name, description, location, block_devices=[], options={})
  common_options = {
    'Action'      => 'RegisterImage',
    'Name'        => name,
    'Description' => description,
    :parser       => Fog::Parsers::Compute::AWS::RegisterImage.new
  }

  # This determines if we are doing a snapshot or a S3 backed AMI.
  if(location =~ /^\/dev\/sd[a-p]\d{0,2}$/)
    common_options['RootDeviceName'] = location
  else
    common_options['ImageLocation'] = location
  end

  bdi = 0
  block_devices.each do |bd|
    bdi += 1
    ["DeviceName","VirtualName"].each do |n|
      common_options["BlockDeviceMapping.#{bdi}.#{n}"] = bd["#{n}"] if bd["#{n}"]
    end
    ["SnapshotId","VolumeSize","NoDevice","DeleteOnTermination"].each do |n|
      common_options["BlockDeviceMapping.#{bdi}.Ebs.#{n}"] = bd["#{n}"] if bd["#{n}"]
    end

  end

  request(common_options.merge!(options))
end