This patch implements:
https://www.aeolusproject.org/redmine/issues/2853
The page is not styled yet.
Note for the reviewers: to test this you need imagefactory-0.9.1-1 and aeolus-image-rubygem built from the latest source (it must include commit 289dcbf0bf53d24c9da6532fec8c6b6219187e33).
Rebuild all and push all should be working (tested on mock & ec2) and it should display the proper status (i.e. "not built" or "pushing").
If you deem the code worthy or only needing a couple of tiny fixes, feel free to push it, dear reviewer. This should definitely get into the upcoming release.
Thanks, Thomas
From: Tomas Sedovic tomas@sedovic.cz
https://www.aeolusproject.org/redmine/issues/2853
It shows the following states: not built, building, not pushed, pushing, pushed. And it allows the user to rebuild and re-push all images.
As things are now, building and pushing is a 2-step operation.
Note that the page isn't styled properly yet. --- src/app/controllers/catalog_entries_controller.rb | 92 ++++++++++++++++++++- src/app/views/catalog_entries/show.html.haml | 12 +-- src/config/routes.rb | 1 + 3 files changed, 97 insertions(+), 8 deletions(-)
diff --git a/src/app/controllers/catalog_entries_controller.rb b/src/app/controllers/catalog_entries_controller.rb index a8adbb6..a398998 100644 --- a/src/app/controllers/catalog_entries_controller.rb +++ b/src/app/controllers/catalog_entries_controller.rb @@ -54,9 +54,15 @@ class CatalogEntriesController < ApplicationController @catalog_entry = CatalogEntry.find(params[:id]) require_privilege(Privilege::VIEW, @catalog_entry.deployable) save_breadcrumb(catalog_catalog_entry_path(@catalog_entry.catalog, @catalog_entry), @catalog_entry.deployable.name) - @providers = Provider.all @catalogs_options = Catalog.all.map {|c| [c.name, c.id]} add_permissions_inline(@catalog_entry.deployable) + + images = @catalog_entry.deployable.fetch_images + builder = Aeolus::Image::Factory::Builder.first + @build_results = [] + ProviderAccount.group_by_type(current_user).each do |driver, groups| + @build_results << build_status(images, builder, driver, groups[:accounts].first) + end end
def create @@ -166,6 +172,22 @@ class CatalogEntriesController < ApplicationController redirect_to original_path.merge(original_params).merge("catalog_entries_preset_filter" => params[:catalog_entries_preset_filter], "catalog_entries_search" => params[:catalog_entries_search]) end
+ def build + catalog_entry = CatalogEntry.find(params[:catalog_entry_id]) + require_privilege(Privilege::MODIFY, catalog_entry.catalog) + require_privilege(Privilege::MODIFY, catalog_entry.deployable) + + images = catalog_entry.deployable.fetch_images + options = params[:build_options].to_sym + case options + when :rebuild_all + build_all(images) + when :push_all + push_all(images) + end + redirect_to catalog_catalog_entry_path(catalog_entry.catalog, catalog_entry) + end + private
def set_header @@ -192,4 +214,72 @@ class CatalogEntriesController < ApplicationController nil end end + + def build_status(images, builder, driver, account) + result = { :provider => account.provider.name } + + builds = images.map { |image| image.latest_pushed_or_unpushed_build } + return result.merge(:status => :not_built) if builds.any? { |b| b.blank? } + + building = builds.any? { |b| builder.find_active_build(b.id, driver) } + return result.merge(:status => :building) if building + + target_images = builds.map do |build| + build.target_images.find { |ti| ti.target == driver } + end + + if target_images.any? { |ti| ti.blank? } + return result.merge(:status => :not_built) + end + + pushing = target_images.any? do |ti| + builder.find_active_push(ti.id, account.provider.name, account.credentials_hash["username"]) + end + if pushing + return result.merge(:status => :pushing) + end + + provider_images = target_images.map do |target_image| + target_image.find_provider_image_by_provider_and_account(account.provider.name, account.warehouse_id).first + end + + if provider_images.any? { |pi| pi.blank? } + return result.merge(:status => :not_pushed) + end + return result.merge(:status => :pushed) + end + + def build_all(images) + images.each do |image| + factory_image = Aeolus::Image::Factory::Image.new(:id => image.id) + factory_image.targets = Provider.list_for_user(current_user, Privilege::VIEW).map {|p| p.provider_type.deltacloud_driver}.uniq.join(',') + factory_image.template = image.template + factory_image.save! + end + end + + def push_all(images) + provider_images = [] + images.each do |image| + ProviderAccount.group_by_type(current_user).each do |driver, groups| + account = groups[:accounts].first + + build = image.latest_pushed_or_unpushed_build + raise Exception.new t('catalog_entries.errors.images_not_built') unless build + target_image = build.target_images.find { |ti| ti.target == driver } + raise Exception.new t('catalog_entries.errors.images_not_built') unless target_image + provider_images << Aeolus::Image::Factory::ProviderImage.new( + :provider => account.provider.name, + :credentials => account.to_xml(:with_credentials => true), + :image_id => image.uuid, + :build_id => build.uuid, + :target_image_id => target_image.uuid + ) + end + end + + provider_images.each do |provider_image| + provider_image.save! + end + end end diff --git a/src/app/views/catalog_entries/show.html.haml b/src/app/views/catalog_entries/show.html.haml index 177d494..57174d9 100644 --- a/src/app/views/catalog_entries/show.html.haml +++ b/src/app/views/catalog_entries/show.html.haml @@ -19,19 +19,17 @@ %header %h2= t('.build')
- = form_tag() do - = select_tag :build_option, options_for_select([[t("rebuild_all"), 1]]) + = form_tag(catalog_catalog_entry_build_path(@catalog_entry.catalog, @catalog_entry)) do + = select_tag :build_options, options_for_select([[t("rebuild_all"), :rebuild_all], [t("push_all"), :push_all]]) = submit_tag t('.start'), :id => :start_build
%p.description= t('.build_description')
%ul#providers-list - - @providers.each do |provider| + - @build_results.each do |result| %li - %span.provider= provider.name - %span.status Building 98% - = form_tag() - %button on/off + %span.provider= result[:provider] + %span.status= result[:status]
%section.catalogs diff --git a/src/config/routes.rb b/src/config/routes.rb index 242e126..106a2a5 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -205,6 +205,7 @@ Conductor::Application.routes.draw do resources :catalog_entries do delete 'multi_destroy', :on => :collection post :filter, :on => :collection + post 'build' end end
On Wed, Nov 30, 2011 at 05:01:23PM +0100, tsedovic@redhat.com wrote:
From: Tomas Sedovic tomas@sedovic.cz
https://www.aeolusproject.org/redmine/issues/2853
It shows the following states: not built, building, not pushed, pushing, pushed. And it allows the user to rebuild and re-push all images.
As things are now, building and pushing is a 2-step operation.
Note that the page isn't styled properly yet.
I'm afraid that I'm not able to get this to apply. It looks like Imre's "Registering/deregistering multiple catalogs to deployment" badly conflicts with this.
I tried to back up to before this, merge your patch in, and then rebase, but the conflicts ended up being major. Your UI changes got discarded, and the two divergent versions of the controller are so different that I'm not sure how to go about resolving them.
Sorry I couldn't make it work. :(
-- Matt
aeolus-devel@lists.fedorahosted.org