---
src/app/controllers/api/images_controller.rb | 2 +
src/app/controllers/images_controller.rb | 4 ++-
src/app/models/image.rb | 40 --------------------------
src/lib/image.rb | 25 ++++++++++++++++
4 files changed, 30 insertions(+), 41 deletions(-)
delete mode 100644 src/app/models/image.rb
create mode 100644 src/lib/image.rb
diff --git a/src/app/controllers/api/images_controller.rb
b/src/app/controllers/api/images_controller.rb
index 1b83ff2..db82553 100644
--- a/src/app/controllers/api/images_controller.rb
+++ b/src/app/controllers/api/images_controller.rb
@@ -19,6 +19,8 @@
module Api
class ImagesController < ApplicationController
+ require "lib/image"
+
before_filter :require_user_api
respond_to :xml
diff --git a/src/app/controllers/images_controller.rb
b/src/app/controllers/images_controller.rb
index 3b89cc3..2adce72 100644
--- a/src/app/controllers/images_controller.rb
+++ b/src/app/controllers/images_controller.rb
@@ -16,6 +16,7 @@
class ImagesController < ApplicationController
before_filter :require_user
+ require "lib/image"
def index
set_admin_environments_tabs 'images'
@@ -44,6 +45,7 @@ class ImagesController < ApplicationController
provider = Provider.find_by_name(pimg.provider)
type = provider.provider_type
acct = ProviderAccount.find_by_provider_name_and_login(provider.name,
pimg.provider_account_identifier)
+ raise unless acct
@account_groups = {type.deltacloud_driver => {:type => type, :accounts
=> [acct]}}
rescue Exception => e
@account_groups = ProviderAccount.group_by_type(current_user)
@@ -90,7 +92,7 @@ class ImagesController < ApplicationController
xml = nil # It'll be assigned in Image.import
end
begin
- image = Image.import(account, params[:image_id])
+ image = Image.import(account, params[:image_id], xml)
flash[:success] = t("images.import.image_imported")
redirect_to image_url(image.id) and return
rescue Exception => e
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
deleted file mode 100644
index ef68a92..0000000
--- a/src/app/models/image.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# 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.
-#
-
-class Image
-
- # Given a Provider Account and an image ID, import the image
- # xml is an optional XML file describing the image (if omitted, we generate the XML)
- # Returns the Aeolus::Image::Factory::Image object, or raises any exceptions
encountered
- def self.import(provider_account, image_id, xml=nil)
- provider = provider_account.provider
- xml ||= "<image><name>#{image_id}</name></image>"
- image = Aeolus::Image::Factory::Image.new(
- :target_name => provider.provider_type.deltacloud_driver,
- :provider_name => provider.name,
- :target_identifier => image_id,
- :image_descriptor => xml
- )
- image.save!
- iwhd_image = Aeolus::Image::Warehouse::Image.find(image.id)
- # 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
- pimg.set_attr('provider_account_identifier',
provider_account.credentials_hash['username'])
- image
- end
-
-end
diff --git a/src/lib/image.rb b/src/lib/image.rb
new file mode 100644
index 0000000..2c8db1a
--- /dev/null
+++ b/src/lib/image.rb
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+class Image
+ # Given a ProviderAccount and an AMI/image ID on a provider, plus an optional XML
string, use aeolus-image
+ # to import the image. Returns an Aeolus::Image::Factory::Image or returns any raised
exceptions
+ def self.import(provider_account, image_id, xml=nil)
+ provider = provider_account.provider
+ account_id = provider_account.credentials_hash['username']
+ Aeolus::Image.import(provider.name, provider.provider_type.deltacloud_driver,
image_id, account_id, xml)
+ end
+end
--
1.7.6.4