---
src/app/models/catalog.rb | 27 +++++++++++++++++++--------
src/app/models/catalog_entry.rb | 7 ++++++-
src/app/models/image.rb | 20 ++++++++++++++++++++
src/app/util/deployable_xml.rb | 4 ++++
4 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/src/app/models/catalog.rb b/src/app/models/catalog.rb
index 58640ec..1449d3e 100644
--- a/src/app/models/catalog.rb
+++ b/src/app/models/catalog.rb
@@ -10,17 +10,28 @@
#
class Catalog < ActiveRecord::Base
- include PermissionedObject
+ include PermissionedObject
- belongs_to :pool
- has_many :catalog_entries, :dependent => :destroy
- has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ belongs_to :pool
+ has_many :catalog_entries, :dependent => :destroy
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
:include => [:role],
:order => "permissions.id ASC"
- validates_presence_of :pool
- validates_presence_of :name
- validates_uniqueness_of :name
- validates_length_of :name, :maximum => 1024
+ validates_presence_of :pool
+ validates_presence_of :name
+ validates_uniqueness_of :name
+ validates_length_of :name, :maximum => 1024
+
+ # Round up Catalog Entries, fetch their Deployables, and extract image UUIDs.
+ def fetch_images
+ images = []
+ catalog_entries.each do |entry|
+ entry.fetch_deployable.image_uuids.each do |uuid|
+ images << Aeolus::Image::Image.find(uuid)
+ end
+ end
+ images.compact.uniq
+ end
end
diff --git a/src/app/models/catalog_entry.rb b/src/app/models/catalog_entry.rb
index fc1cb75..52e94b3 100644
--- a/src/app/models/catalog_entry.rb
+++ b/src/app/models/catalog_entry.rb
@@ -29,7 +29,7 @@ class CatalogEntry < ActiveRecord::Base
def accessible_and_valid_deployable_xml?(url)
begin
- deployable_xml = DeployableXML.new(DeployableXML.import_xml_from_url(url))
+ deployable_xml = fetch_deployable
deployable_xml.validate!
true
rescue
@@ -37,4 +37,9 @@ class CatalogEntry < ActiveRecord::Base
end
end
+ # Fetch the deployable contained at :url
+ def fetch_deployable
+ DeployableXML.new(DeployableXML.import_xml_from_url(url))
+ end
+
end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index eb65170..a374d62 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -20,4 +20,24 @@ class Image < WarehouseModel
def image_builds
ImageBuild.find_all_by_image_uuid(self.uuid)
end
+
+ # This is extraordinarily inefficient, but we allow it assuming that the calls
we're
+ # making will be optimized soon enough.
+ # Returns a hash of {image => [ProviderImages]}, which is really weird but exactly
what we'll need
+ def self.provider_images_for_images(images)
+ return_obj = {}
+ images.each do |image|
+ return_obj[image] = []
+ uuid = image.uuid
+ Aeolus::Image::ImageBuild.find_all_by_image_uuid(uuid).each do |build|
+ build.target_images.each do |target_image|
+ target_image.provider_images.each do |provider_image|
+ return_obj[image] << provider_image
+ end
+ end
+ end
+ end
+ return_obj
+ end
+
end
diff --git a/src/app/util/deployable_xml.rb b/src/app/util/deployable_xml.rb
index c4d2a80..220ae3d 100644
--- a/src/app/util/deployable_xml.rb
+++ b/src/app/util/deployable_xml.rb
@@ -62,6 +62,10 @@ class DeployableXML
end
end
+ def image_uuids
+ @image_uuids ||=
@root.xpath('/deployable/assemblies/assembly/image').collect{|x| x['id']}
+ end
+
def self.import_xml_from_url(url)
# Right now we allow this to raise exceptions on timeout / errors
resource = RestClient::Resource.new(url, :open_timeout => 10, :timeout => 45)
--
1.7.6