This is a combination form that creates a pool for a given
Provider as well as either mapping an existing cloud_account
to this pool, or creating a new one based on the credentials
provided in form.
On completion, user is brought to the list page for the pools
for this portal (just just the names, not formatted). This
will also show # instances in an upcoming patch.
Signed-off-by: Jason Guiditta <jason.guiditta(a)gmail.com>
---
src/app/controllers/portal_pool_controller.rb | 33 +++++++++++++++++++++++++
src/app/controllers/provider_controller.rb | 4 +-
src/app/helpers/portal_pool_helper.rb | 2 +
src/app/models/cloud_account.rb | 12 ++++++++-
src/app/models/provider.rb | 7 +++++
src/app/views/portal_pool/delete.html.erb | 2 +
src/app/views/portal_pool/index.html.erb | 8 ++++++
src/app/views/portal_pool/new.html.erb | 24 ++++++++++++++++++
src/app/views/portal_pool/show.html.erb | 2 +
src/app/views/provider/index.html.erb | 3 +-
src/app/views/provider/new.html.erb | 2 +-
11 files changed, 93 insertions(+), 6 deletions(-)
create mode 100644 src/app/controllers/portal_pool_controller.rb
create mode 100644 src/app/helpers/portal_pool_helper.rb
create mode 100644 src/app/views/portal_pool/delete.html.erb
create mode 100644 src/app/views/portal_pool/index.html.erb
create mode 100644 src/app/views/portal_pool/new.html.erb
create mode 100644 src/app/views/portal_pool/show.html.erb
diff --git a/src/app/controllers/portal_pool_controller.rb b/src/app/controllers/portal_pool_controller.rb
new file mode 100644
index 0000000..506885b
--- /dev/null
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -0,0 +1,33 @@
+class PortalPoolController < ApplicationController
+ def index
+ @pools = Provider.find(params[:id]).portal_pools
+ end
+
+ def show
+ end
+
+ def new
+ @portal_pool = PortalPool.new
+ @account = CloudAccount.new
+ @account.provider_id = params[:provider]
+ end
+
+ def create
+ @account = CloudAccount.find_or_create(params[:account])
+ #FIXME: This should probably be in a transaction
+ if @account.save
+ @portal_pool = @account.portal_pools.build(params[:portal_pool])
+ if @portal_pool.save
+ flash[:notice] = "Pool added."
+ redirect_to :action => 'index', :id => @account.provider_id
+ else
+ render :action => 'new'
+ end
+ else
+ render :action => 'new'
+ end
+ end
+
+ def delete
+ end
+end
diff --git a/src/app/controllers/provider_controller.rb b/src/app/controllers/provider_controller.rb
index 3469ac6..b3088f8 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -1,6 +1,6 @@
class ProviderController < ApplicationController
def index
- @providers = Provider.find(:all)
+ @provider = Provider.find(params[:id])
end
def show
@@ -10,7 +10,7 @@ class ProviderController < ApplicationController
@provider = Provider.new(params[:provider])
if request.post? && @provider.save @provider.populate_flavors
flash[:notice] = "Provider added."
- redirect_to :action => "index"
+ redirect_to :action => "index", :id => @provider
end
end
diff --git a/src/app/helpers/portal_pool_helper.rb b/src/app/helpers/portal_pool_helper.rb
new file mode 100644
index 0000000..5572ff3
--- /dev/null
+++ b/src/app/helpers/portal_pool_helper.rb
@@ -0,0 +1,2 @@
+module PortalPoolHelper
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
index c99b506..dd84726 100644
--- a/src/app/models/cloud_account.rb
+++ b/src/app/models/cloud_account.rb
@@ -15,6 +15,16 @@ class CloudAccount < ActiveRecord::Base
validates_presence_of :password
def connect
- DeltaCloud.new(username, password, provider.url)
+ begin
+ return DeltaCloud.new(username, password, provider.url)
+ rescue Exception => e
+ #TODO: log or return an exception
+ return nil
+ end
+ end
+
+ def self.find_or_create(account)
+ a = CloudAccount.find_by_username_and_provider_id(account["username"], account["provider_id"])
+ return a.nil? ? CloudAccount.new(account) : a
end
end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index e4c6890..3ef1d89 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -3,6 +3,7 @@ class Provider < ActiveRecord::Base
has_many :flavors
has_many :images
has_many :realms
+ has_many :portal_pools, :through=>:cloud_accounts
validates_presence_of :name
validates_uniqueness_of :name
@@ -35,6 +36,12 @@ class Provider < ActiveRecord::Base
end
end
+ # TODO: implement or remove - this is meant to contain a hash of
+ # supported cloud_types to use in populating form, though if we
+ # infer that field, we don't need this.
+ def supported_types
+ end
+
protected
def validate
if !nil_or_empty(url)
diff --git a/src/app/views/portal_pool/delete.html.erb b/src/app/views/portal_pool/delete.html.erb
new file mode 100644
index 0000000..b21ec14
--- /dev/null
+++ b/src/app/views/portal_pool/delete.html.erb
@@ -0,0 +1,2 @@
+<h1>ProviderController#delete</h1>
+<p>Find me in app/views/provider_controller/delete.html.erb</p>
diff --git a/src/app/views/portal_pool/index.html.erb b/src/app/views/portal_pool/index.html.erb
new file mode 100644
index 0000000..efb47e8
--- /dev/null
+++ b/src/app/views/portal_pool/index.html.erb
@@ -0,0 +1,8 @@
+<% if @pools.size == 0 %>
+<h1>There are no pools to display</h1>
+<% else %>
+ <%(a)pools.each {|pool| %>
+ <%= pool.name %><br/>
+ <% } %>
+<% end %>
+<%= link_to "Add a pool", :controller => "portal_pool", :action => "new", :provider => @provider%>
diff --git a/src/app/views/portal_pool/new.html.erb b/src/app/views/portal_pool/new.html.erb
new file mode 100644
index 0000000..adba03c
--- /dev/null
+++ b/src/app/views/portal_pool/new.html.erb
@@ -0,0 +1,24 @@
+<div class="dcloud_form">
+ <%= error_messages_for 'portal_pool' %>
+ <%= error_messages_for 'account' %>
+
+ <h2>Add a Pool and Account for this Provider</h2><br />
+
+ <% form_tag :action => 'create' do -%>
+ <fieldset>
+ <legend>Account</legend>
+ <ul>
+ <li><label>UserName<span>UserName for the account you wish to connect to this pool.</span></label><%= text_field :account, :username %></li>
+ <li><label>Password<span>Password for the account you wish to connect to this pool.</span></label><%=password_field :account, :password %></li>
+ </ul>
+ <%=hidden_field :account, :provider_id %>
+ </fieldset>
+ <fieldset>
+ <legend>Pool</legend>
+ <ul>
+ <li><label>Name<span>Provide a descriptive name for this pool.</span></label><%= text_field :portal_pool, :name %></li>
+ </ul>
+ </fieldset>
+ <%= submit_tag "Save", :class => "submit" %>
+ <% end %>
+</div>
\ No newline at end of file
diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb
new file mode 100644
index 0000000..f1c634a
--- /dev/null
+++ b/src/app/views/portal_pool/show.html.erb
@@ -0,0 +1,2 @@
+<h1>ProviderController#show</h1>
+<p>Find me in app/views/provider_controller/show.html.erb</p>
diff --git a/src/app/views/provider/index.html.erb b/src/app/views/provider/index.html.erb
index acd2676..ed4ddfc 100644
--- a/src/app/views/provider/index.html.erb
+++ b/src/app/views/provider/index.html.erb
@@ -1,2 +1 @@
-<h1>ProviderController#index</h1>
-<p>Find me in app/views/provider_controller/index.html.erb</p>
+This will likely just have the 'New Provider' form for now.
diff --git a/src/app/views/provider/new.html.erb b/src/app/views/provider/new.html.erb
index f73c15c..edde8f2 100644
--- a/src/app/views/provider/new.html.erb
+++ b/src/app/views/provider/new.html.erb
@@ -6,7 +6,7 @@
<% form_for :provider do |f| %>
<ul>
<li><label>Name<span>Provide a descriptive name for this provider connection.</span></label><%= f.text_field :name, :class => "txtfield" %></li>
- <li><label>Type<span>Choose the type of provider connection.</span></label><%= select :provider, :cloud_type, [["EC2", "EC2"],["RHEV-M", "RHEV-M"]], :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><%= f.text_field :url, :class => "txtfield" %></li>
</ul>
<%= submit_tag "Save", :class => "submit" %>
--
1.6.2.5