Some notes on initial integration of Aeolus and Matahari
by Perry Myers
cross-posting to Aeolus and Matahari upstream projects...
We discussed sort of a pilot project for integration of Matahari into
Aeolus usage. The driver for this is that we need a way for folks
upstream to be able to deploy a single node Aeolus environment managing
1 or more Fedora hosts using kvm/libvirt (or VMware)
The problem is that we don't have a way in this environment to
bootstrap, specifically for Aeolus to get the ip address of the guests
as they are booting on the libvirt/kvm/VMware hosts.
I thought that this would be a good simple first use case for running
Matahari in Aeolus managed guests. So here's what I propose:
* Aeolus uses Image Factory to build images... When those images are
either Fedora, RHEL or Windows IF will include Matahari and puppet in
the core images
* Aeolus will inject basic bootstrapping info for Matahari like broker
ip address and broker auth info (this ignores the more complex post
boot config process Carl has for the time being, this process is
quick and dirty just to get stuff working and then we can expand to
use Carl's process as a second step)
* This injection could happen in a few ways:
- During image build
- During image deployment (using guestfish to inject a config file)
- Other? Could rely on DNS SRV records w/ no broker auth (again this
is meant for developer environments, not production usage)
* When an instance is booted, matahari comes up uses the injected config
and connects to the broker and a "hey I'm a new guest on the bus"
event should be sent out which includes the ip address of the guest
* Simple QMF console written that runs as part of the Conductor
infrastructure that monitors the bus for new 'I'm here' events and
when it sees one it grabs the ip address and stores it in the database
* It then calls a processConfig method (on which Agent?) which gives a
puppet file to a guest agent to process via a call to puppet tool.
Return from that method should be success or failure (with logging
info probably) This means puppet needs to be baked into the image as
well along with matahari.
TODOs:
Matahari Team:
* Write host agent event for 'i'm here configure me, here's my ip
address'
* Write method (which agent?) for processConfig(puppet-conf)
Aeolus Team:
* Need to write a simple QMF Console app that is part of the Conductor
that registers for 'new guest' events and when it sees these reports
that to Conductor and calls the processConfig method with the right
puppet script
* Run a broker alongside the Conductor and other Aeolus core
infrastructure. The ip address of the host running this is what
needs to be pushed into images for bootstrapping
The end goal here should be making it EASY for someone to grab Aeolus
and set it up quickly to manage local resources (i.e. we don't want to
_require_ people playing with Aeolus to need an EC2 account)
Andrew/Adam: Random question, what links all of the top level objects on
a single host together? Is there a common/shared UUID exposed by each
Agent? If a guest comes up and the Host agent appears, I can query that
Host object for UUID. But how do I know which Network Agent is the one
on the same guest as the Host Agent with the UUID that I just got?
Perry
12 years, 1 month
[PATCH] allow retrying of image build and upload.
by Scott Seago
Signed-off-by: Scott Seago <sseago(a)redhat.com>
---
.../controllers/image_factory/builds_controller.rb | 36 ++++++++++++++++++++
src/app/models/image.rb | 11 ++++++
src/app/models/provider_image.rb | 6 +++
src/app/views/image_factory/templates/_builds.haml | 12 +++++-
src/config/routes.rb | 2 +-
src/spec/controllers/builds_controller_spec.rb | 14 ++++++++
6 files changed, 78 insertions(+), 3 deletions(-)
create mode 100644 src/app/views/image_factory/builds/index.haml
diff --git a/src/app/controllers/image_factory/builds_controller.rb b/src/app/controllers/image_factory/builds_controller.rb
index b6efe81..a9901e5 100644
--- a/src/app/controllers/image_factory/builds_controller.rb
+++ b/src/app/controllers/image_factory/builds_controller.rb
@@ -1,6 +1,9 @@
class ImageFactory::BuildsController < ApplicationController
before_filter [:require_user], :except => [:update_status]
+ def index
+ end
+
def create
@tpl = Template.find(params[:template_id])
check_permission
@@ -43,6 +46,39 @@ class ImageFactory::BuildsController < ApplicationController
# FIXME: is @tpl defined here? do we need check_permission here?
end
+ def retry
+ @tpl = Template.find(params[:template_id])
+ check_permission
+ begin
+ if params[:image_id]
+ image = Image.find(params[:image_id])
+ if image
+ errors = {}
+ warnings = []
+ image.rebuild!
+ flash[:notice] = "Queued rebuild for image #{image.name}"
+ else
+ flash[:warning] = "could not find image #{image_id}"
+ end
+ elsif params[:provider_image_id]
+ provider_image = ProviderImage.find(params[:provider_image_id])
+ if provider_image
+ provider_image.retry_upload!
+ flash[:notice] = "Queued upload for provider image #{provider_image.name}"
+ else
+ flash[:warning] = "could not find provider image #{provider_image_id}"
+ end
+ else
+ flash[:warning] = 'You need to specify either a provider or a provider image'
+ end
+ rescue
+ flash[:warning] = $!.message
+ logger.error $!.message
+ logger.error $!.backtrace.join("\n ")
+ end
+ redirect_to image_factory_template_path(@tpl, :details_tab => 'builds')
+ end
+
def update_status
image = Image.find_by_uuid(params[:uuid])
image = ProviderImage.find_by_uuid(params[:uuid]) unless image
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index f15f2da..f0434b8 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -84,6 +84,17 @@ class Image < ActiveRecord::Base
end
end
+ def rebuild!
+ # TODO: remove this check when we have UI for pushing images
+ if self.provider_type.providers.empty? or not self.provider_type.providers.detect {|p| !p.provider_accounts.empty?}
+ raise "Error: A valid provider and provider account are required to create and build templates"
+ end
+ self.status = STATE_QUEUED
+ self.save!
+ self.provider_images.each {|pimg| pimg.destroy}
+ Delayed::Job.enqueue(BuildJob.new(self.id))
+ end
+
def not_uploaded_providers
uploaded = self.provider_images
Provider.all(:conditions => {:provider_type_id => self.provider_type.id}).select do |p|
diff --git a/src/app/models/provider_image.rb b/src/app/models/provider_image.rb
index aee69a9..9cc0e23 100644
--- a/src/app/models/provider_image.rb
+++ b/src/app/models/provider_image.rb
@@ -37,6 +37,12 @@ class ProviderImage < ActiveRecord::Base
end
end
+ def retry_upload!
+ self.status = STATE_QUEUED
+ self.save!
+ Delayed::Job.enqueue(BuildJob.new(self.id))
+ end
+
def warehouse_bucket
'provider_images'
end
diff --git a/src/app/views/image_factory/builds/index.haml b/src/app/views/image_factory/builds/index.haml
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/views/image_factory/templates/_builds.haml b/src/app/views/image_factory/templates/_builds.haml
index 65cbc5a..446ceb2 100644
--- a/src/app/views/image_factory/templates/_builds.haml
+++ b/src/app/views/image_factory/templates/_builds.haml
@@ -19,12 +19,20 @@ Builds for
- else
- @images.each do |img|
%li
- = "#{img.name}-#{img.template.architecture}: #{img.status}"
+ - form_tag(retry_image_factory_builds_path, { :method => :post }) do
+ = "#{img.name}-#{img.template.architecture}: #{img.status}"
+ = hidden_field_tag :template_id, @tpl.id
+ = hidden_field_tag :image_id, img.id
+ = submit_tag "Retry build", :name => "build"
- if img.status == Image::STATE_COMPLETED
%ul
- img.provider_images.each do |pimg|
%li
- = "#{pimg.provider.name}: #{pimg.status}"
+ - form_tag(retry_image_factory_builds_path, { :method => :post }) do
+ = "#{pimg.provider.name}: #{pimg.status}"
+ = hidden_field_tag :template_id, @tpl.id
+ = hidden_field_tag :provider_image_id, img.id
+ = submit_tag "Retry upload", :name => "build"
- unless @tpl.imported
- img.not_uploaded_providers.each do |provider|
%li
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 313dd25..54c8ee6 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -46,7 +46,7 @@ ActionController::Routing::Routes.draw do |map|
r.resources :deployables, :collection => { :multi_destroy => :delete }
r.resources :templates, :collection => {:collections => :get, :add_selected => :get, :metagroup_packages => :get, :remove_package => :get, :multi_destroy => :delete}
r.connect "/builds/update_status.:format", :controller => :builds, :action => :update_status
- r.resources :builds, :collection => { :delete => :delete, :upload => :get }
+ r.resources :builds, :collection => { :delete => :delete, :upload => :get, :retry => :post }
end
map.namespace 'admin' do |r|
diff --git a/src/spec/controllers/builds_controller_spec.rb b/src/spec/controllers/builds_controller_spec.rb
index a3d7f4d..17fac9c 100644
--- a/src/spec/controllers/builds_controller_spec.rb
+++ b/src/spec/controllers/builds_controller_spec.rb
@@ -53,5 +53,19 @@ describe ImageFactory::BuildsController do
post :create, :template_id => @template.id, :target => ProviderType.find_by_codename("mock").id
end.should change(Image, :count).by(1)
end
+
+ it "retry build should update Image status" do
+ lambda do
+ post :create, :template_id => @template.id, :target => ProviderType.find_by_codename("mock").id
+ end.should change(Image, :count).by(1)
+ @template.images.size.should == 1
+ image = @template.images[0]
+ image.reload.status.should == "queued"
+ post :update_status, :uuid => image.uuid, :status => 'failed'
+ image.reload.status.should == "failed"
+ post :retry, :image_id => image.id, :template_id => @template.id
+ image.reload.status.should == "queued"
+
+ end
end
end
--
1.7.4
12 years, 2 months
Bugfox for 500 errors in connector log
by Jason Guiditta
If you are not seeing something to the effect of:
Error Received: #<Qmf2::Data:0x7f77ced19028 @schema=nil, @impl=#<Cqmf2::Data:0x7f77ced19078>>
in your connector log right after the logged debug message that starts with
"build method called with", this may be difficult to test. Everyone should be getting
this error right now, but that does not seem to be the case. If you get that error,
this fixes it, and tests that it works by removing a console method stub and running
the real call against factory. The stub is apparently why I did not see the error before.
[PATCH conductor] Bugfix: build and push always throw 500 errors
12 years, 2 months
[PATCH aeolus] Fix credential definitions
by jzigmund@redhat.com
From: Jozef Zigmund <jzigmund(a)redhat.com>
---
...20110331152400_change_credential_definitions.rb | 48 ++++++++++++++++++++
src/db/seeds.rb | 8 ++--
2 files changed, 52 insertions(+), 4 deletions(-)
create mode 100644 src/db/migrate/20110331152400_change_credential_definitions.rb
diff --git a/src/db/migrate/20110331152400_change_credential_definitions.rb b/src/db/migrate/20110331152400_change_credential_definitions.rb
new file mode 100644
index 0000000..9206504
--- /dev/null
+++ b/src/db/migrate/20110331152400_change_credential_definitions.rb
@@ -0,0 +1,48 @@
+class ChangeCredentialDefinitions < ActiveRecord::Migration
+ def self.up
+ transform_credential_definitions
+ end
+
+ def self.down
+ transform_credential_definitions_back
+ end
+
+ def self.transform_credential_definitions
+ ec2 = ProviderType.find_by_codename('ec2')
+ CredentialDefinition.all.each do |cred|
+ if cred.provider_type != ec2
+ if cred.name == 'username'
+ cred.update_attribute(:label, 'Username')
+ elsif cred.name == 'password'
+ cred.update_attribute(:label, 'Password')
+ end
+ else
+ if cred.name == 'username'
+ cred.update_attribute(:label, 'API Key')
+ elsif cred.name == 'password'
+ cred.update_attribute(:label, 'Secret')
+ end
+ end
+ end
+ end
+
+ def self.transform_credential_definitions_back
+ ec2 = ProviderType.find_by_codename('ec2')
+ CredentialDefinition.all.each do |cred|
+ if cred.provider_type != ec2
+ if cred.name == 'username'
+ cred.update_attribute(:label, 'API Key')
+ elsif cred.name == 'password'
+ cred.update_attribute(:label, 'Secret')
+ end
+ else
+ if cred.name == 'username'
+ cred.update_attribute(:label, 'Username')
+ elsif cred.name == 'password'
+ cred.update_attribute(:label, 'Password')
+ end
+ end
+ end
+ end
+
+end
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index cafcc79..69be3f4 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -126,15 +126,15 @@ end
if CredentialDefinition.all.empty?
ProviderType.all.each do |provider_type|
unless provider_type.codename == 'ec2'
- CredentialDefinition.create!(:name => 'username', :label => 'API Key', :input_type => 'text', :provider_type_id => provider_type.id)
- CredentialDefinition.create!(:name => 'password', :label => 'Secret', :input_type => 'password', :provider_type_id => provider_type.id)
+ CredentialDefinition.create!(:name => 'username', :label => 'Username', :input_type => 'text', :provider_type_id => provider_type.id)
+ CredentialDefinition.create!(:name => 'password', :label => 'Password', :input_type => 'password', :provider_type_id => provider_type.id)
end
end
#for ec2 provider type
ec2 = ProviderType.find_by_codename 'ec2'
- CredentialDefinition.create!(:name => 'username', :label => 'Username', :input_type => 'text', :provider_type_id => ec2.id)
- CredentialDefinition.create!(:name => 'password', :label => 'Password', :input_type => 'password', :provider_type_id => ec2.id)
+ CredentialDefinition.create!(:name => 'username', :label => 'API Key', :input_type => 'text', :provider_type_id => ec2.id)
+ CredentialDefinition.create!(:name => 'password', :label => 'Secret', :input_type => 'password', :provider_type_id => ec2.id)
CredentialDefinition.create!(:name => 'account_id', :label => 'AWS Account ID', :input_type => 'text', :provider_type_id => ec2.id)
CredentialDefinition.create!(:name => 'x509private', :label => 'EC2 x509 private key', :input_type => 'file', :provider_type_id => ec2.id)
CredentialDefinition.create!(:name => 'x509public', :label => 'EC2 x509 public key', :input_type => 'file', :provider_type_id => ec2.id)
--
1.7.4
12 years, 2 months
Updated Condor, Needs new Configure
by Ian Main
Hiya Folks,
Just wanted to let you all know we just put a new upstream condor
release in to the packages-testing repo. This version changes the name
of the deltacloud GAHP so a configuration change is also necessary.
Therefore, *you must update condor and aeolus-configure together*, or
you won't be able to start instances.
Thanks!
Ian
12 years, 2 months
ANNOUNCE: oz 0.3.0 release
by Chris Lalancette
All,
I'm pleased to announce release 0.3.0 of Oz. Oz is a program for doing
automated installation of guest operating systems with limited input from the
user.
Release 0.3.0 is mostly a bugfix release for Oz. However, there are also
a few minor features included as well. Some of the highlights between Oz 0.2.0
and 0.3.0 are:
- Add the ability to specify the output directory for screenshots (the default
is still CWD).
- Add the ability to specify the bridge to use for installs (the default is
still the first libvirt NAT bridge on the system).
- Nicer error messages from the command-line tools when debugging is off.
- Add the ability to install Debian 5 and 6.
- Detect servers that can't possibly work for installing RedHat/Fedora OSs,
and fail the install.
- Allow installs with spaces in the name.
- Add the ability to install OpenSUSE 11.4.
More documentation on Oz is available here: http://aeolusproject.org/oz.html
If you have any questions or comments about oz, please feel free to contact
aeolus-devel(a)fedorahosted.org or me (clalance(a)redhat.com) directly.
Thanks,
--
Chris Lalancette
12 years, 2 months
[PATCH conductor] ImageImports UI and Image model changes to adapt to ImageImports UI need
by Francesco Vollero
From: Francesco Vollero <fvollero(a)redhat.com>
Hey guys, sorry for all this noise, but please throw away the latest 2 email i sent they included a mistake.
This patch its a review of the last patch of Image Imports. What i do here is:
1) Redesign the combobox design in a more slick way
2) Apply the jtomasek suggestion in cucumber test.
3) Fix a distraction bug in controller, uncommenting again the before_filter.
---
.../image_factory/image_imports_controller.rb | 25 ++++++++++++++++
src/app/models/image.rb | 10 +++++-
src/app/models/image_warehouse_object.rb | 1 +
src/app/views/image_factory/image_imports/new.haml | 8 +++++
src/config/locales/en.yml | 1 +
src/config/navigation.rb | 1 +
src/config/routes.rb | 1 +
src/features/image_import.feature | 30 ++++++++++++++++++++
8 files changed, 75 insertions(+), 2 deletions(-)
create mode 100644 src/app/controllers/image_factory/image_imports_controller.rb
create mode 100644 src/app/views/image_factory/image_imports/new.haml
create mode 100644 src/features/image_import.feature
diff --git a/src/app/controllers/image_factory/image_imports_controller.rb b/src/app/controllers/image_factory/image_imports_controller.rb
new file mode 100644
index 0000000..cd25f31
--- /dev/null
+++ b/src/app/controllers/image_factory/image_imports_controller.rb
@@ -0,0 +1,25 @@
+class ImageFactory::ImageImportsController < ApplicationController
+ before_filter :require_user
+
+ def new
+ init_provider_vars
+ end
+
+ def create
+ begin
+ Image.import(ProviderAccount.find(params[:provider_account_id]), params[:ami_id])
+ flash[:notice]="Image successfully imported"
+ redirect_to image_factory_templates_path
+ rescue => e
+ init_provider_vars
+ flash.now[:error]=e.message
+ Rails.logger.error([e.message,e.backtrace].join("\n "))
+ render :new
+ end
+ end
+
+protected
+def init_provider_vars
+ @providers = Provider.list_for_user(current_user, Privilege::VIEW)
+end
+end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index f15f2da..5e7c994 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -78,7 +78,7 @@ class Image < ActiveRecord::Base
# TODO: for now when build is finished we call upload automatically for all providers
def after_update
- if self.status_changed? and self.status == STATE_COMPLETED
+ if not self.new_record? and self.status_changed? and self.status == STATE_COMPLETED
safe_warehouse_sync
upload_to_all_providers_with_account
end
@@ -126,6 +126,9 @@ class Image < ActiveRecord::Base
end
def self.import(account, image_id)
+ if image_id.blank?
+ raise "image id should not be blank"
+ end
unless raw_image = account.connect.image(image_id)
raise "There is no image with '#{image_id}' id"
end
@@ -154,6 +157,8 @@ class Image < ActiveRecord::Base
:provider_type_id => account.provider.provider_type_id,
:template_id => template.id
)
+ image.generate_uuid
+ image.upload
image.save!
rep = ProviderImage.new(
@@ -162,9 +167,10 @@ class Image < ActiveRecord::Base
:provider_image_key => image_id,
:status => STATE_COMPLETED
)
+ rep.generate_uuid
+ rep.upload
rep.save!
- template.upload
end
image
end
diff --git a/src/app/models/image_warehouse_object.rb b/src/app/models/image_warehouse_object.rb
index 43f3b76..b88cc93 100644
--- a/src/app/models/image_warehouse_object.rb
+++ b/src/app/models/image_warehouse_object.rb
@@ -45,6 +45,7 @@ module ImageWarehouseObject
# TODO: for now there is no way how it check if bucket exists in warehouse
# so we try to create bucket everytime, if bucket exists, warehouse returns
# 500 Internal server error
+ raise "uuid is not set" unless self.uuid
warehouse.create_bucket(warehouse_bucket) rescue true
# TODO: we delete existing object if it exists
warehouse.bucket(warehouse_bucket).object(self.uuid).delete! rescue true
diff --git a/src/app/views/image_factory/image_imports/new.haml b/src/app/views/image_factory/image_imports/new.haml
new file mode 100644
index 0000000..cebc7a7
--- /dev/null
+++ b/src/app/views/image_factory/image_imports/new.haml
@@ -0,0 +1,8 @@
+- form_tag :image_factory_image_imports do
+ %fieldset.clear
+ = label_tag :provider_account_id, "Provider Account ID: "
+ = select_tag :provider_account_id, option_groups_from_collection_for_select(@providers,:provider_accounts, :name, :id,:name)
+ %fieldset.clear
+ = label_tag :ami_id, "Image ID: "
+ = text_field_tag :ami_id, params[:ami_id]
+ = restful_submit_tag "Import", 'create', image_factory_image_imports_path, 'POST', :class => "submit"
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 7a448de..7510a05 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -38,6 +38,7 @@ en:
assistance_requests: Assistance Requests
define: Define
deployables: Deployables
+ image_imports: Image Imports
basic_template: Template Builder Basic Workflow
browse_packages: Browse Packages
builds: Builds
diff --git a/src/config/navigation.rb b/src/config/navigation.rb
index bcf3b3b..b6944a5 100644
--- a/src/config/navigation.rb
+++ b/src/config/navigation.rb
@@ -10,6 +10,7 @@ SimpleNavigation::Configuration.run do |navigation|
second_level.item :templates, t(:templates), image_factory_templates_path
second_level.item :assemblies, t(:assemblies), image_factory_assemblies_path
second_level.item :deployables, t(:deployables), image_factory_deployables_path
+ second_level.item :image_imports, t(:image_imports), new_image_factory_image_import_path
end
first_level.item :administration, t(:administration), admin_users_path, :highlights_on => /\/admin/ do |second_level|
second_level.item :users, t(:users), admin_users_path
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 313dd25..98bc4f8 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -43,6 +43,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace 'image_factory' do |r|
r.resources :assemblies
+ r.resources :image_imports
r.resources :deployables, :collection => { :multi_destroy => :delete }
r.resources :templates, :collection => {:collections => :get, :add_selected => :get, :metagroup_packages => :get, :remove_package => :get, :multi_destroy => :delete}
r.connect "/builds/update_status.:format", :controller => :builds, :action => :update_status
diff --git a/src/features/image_import.feature b/src/features/image_import.feature
new file mode 100644
index 0000000..8fc6f7a
--- /dev/null
+++ b/src/features/image_import.feature
@@ -0,0 +1,30 @@
+Feature: Import Images
+ In order to use other images in my cloud infrastructure
+ As a user
+ I want to import images from other providers
+
+ Background:
+ Given I am an authorised user
+ And I am logged in
+ And I am on the homepage
+ And there is a provider named "testprovider"
+ And there is a provider account named "provider1"
+ And There is a mock pulp repository
+ When I go to the new image factory image import page
+ Then I should be on the new image factory image import page
+ When I select "provider1" from "provider_account_id"
+ And I fill in "ami_id" with "img1"
+
+ Scenario: Import a new image
+ Given I press "Import"
+ Then I should see "Image successfully imported"
+ And I should be on the image factory templates page
+
+ Scenario: Import an already imported image
+ Given I press "Import"
+ When I go to the new image factory image import page
+ When I select "provider1" from "provider_account_id"
+ And I fill in "ami_id" with "img1"
+ And I press "Import"
+ Then I should see "Image 'img1' is already imported"
+ And I should be on the image factory image imports page
--
1.7.4.2
12 years, 2 months
[PATCH conductor] Ssh user renamed to 'root'
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/db/migrate/20110329104633_rename_ssh_user.rb | 15 +++++++++++++++
src/db/seeds.rb | 2 +-
2 files changed, 16 insertions(+), 1 deletions(-)
create mode 100644 src/db/migrate/20110329104633_rename_ssh_user.rb
diff --git a/src/db/migrate/20110329104633_rename_ssh_user.rb b/src/db/migrate/20110329104633_rename_ssh_user.rb
new file mode 100644
index 0000000..e77eae3
--- /dev/null
+++ b/src/db/migrate/20110329104633_rename_ssh_user.rb
@@ -0,0 +1,15 @@
+class RenameSshUser < ActiveRecord::Migration
+ def self.up
+ pt = ProviderType.first(:conditions => {:codename => 'ec2'})
+ pt.ssh_user = 'root'
+ pt.home_dir = '/root'
+ pt.save!
+ end
+
+ def self.down
+ pt = ProviderType.first(:conditions => {:codename => 'ec2'})
+ pt.ssh_user = 'ec2-user'
+ pt.home_dir = '/home/ec2-user'
+ pt.save!
+ end
+end
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index 33c78ed..00be305 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -107,7 +107,7 @@ end
# Provider types actually supported
if ProviderType.all.empty?
ProviderType.create!(:name => "Mock", :build_supported => true, :codename =>"mock")
- ProviderType.create!(:name => "Amazon EC2", :build_supported => true, :codename =>"ec2", :ssh_user => "ec2-user", :home_dir => "/home/ec2-user")
+ ProviderType.create!(:name => "Amazon EC2", :build_supported => true, :codename =>"ec2", :ssh_user => "root", :home_dir => "/root")
ProviderType.create!(:name => "GoGrid", :codename =>"gogrid")
ProviderType.create!(:name => "Rackspace", :codename =>"rackspace")
ProviderType.create!(:name => "RHEV-M", :codename =>"rhevm")
--
1.7.4
12 years, 2 months
[PATCH conductor] ImageImports UI and Image model changes to adapt to ImageImports UI need
by Francesco Vollero
From: Francesco Vollero <fvollero(a)redhat.com>
---
.../image_factory/image_imports_controller.rb | 28 +++++++++++++++++
src/app/models/image.rb | 10 +++++-
src/app/models/image_warehouse_object.rb | 1 +
src/app/views/image_factory/image_imports/new.haml | 14 ++++++++
src/config/locales/en.yml | 1 +
src/config/navigation.rb | 1 +
src/config/routes.rb | 1 +
src/features/image_import.feature | 33 ++++++++++++++++++++
8 files changed, 87 insertions(+), 2 deletions(-)
create mode 100644 src/app/controllers/image_factory/image_imports_controller.rb
create mode 100644 src/app/views/image_factory/image_imports/new.haml
create mode 100644 src/features/image_import.feature
diff --git a/src/app/controllers/image_factory/image_imports_controller.rb b/src/app/controllers/image_factory/image_imports_controller.rb
new file mode 100644
index 0000000..d8f3afa
--- /dev/null
+++ b/src/app/controllers/image_factory/image_imports_controller.rb
@@ -0,0 +1,28 @@
+class ImageFactory::ImageImportsController < ApplicationController
+ #before_filter :require_user
+
+ def new
+ init_provider_vars
+ end
+
+ def create
+ begin
+ Image.import(ProviderAccount.find(params[:provider_account_id]), params[:ami_id])
+ flash[:notice]="Image successfully imported"
+ redirect_to image_factory_templates_path
+ rescue => e
+ init_provider_vars
+ flash.now[:error]=e.message
+ Rails.logger.error([e.message,e.backtrace].join("\n "))
+ render :new
+ end
+ end
+
+protected
+def init_provider_vars
+ @providers = Provider.list_for_user(current_user, Privilege::VIEW)
+ if params[:provider]
+ @accounts_related_to_provider = Provider.find(params[:provider]).provider_accounts
+ end
+end
+end
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index f15f2da..5e7c994 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -78,7 +78,7 @@ class Image < ActiveRecord::Base
# TODO: for now when build is finished we call upload automatically for all providers
def after_update
- if self.status_changed? and self.status == STATE_COMPLETED
+ if not self.new_record? and self.status_changed? and self.status == STATE_COMPLETED
safe_warehouse_sync
upload_to_all_providers_with_account
end
@@ -126,6 +126,9 @@ class Image < ActiveRecord::Base
end
def self.import(account, image_id)
+ if image_id.blank?
+ raise "image id should not be blank"
+ end
unless raw_image = account.connect.image(image_id)
raise "There is no image with '#{image_id}' id"
end
@@ -154,6 +157,8 @@ class Image < ActiveRecord::Base
:provider_type_id => account.provider.provider_type_id,
:template_id => template.id
)
+ image.generate_uuid
+ image.upload
image.save!
rep = ProviderImage.new(
@@ -162,9 +167,10 @@ class Image < ActiveRecord::Base
:provider_image_key => image_id,
:status => STATE_COMPLETED
)
+ rep.generate_uuid
+ rep.upload
rep.save!
- template.upload
end
image
end
diff --git a/src/app/models/image_warehouse_object.rb b/src/app/models/image_warehouse_object.rb
index 43f3b76..b88cc93 100644
--- a/src/app/models/image_warehouse_object.rb
+++ b/src/app/models/image_warehouse_object.rb
@@ -45,6 +45,7 @@ module ImageWarehouseObject
# TODO: for now there is no way how it check if bucket exists in warehouse
# so we try to create bucket everytime, if bucket exists, warehouse returns
# 500 Internal server error
+ raise "uuid is not set" unless self.uuid
warehouse.create_bucket(warehouse_bucket) rescue true
# TODO: we delete existing object if it exists
warehouse.bucket(warehouse_bucket).object(self.uuid).delete! rescue true
diff --git a/src/app/views/image_factory/image_imports/new.haml b/src/app/views/image_factory/image_imports/new.haml
new file mode 100644
index 0000000..1ca7826
--- /dev/null
+++ b/src/app/views/image_factory/image_imports/new.haml
@@ -0,0 +1,14 @@
+- form_tag do
+ %fieldset.clear
+ = label_tag :provider, "Provider: "
+ = select_tag "provider", options_from_collection_for_select(@providers, 'id', "name"),{:include_blank => true}
+ = restful_submit_tag "Choose", 'new',new_image_factory_image_import_path, 'GET', :class => 'button'
+ %fieldset.clear
+ - if @accounts_related_to_provider
+ = label_tag :provider_account_id, "Provider Account ID: "
+ = select_tag :provider_account_id, options_from_collection_for_select(@accounts_related_to_provider, "id", "name")
+ %fieldset.clear
+ = label_tag :ami_id, "Image ID: "
+ = text_field_tag :ami_id, params[:ami_id]
+ %fieldset.clear
+ = restful_submit_tag "Import", 'create', image_factory_image_imports_path, 'POST', :class => "submit"
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 7a448de..7510a05 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -38,6 +38,7 @@ en:
assistance_requests: Assistance Requests
define: Define
deployables: Deployables
+ image_imports: Image Imports
basic_template: Template Builder Basic Workflow
browse_packages: Browse Packages
builds: Builds
diff --git a/src/config/navigation.rb b/src/config/navigation.rb
index bcf3b3b..b6944a5 100644
--- a/src/config/navigation.rb
+++ b/src/config/navigation.rb
@@ -10,6 +10,7 @@ SimpleNavigation::Configuration.run do |navigation|
second_level.item :templates, t(:templates), image_factory_templates_path
second_level.item :assemblies, t(:assemblies), image_factory_assemblies_path
second_level.item :deployables, t(:deployables), image_factory_deployables_path
+ second_level.item :image_imports, t(:image_imports), new_image_factory_image_import_path
end
first_level.item :administration, t(:administration), admin_users_path, :highlights_on => /\/admin/ do |second_level|
second_level.item :users, t(:users), admin_users_path
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 313dd25..98bc4f8 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -43,6 +43,7 @@ ActionController::Routing::Routes.draw do |map|
map.namespace 'image_factory' do |r|
r.resources :assemblies
+ r.resources :image_imports
r.resources :deployables, :collection => { :multi_destroy => :delete }
r.resources :templates, :collection => {:collections => :get, :add_selected => :get, :metagroup_packages => :get, :remove_package => :get, :multi_destroy => :delete}
r.connect "/builds/update_status.:format", :controller => :builds, :action => :update_status
diff --git a/src/features/image_import.feature b/src/features/image_import.feature
new file mode 100644
index 0000000..697bb7d
--- /dev/null
+++ b/src/features/image_import.feature
@@ -0,0 +1,33 @@
+Feature: Import Images
+ In order to use other images in my cloud infrastructure
+ As a user
+ I want to import images from other providers
+
+ Background:
+ Given I am an authorised user
+ And I am logged in
+ And I am on the homepage
+ And there is a provider named "testprovider"
+ And there is a provider account named "provider1"
+ When I go to the new image factory image import page
+ Then I should be on the new image factory image import page
+ When I select "testprovider" from "provider"
+ And I press "Choose"
+ When I select "provider1" from "provider_account_id"
+ And I fill in "ami_id" with "img1"
+
+ Scenario: Import a new image
+ Given I press "Import"
+ Then I should see "Image successfully imported"
+ And I should be on the image factory templates page
+
+ Scenario: Import an already imported image
+ Given I press "Import"
+ When I go to the new image factory image import page
+ When I select "testprovider" from "provider"
+ And I press "Choose"
+ When I select "provider1" from "provider_account_id"
+ And I fill in "ami_id" with "img1"
+ And I press "Import"
+ Then I should see "Image 'img1' is already imported"
+ And I should be on the new image factory image import page
--
1.7.4.2
12 years, 2 months