module Aeolus::Image

Public Class Methods

import(provider_name, deltacloud_driver, image_id, account_id, environment, xml=nil, arch=nil) click to toggle source
# File lib/aeolus_image/import.rb, line 17
def self.import(provider_name, deltacloud_driver, image_id, account_id, environment, xml=nil, arch=nil)
  xml ||= "<image><name>#{image_id}</name></image>"
  image = Factory::Image.new(
    :target_name => deltacloud_driver,
    :provider_name => provider_name,
    :target_identifier => image_id,
    :image_descriptor => xml
  )
  image.save!
  # Set the provider_account_id on the image
  iwhd_image = Warehouse::Image.find(image.id)
  iwhd_image.set_attr("environment", environment)
  # For imported images, stash an :architecture flag on the image itself since we have no template
  iwhd_image.set_attr(:architecture, arch) if arch
  # Set the account on the provider image
  # This assumes (as is currently correct) that there will only be one provider image for imported images
  pimg = iwhd_image.provider_images.first
  # Check that we have provider images! If not, the import has failed.
  if pimg
    pimg.set_attr('provider_account_identifier', account_id)
    return image
  else
    iwhd_image.delete!
    raise "Image import failed to import provider image! Aborting."
  end
end