From: Jan Provaznik <jprovazn(a)redhat.com>
Cloud type is fetched from backend driver before save.
---
src/app/controllers/provider_controller.rb | 7 ++++---
src/app/models/provider.rb | 4 ++++
src/app/views/provider/_form.html.erb | 3 +--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/app/controllers/provider_controller.rb
b/src/app/controllers/provider_controller.rb
index 59c9393..7422c95 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -35,9 +35,10 @@ class ProviderController < ApplicationController
def new
require_privilege(Privilege::PROVIDER_MODIFY)
@provider = Provider.new(params[:provider])
- if request.post? && @provider.save &&
@provider.populate_hardware_profiles
- flash[:notice] = "Provider added."
- redirect_to :action => "show", :id => @provider
+ if request.post? && @provider.set_cloud_type &&
+ @provider.save && @provider.populate_hardware_profiles
+ flash[:notice] = "Provider added."
+ redirect_to :action => "show", :id => @provider
end
condormatic_classads_sync
end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index e439520..ae8e98f 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -38,6 +38,10 @@ class Provider < ActiveRecord::Base
:include => [:role],
:order => "permissions.id ASC"
+ def set_cloud_type
+ self.cloud_type = connect.driver_name
+ end
+
def connect
begin
return DeltaCloud.new(nil, nil, url)
diff --git a/src/app/views/provider/_form.html.erb
b/src/app/views/provider/_form.html.erb
index 9b4735f..6058894 100644
--- a/src/app/views/provider/_form.html.erb
+++ b/src/app/views/provider/_form.html.erb
@@ -5,9 +5,8 @@
<% form_tag :controller => :provider, :action => 'new' do %>
<ul>
<li><label>Name<span>Provide a descriptive name for this provider
connection.</span></label><%= text_field :provider, :name, :class =>
"txtfield" %></li>
- <li><label>Type<span>Choose the type of provider
connection.</span></label><%= select :provider, :cloud_type,
[["Mock","Mock"],["EC2",
"EC2"],["RHEV-M", "RHEV-M"]], :class =>
"txtfield" %></li>
<li><label>URL<span>Enter the URL of the cloud
provider.</span></label><%= text_field:provider, :url, :class =>
"txtfield" %></li>
</ul>
<%= submit_tag "Save", :class => "submit" %>
<% end %>
-</div>
\ No newline at end of file
+</div>
--
1.7.0.1
Show replies by date
From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/spec/models/provider_spec.rb | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index aa61cd5..7cabea7 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -60,6 +60,12 @@ describe Provider do
provider2.should_not be_valid
end
+ it "should set valid cloud type" do
+ @client.driver_name = @provider.cloud_type
+ @provider.cloud_type = nil
+ @provider.set_cloud_type
+ @provider.should be_valid
+ end
end
context "(using original connect method)" do
--
1.7.0.1
On Tue, 2010-08-03 at 09:26 +0200, jprovazn(a)redhat.com wrote:
From: Jan Provaznik <jprovazn(a)redhat.com>
Cloud type is fetched from backend driver before save.
---
src/app/controllers/provider_controller.rb | 7 ++++---
src/app/models/provider.rb | 4 ++++
src/app/views/provider/_form.html.erb | 3 +--
3 files changed, 9 insertions(+), 5 deletions(-)
ACK to the series.