Also, add 'create and add new cloud account from portal pool view'.
Added link on provider view to see existing accounts & add new accounts.
With the functionality added by this patch, I'm able to start Mock instances. 
Handy for demos!
---
 src/app/controllers/cloud_accounts_controller.rb   |   66 ++++++++++++++++++++
 src/app/controllers/portal_pool_controller.rb      |   22 +++++++
 src/app/views/cloud_accounts/_form.erb             |   13 ++++
 src/app/views/cloud_accounts/new.html.erb          |   14 ++++
 .../views/cloud_accounts/new_from_pool.html.erb    |   11 +++
 src/app/views/portal_pool/accounts.html.erb        |    2 +-
 .../views/portal_pool/accounts_for_pool.html.erb   |   36 +++++++++++
 7 files changed, 163 insertions(+), 1 deletions(-)
 create mode 100644 src/app/controllers/cloud_accounts_controller.rb
 create mode 100644 src/app/views/cloud_accounts/_form.erb
 create mode 100644 src/app/views/cloud_accounts/new.html.erb
 create mode 100644 src/app/views/cloud_accounts/new_from_pool.html.erb
 create mode 100644 src/app/views/portal_pool/accounts_for_pool.html.erb

diff --git a/src/app/controllers/cloud_accounts_controller.rb 
b/src/app/controllers/cloud_accounts_controller.rb
new file mode 100644
index 0000000..fc70ad5
--- /dev/null
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -0,0 +1,66 @@
+#
+# Copyright (C) 2010 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class CloudAccountsController < ApplicationController
+  before_filter :require_user
+
+  def new
+    @cloud_account = CloudAccount.new
+    @providers = []
+    all_providers = Provider.all
+    all_providers.each {|provider|
+      @providers << provider if authorized?(Privilege::PROVIDER_VIEW,provider)
+    }
+  end
+
+  def new_from_pool
+    @pool = PortalPool.find(params[:pool_id])
+    require_privilege(Privilege::ACCOUNT_ADD,@pool)
+    @cloud_account = CloudAccount.new
+    @providers = []
+    all_providers = Provider.all
+    all_providers.each {|provider|
+      @providers << provider if authorized?(Privilege::PROVIDER_VIEW,provider)
+    }
+  end
+
+
+  def create
+    @cloud_account = CloudAccount.new(params[:cloud_account])
+    @provider = Provider.find(params[:provider][:id])
+    require_privilege(Privilege::ACCOUNT_MODIFY,@provider)
+    @cloud_account.provider = @provider
+    @cloud_account.save!
+  end
+
+  def create_from_pool
+    @pool = PortalPool.find(params[:pool][:id])
+    @cloud_account = CloudAccount.new(params[:cloud_account])
+    @provider = Provider.find(params[:provider][:id])
+    @cloud_account.provider = @provider
+    @cloud_account.save!
+    @pool.cloud_accounts << @cloud_account unless @pool.cloud_accounts.map{|x| 
x.id}.include?(@cloud_account.id)
+    @pool.save!
+    redirect_to :controller => "portal_pool", :action => 'show', :id => 
@pool.id
+  end
+
+
+end
diff --git a/src/app/controllers/portal_pool_controller.rb 
b/src/app/controllers/portal_pool_controller.rb
index 1897fc9..0f2c8d4 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -77,4 +77,26 @@ class PortalPoolController < ApplicationController
 
   def delete
   end
+
+  def accounts_for_pool
+    @pool =  PortalPool.find(params[:pool_id])
+    require_privilege(Privilege::ACCOUNT_ADD,@pool)
+    @cloud_accounts = []
+    all_accounts = CloudAccount.all
+    all_accounts.each {|account|
+      if authorized?(Privilege::ACCOUNT_VIEW,account) && 
authorized?(Privilege::ACCOUNT_ADD,account)
+        @cloud_accounts << account unless @pool.cloud_accounts.map{|x| 
x.id}.include?(account.id)
+      end
+    }
+  end
+
+  def add_account
+    @portal_pool = PortalPool.find(params[:portal_pool])
+    @cloud_account = CloudAccount.find(params[:cloud_account])
+    @portal_pool.cloud_accounts << @cloud_account unless 
@portal_pool.cloud_accounts.map{|x| x.id}.include?(@cloud_account.id)
+    @portal_pool.save!
+    @portal_pool.populate_realms_and_images([...@cloud_account])
+    redirect_to :action => 'show', :id => @portal_pool.id
+  end
+
 end
diff --git a/src/app/views/cloud_accounts/_form.erb 
b/src/app/views/cloud_accounts/_form.erb
new file mode 100644
index 0000000..4fa1a79
--- /dev/null
+++ b/src/app/views/cloud_accounts/_form.erb
@@ -0,0 +1,13 @@
+<ul>
+  <li>
+    <%= form.label :username, "Cloud Account username" %>
+    <%= form.text_field :username %>
+  </li>
+  <li>
+    <%= form.label :password, "Cloud Account password" %>
+    <%= form.password_field :password %>
+  </li>
+  <li>
+     <%= select("provider", "id", @providers.map{|p| [p.name,p.id]} , { 
:include_blank => false }) %>
+  </li>
+</ul>
diff --git a/src/app/views/cloud_accounts/new.html.erb 
b/src/app/views/cloud_accounts/new.html.erb
new file mode 100644
index 0000000..40f32cb
--- /dev/null
+++ b/src/app/views/cloud_accounts/new.html.erb
@@ -0,0 +1,14 @@
+<% if @providers.size == 0 %>
+<h1>No Providers available to associate with a new cloud account</h1>
+<% else %>
+<h2 class="greeting">New Cloud Account</h2>
+
+<div class="dcloud_form">
+  <% form_for @cloud_account, :url => { :action => "create" } do |f| %>
+    <%= f.error_messages %>
+      <%= render :partial => "form", :object => f %>
+    <%= f.submit "Create Cloud Account", :class => "submit" %>
+  <% end %>
+  <%= link_to "Cancel", root_path, :class => 'actionlink'  %>
+</div>
+<% end %>
diff --git a/src/app/views/cloud_accounts/new_from_pool.html.erb 
b/src/app/views/cloud_accounts/new_from_pool.html.erb
new file mode 100644
index 0000000..747df03
--- /dev/null
+++ b/src/app/views/cloud_accounts/new_from_pool.html.erb
@@ -0,0 +1,11 @@
+<h2 class="greeting">New Cloud Account</h2>
+
+<div class="dcloud_form">
+  <% form_for @cloud_account, :url => { :action => "create_from_pool" } do |f| 
%>
+    <%= f.error_messages %>
+      <%= render :partial => "form", :object => f %>
+    <%= hidden_field :pool, :id %>
+    <%= f.submit "Create Cloud Account", :class => "submit" %>
+  <% end %>
+  <%= link_to "Cancel", root_path, :class => 'actionlink'  %>
+</div>
diff --git a/src/app/views/portal_pool/accounts.html.erb 
b/src/app/views/portal_pool/accounts.html.erb
index 81a8a76..e6b4f1c 100644
--- a/src/app/views/portal_pool/accounts.html.erb
+++ b/src/app/views/portal_pool/accounts.html.erb
@@ -18,6 +18,6 @@
     </tbody>
   </table>
 <% end %>
-<%= link_to "View/Add Existing Cloud Accounts", {:controller => 
"cloud_accounts",:action => "accounts_for_pool", :pool_id => @pool}, 
:class=>"actionlink" %>
+<%= link_to "View/Add Existing Cloud Accounts", {:controller => 
"portal_pool",:action => "accounts_for_pool", :pool_id => @pool}, 
:class=>"actionlink" %>
 <%= link_to "Add a New Cloud Account", {:controller => 
"cloud_accounts",:action => "new_from_pool", :pool_id => @pool}, 
:class=>"actionlink" %><br/>
 
diff --git a/src/app/views/portal_pool/accounts_for_pool.html.erb 
b/src/app/views/portal_pool/accounts_for_pool.html.erb
new file mode 100644
index 0000000..e273551
--- /dev/null
+++ b/src/app/views/portal_pool/accounts_for_pool.html.erb
@@ -0,0 +1,36 @@
+<% if @pool.cloud_accounts.size > 0 %>
+<h1>These Cloud Accounts are already attached to this pool</h1>
+<table>
+<thead>
+<tr>
+<th scope="col">Provider Name</th>
+<th scope="col">Cloud Account User Name</th>
+</tr>
+<% @pool.cloud_accounts.each {|a| %>
+<tr>
+<td><%= a.provider.name %></td>
+<td><%= a.username %></td>
+</tr>
+<% } %>
+</table>
+<% end %>
+
+<% if @cloud_accounts.size == 0 %>
+<h1>There are no existing Cloud Accounts available to add</h1>
+<% else %>
+<h1>These Cloud Accounts are available to add</h1>
+<table>
+<thead>
+<tr>
+<th scope="col">Provider Name</th>
+<th scope="col">Cloud Account User Name</th>
+</tr>
+<% @cloud_accounts.each {|a| %>
+<tr>
+<td><%= a.provider.name %></td>
+<td><%= a.username %> <%= link_to "Add this account", {:controller=> 
"portal_pool",
+  :action => "add_account", :portal_pool => @pool, :cloud_account => a}, 
:class => "actionlink" %></td>
+</tr>
+<% } %>
+</table>
+<% end %>
-- 
1.6.2.5

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to