Sha256: 218986b7e11b9c9c7f5f13d5b4aeea0ffbc819db1701674c6cc4b7fdee4c0f02

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

#   Copyright 2011 Red Hat, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

module Aeolus
  module Image
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aeolus-image-0.7.0 lib/aeolus_image/import.rb
aeolus-image-0.5.1 lib/aeolus_image/import.rb
aeolus-image-0.4.0 lib/aeolus_image/import.rb