From: Jan Provaznik <jprovazn(a)redhat.com>
The newer boxgrinder uses euca2ools instead of ec2-ami-tools to build and upload
ec2 images. Ec2-ami-tools used to automatically create a amazon s3 bucket where
images are uploaded, euca2ools doesn't. In future boxgrinder should take care of
creation bucket but this will take time, so hotfix is to create bucket from
conductor when cloudaccount is created.
---
src/app/models/cloud_account_observer.rb | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/app/models/cloud_account_observer.rb
b/src/app/models/cloud_account_observer.rb
index a0826ea..299b9db 100644
--- a/src/app/models/cloud_account_observer.rb
+++ b/src/app/models/cloud_account_observer.rb
@@ -1,9 +1,33 @@
class CloudAccountObserver < ActiveRecord::Observer
def after_create(account)
+ # FIXME: new boxgrinder doesn't create bucket for amis automatically,
+ # for now we create bucket from conductor
+ # remove this hotfix when fixed on boxgrinder side
+ if account.provider.cloud_type == 'ec2'
+ create_bucket(account)
+ end
if key = account.generate_auth_key
account.update_attribute(:instance_key, InstanceKey.create!(:pem => key.pem,
:name => key.id, :instance_key_owner => account))
end
end
+
+ private
+
+ def create_bucket(account)
+ client = account.connect
+ bucket_name = "#{account.account_number}-imagefactory-amis"
+ # TODO (jprovazn): getting particular bucket takes long time (core fetches all
+ # buckets from provider), so we call directly create_bucket, if bucket exists,
+ # exception should be thrown (actually existing bucket is returned - this
+ # bug should be fixed soon)
+ #client.create_bucket(:name => bucket_name) unless client.bucket(bucket_name)
+ begin
+ client.create_bucket(:name => bucket_name)
+ rescue Exception => e
+ Rails.logger.error e.message
+ Rails.logger.error e.backtrace.join("\n ")
+ end
+ end
end
CloudAccountObserver.instance
--
1.7.3.5