Also, add 'create and add new cloud account from portal pool view'.
Added link on provider view to see existing accounts & add new accounts.
The permissions checking in this patch is woefully inadequate, but should be 
easy to add in before end of sprint!
With the functionality added by this patch, I'm able to start Mock instances. 
Handy for demos!
---
 src/app/controllers/cloud_accounts_controller.rb   |   86 ++++++++++++++++++++
 src/app/controllers/portal_pool_controller.rb      |   10 +++
 src/app/views/cloud_accounts/_form.erb             |   13 +++
 .../cloud_accounts/accounts_for_pool.html.erb      |   36 ++++++++
 src/app/views/cloud_accounts/new.html.erb          |   14 +++
 .../views/cloud_accounts/new_from_pool.html.erb    |   11 +++
 src/app/views/portal_pool/show.html.erb            |    6 +-
 7 files changed, 175 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/accounts_for_pool.html.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

diff --git a/src/app/controllers/cloud_accounts_controller.rb 
b/src/app/controllers/cloud_accounts_controller.rb
new file mode 100644
index 0000000..96a0e0f
--- /dev/null
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -0,0 +1,86 @@
+#
+# 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|
+      begin
+        require_privilege(Privilege::PROVIDER_VIEW,provider)
+        @providers << provider
+      rescue
+      end
+    }
+  end
+
+  def new_from_pool
+    @pool = PortalPool.find(params[:id])
+    @cloud_account = CloudAccount.new
+    @providers = []
+    all_providers = Provider.all
+    all_providers.each {|provider|
+      begin
+        require_privilege(Privilege::PROVIDER_VIEW,provider)
+        @providers << provider
+      rescue
+      end
+    }
+  end
+
+
+  def create
+    @cloud_account = CloudAccount.new(params[:cloud_account])
+    @provider = Provider.find(params[:provider][:id])
+    @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
+
+  def accounts_for_pool
+    @pool =  PortalPool.find(params[:id])
+    @cloud_accounts = []
+    all_accounts = CloudAccount.all
+    all_accounts.each {|account|
+      begin
+        require_privilege(Privilege::ACCOUNT_VIEW,account)
+        require_privilege(Privilege::ACCOUNT_ADD,account)
+        @cloud_accounts << account unless @pool.cloud_accounts.map{|x| 
x.id}.include?(account.id)
+      rescue
+      end
+    }
+
+  end
+
+end
diff --git a/src/app/controllers/portal_pool_controller.rb 
b/src/app/controllers/portal_pool_controller.rb
index 90df8a5..be9d774 100644
--- a/src/app/controllers/portal_pool_controller.rb
+++ b/src/app/controllers/portal_pool_controller.rb
@@ -66,4 +66,14 @@ class PortalPoolController < ApplicationController
 
   def delete
   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..78b3510
--- /dev/null
+++ b/src/app/views/cloud_accounts/_form.erb
@@ -0,0 +1,13 @@
+<ul>
+  <li>
+    <%= form.label :username, "Choose a username" %>
+    <%= form.text_field :username %>
+  </li>
+  <li>
+    <%= form.label :password, form.object.new_record? ? "Choose a password" : 
"Change 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/accounts_for_pool.html.erb 
b/src/app/views/cloud_accounts/accounts_for_pool.html.erb
new file mode 100644
index 0000000..e273551
--- /dev/null
+++ b/src/app/views/cloud_accounts/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 %>
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/show.html.erb 
b/src/app/views/portal_pool/show.html.erb
index d649199..9d4e36c 100644
--- a/src/app/views/portal_pool/show.html.erb
+++ b/src/app/views/portal_pool/show.html.erb
@@ -35,4 +35,8 @@
     </tbody>
   </table>
 <% end %>
-<%= link_to "Add a new instance", {:controller => "instance", :action => 
"new", :id => @pool}, :class=>"actionlink"%>
+<%= link_to "Add a new instance", {:controller => "instance", :action => 
"new", :id => @pool}, :class=>"actionlink"%><br/>
+<%= link_to "View/Add Existing Cloud Accounts", {:controller => 
"cloud_accounts",:action => "accounts_for_pool", :id => @pool}, 
:class=>"actionlink" %><br/>
+<%= link_to "Add a New Cloud Account", {:controller =>
+"cloud_accounts",:action => "new_from_pool", :id => @pool},
+:class=>"actionlink" %>
-- 
1.6.2.5

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

Reply via email to