---
src/Gemfile | 21 +++++++++++----------
src/app/controllers/pools_controller.rb | 12 ++++++++----
src/app/models/catalog.rb | 11 -----------
src/app/models/catalog_entry.rb | 13 +++++++++++++
src/app/models/image.rb | 30 +++++++++++++++++-------------
src/app/models/pool.rb | 19 +++++++++++++++++++
src/app/views/pools/_images.haml | 19 +++++++++++++++++++
7 files changed, 87 insertions(+), 38 deletions(-)
create mode 100644 src/app/views/pools/_images.haml
diff --git a/src/Gemfile b/src/Gemfile
index 4a11254..3092790 100644
--- a/src/Gemfile
+++ b/src/Gemfile
@@ -24,14 +24,15 @@ gem 'railties'
gem 'fastercsv'
gem 'aeolus-image'
group :development, :test do
- #gem 'rspec-rails'
- #gem 'factory_girl_rails'
- #gem 'timecop'
- #gem 'capybara'
- #gem 'cucumber'
- #gem 'cucumber-rails'
- #gem 'database_cleaner'
- #gem 'vcr'
- #gem 'webmock'
- #gem 'launchy'
+ gem 'rspec-rails'
+ gem 'factory_girl_rails'
+ gem 'timecop'
+ gem 'capybara'
+ gem 'cucumber'
+ gem 'cucumber-rails'
+ gem 'database_cleaner'
+ gem 'vcr'
+ gem 'webmock'
+ gem 'launchy'
+ gem 'wirble'
end
diff --git a/src/app/controllers/pools_controller.rb
b/src/app/controllers/pools_controller.rb
index 1183e3e..796a99a 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -69,11 +69,15 @@ class PoolsController < ApplicationController
@view = filter_view? ? 'history_filter' : 'history_pretty'
end
#TODO add links to real data for history,properties,permissions
- @tabs = [{:name => 'Deployments', :view => @view, :id =>
'deployments', :count => @pool.deployments.count},
- #{:name => 'History', :view => @view, :id =>
'history'},
- {:name => 'Properties', :view => 'properties', :id
=> 'properties'}
- #{:name => 'Permissions', :view => 'permissions', :id
=> 'permissions'}
+ @tabs = [{:name => 'Deployments', :view => @view, :id =>
'deployments', :count => @pool.deployments.count},
+ #{:name => 'History', :view => @view, :id =>
'history'},
+ {:name => 'Properties', :view => 'properties',
:id => 'properties'},
+ {:name => 'Catalog Images', :view => 'images',
:id => 'images'}
+ #{:name => 'Permissions', :view => 'permissions',
:id => 'permissions'}
]
+ if "images" == params[:details_tab]
+ @map = @pool.provider_image_map
+ end
details_tab_name = params[:details_tab].blank? ? 'deployments' :
params[:details_tab]
@details_tab = @tabs.find {|t| t[:id] == details_tab_name} ||
@tabs.first[:name].downcase
@deployments = @pool.deployments if @details_tab[:id] == 'deployments'
diff --git a/src/app/models/catalog.rb b/src/app/models/catalog.rb
index 1449d3e..638b1f1 100644
--- a/src/app/models/catalog.rb
+++ b/src/app/models/catalog.rb
@@ -23,15 +23,4 @@ class Catalog < ActiveRecord::Base
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 52e94b3..7e0dd91 100644
--- a/src/app/models/catalog_entry.rb
+++ b/src/app/models/catalog_entry.rb
@@ -42,4 +42,17 @@ class CatalogEntry < ActiveRecord::Base
DeployableXML.new(DeployableXML.import_xml_from_url(url))
end
+ # Round up Catalog Entries, fetch their Deployables, and extract image UUIDs.
+ def fetch_images
+ images = []
+ fetch_image_uuids.each do |uuid|
+ images << Aeolus::Image::Image.find(uuid)
+ end
+ images.compact.uniq
+ end
+
+ def fetch_image_uuids
+ fetch_deployable.image_uuids
+ end
+
end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index a374d62..96a877b 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -21,23 +21,27 @@ class Image < WarehouseModel
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 = {}
+ # The iwhd API really isn't built for what we're trying to do.
+ # Here's a nutty workaround to not issues thousands of queries.
+ # images should be an array of Aeolus::Image::Image objects
+ # Please don't shoot me for this!
+ def self.provider_images_for_image_list(images)
+ # Fetch all of these, but only once
+ provider_images = Aeolus::Image::ProviderImage.all
+ target_images = Aeolus::Image::TargetImage.all
+ builds = Aeolus::Image::ImageBuild.all
+ return_objs = {}
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
+ _builds = builds.select{|b| b.instance_variable_get('@image') ==
image.uuid}
+ _builds.each do |build|
+ _target_images = target_images.select{|ti|
ti.instance_variable_get('@build') == build.uuid}
+ _target_images.each do |target_image|
+ _provider_images = provider_images.select{|pi|
pi.instance_variable_get('@target_image') == target_image.uuid}
+ return_objs[image.uuid] = _provider_images
end
end
end
- return_obj
+ return_objs
end
end
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index 76516b7..19e10e9 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -101,4 +101,23 @@ class Pool < ActiveRecord::Base
:order => (order_field || 'name') +' '+ (order_dir ||
'asc'))
end
+ def provider_image_map
+ catalog_entries = catalogs.collect{|c| c.catalog_entries}.flatten
+ all_images = catalog_entries.collect{|ce| ce.fetch_images}.flatten.uniq
+ provider_images = Image.provider_images_for_image_list(all_images)
+
+ return_obj = {}
+ catalogs.each do |catalog|
+ return_obj[catalog] = {}
+ catalog.catalog_entries.each do |catalog_entry|
+ return_obj[catalog][catalog_entry] = {}
+ images = catalog_entry.fetch_images
+ images.each do |image|
+ return_obj[catalog][catalog_entry][image] = provider_images[image.uuid]
+ end
+ end
+ end
+ return_obj
+ end
+
end
diff --git a/src/app/views/pools/_images.haml b/src/app/views/pools/_images.haml
new file mode 100644
index 0000000..26b8d3d
--- /dev/null
+++ b/src/app/views/pools/_images.haml
@@ -0,0 +1,19 @@
+- @map.each_pair do |catalog, catalog_entries|
+ %h1{:style => 'font-size: 18pt;'}
+ = catalog.name
+ Catalog
+
+ - catalog_entries.each_pair do |entry, images|
+ %h2{:style => 'font-size: 16pt;'}
+ = entry.name
+ Catalog Entry
+
+ - images.each_pair do |image, provider_images|
+ %h3{:style => 'font-size: 14pt;'}
+ Image:
+ = "#{image.name} (#{image.uuid})"
+
+ %ul
+ - provider_images.each do |provider_image|
+ %li
+ = "#{provider_image.uuid} pushed to #{provider_image.provider.name}"
--
1.7.6