def register_image(name, description, location, block_devices=[], options={})
unless name.empty?
image = {
'imageId' => Fog::AWS::Mock.image_id,
'imageLocation' => '',
'imageState' => 'pending',
'imageOwnerId' => self.data[:owner_id],
'isPublic' => false,
'productCodes' => [],
'architecture' => 'i386',
'imageType' => 'machine',
'kernelId' => Fog::AWS::Mock.kernel_id,
'ramdiskId' => Fog::AWS::Mock.ramdisk_id,
'platform' => 'Linux',
'stateReason' => {},
'imageOwnerAlias' => self.data[:owner_id],
'name' => name,
'description' => description,
'rootDeviceType' => '',
'rootDeviceName' => '',
'blockDeviceMapping' => [],
'virtualizationType' => 'paravirtual',
'hypervisor' => 'xen',
'registered' => Time.now
}
if location[/^\/dev\/sd[a-p]\d{0,2}$/]
image['rootDeviceName'] = location
image['rootDeviceType'] = 'ebs'
else
image['imageLocation'] = location
end
block_devices.each do |bd|
block_device_mapping = {
'ebs' => {}
}
["DeviceName","VirtualName"].each do |n|
block_device_mapping = bd[n] if bd[n]
end
["SnapshotId","VolumeSize","NoDevice","DeleteOnTermination"].each do |n|
block_device_mapping['ebs'][n] = bd[n] if bd[n]
end
image['blockDeviceMapping'] << block_device_mapping
end
self.data[:images][image['imageId']] = image
response = Excon::Response.new
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'imageId' => image['imageId']
}
response
else
message = 'MissingParameter => '
if name.empty?
message << 'The request must contain the parameter name'
end
raise Fog::Compute::AWS::Error.new(message)
end
end