[PATCH conductor 7/8] images#show only shows the relevant provider for imported images
Tomas Sedovic
tsedovic at redhat.com
Wed Dec 14 12:40:07 UTC 2011
On 12/13/2011 08:09 PM, Matt Wagner wrote:
> ---
> src/app/controllers/images_controller.rb | 15 +++++++++++++--
> 1 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/src/app/controllers/images_controller.rb b/src/app/controllers/images_controller.rb
> index baf72e4..f7f9b0b 100644
> --- a/src/app/controllers/images_controller.rb
> +++ b/src/app/controllers/images_controller.rb
> @@ -36,8 +36,19 @@ class ImagesController< ApplicationController
>
> def show
> @image = Aeolus::Image::Warehouse::Image.find(params[:id])
> - # FIXME: This should be narrowed if the image is imported
> - @account_groups = ProviderAccount.group_by_type(current_user)
> + if @image.imported?
> + begin
> + # For an imported image, we only want to show the actual provider account
> + # This can raise exceptions with old/bad data, though, so rescue and show all providers
> + acct = ProviderAccount.find_by_label(@image.provider_images.first.provider_account_identifier)
This didn't work when I tried it with EC2. The
`provider_account_identifier` attribute returns the account's username
value (e.g. "AKIAJO2EXGWRYAKHD57Q"), rather than the label ("ec2").
So the `find` results in nil which in turns raises an exception on the
next line, which causes to render all the providers, not just EC2.
For the record, I did this with an image that I imported with all your
patches (and the new factory) in place. But it's still possible I'm
doing something wrong.
Anyway, this seems to do the trick for me:
acct =
Credential.find_by_value(@image.provider_images.first.provider_account_identifier).provider_account
But it would probably need to be scoped by the correct
`CredentialDefinition` type.
> + type = acct.provider.provider_type
> + @account_groups = {type.deltacloud_driver => {:type => type, :accounts => [acct]}}
> + rescue
> + @account_groups = ProviderAccount.group_by_type(current_user)
> + end
> + else
> + @account_groups = ProviderAccount.group_by_type(current_user)
> + end
> # according to imagefactory Builder.first shouldn't be implemented yet
> # but it does what we need - returns builder object which contains
> # all builds
More information about the aeolus-devel
mailing list