From: Tomas Sedovic <[email protected]>

---
 src/app/controllers/cloud_accounts_controller.rb |   53 +++++++++-
 src/app/models/quota.rb                          |    3 +
 src/app/stylesheets/aggregator.scss              |    6 +
 src/app/views/provider/_providers.haml           |    2 +-
 src/app/views/provider/accounts.haml             |  114 +++++++++++++++++----
 src/config/locales/en.yml                        |   14 +++
 6 files changed, 165 insertions(+), 27 deletions(-)

diff --git a/src/app/controllers/cloud_accounts_controller.rb 
b/src/app/controllers/cloud_accounts_controller.rb
index 6fb2398..eeba09f 100644
--- a/src/app/controllers/cloud_accounts_controller.rb
+++ b/src/app/controllers/cloud_accounts_controller.rb
@@ -31,22 +31,29 @@ class CloudAccountsController < ApplicationController
   def create
     @provider = Provider.find(params[:cloud_account][:provider_id])
     require_privilege(Privilege::ACCOUNT_MODIFY,@provider)
+    if not params[:cloud_account][:x509_cert_priv_file].nil?
+      params[:cloud_account][:x509_cert_priv] = 
params[:cloud_account][:x509_cert_priv_file].read
+    end
+    params[:cloud_account].delete :x509_cert_priv_file
+    if not params[:cloud_account][:x509_cert_pub_file].nil?
+      params[:cloud_account][:x509_cert_pub] = 
params[:cloud_account][:x509_cert_pub_file].read
+    end
+    params[:cloud_account].delete :x509_cert_pub_file
     @cloud_account = CloudAccount.new(params[:cloud_account])
     unless @cloud_account.valid_credentials?
       flash[:notice] = "The entered credential information is incorrect"
-      render :action => "new"
+      redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
     else
       quota = Quota.new
+      quota.maximum_total_instances = 
quota_from_string(params[:quota][:maximum_total_instances])
       quota.save!
       @cloud_account.quota_id = quota.id
       @cloud_account.zones << Zone.default
       @cloud_account.save!
       if request.post? && @cloud_account.save && 
@cloud_account.populate_realms_and_images
         flash[:notice] = "Provider account added."
-        redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
-      else
-        render :action => "new"
       end
+      redirect_to :controller => "provider", :action => "accounts", :id => 
@provider
       condormatic_classads_sync
     end
   end
@@ -57,6 +64,34 @@ class CloudAccountsController < ApplicationController
     require_privilege(Privilege::ACCOUNT_MODIFY,@provider)
   end
 
+  def update_accounts
+    params[:cloud_accounts].each do |id, attributes|
+      @cloud_account = CloudAccount.find(id)
+      require_privilege(Privilege::ACCOUNT_MODIFY, @cloud_account.provider)
+
+      # blank password means the user didn't change it -- don't update it then
+      if attributes.has_key? :password and String(attributes[:password]).empty?
+        attributes.delete :password
+      end
+      @cloud_account.quota.maximum_total_instances = 
quota_from_string(params[:quota][id][:maximum_total_instances])
+      private_cert = attributes[:x509_cert_priv]
+      if private_cert.nil?
+        attributes.delete :x509_cert_priv
+      else
+        attributes[:x509_cert_priv] = private_cert.read
+      end
+      public_cert = attributes[:x509_cert_pub]
+      if public_cert.nil?
+        attributes.delete :x509_cert_pub
+      else
+        attributes[:x509_cert_pub] = public_cert.read
+      end
+      @cloud_account.update_attributes!(attributes)
+      @cloud_account.quota.save!
+    end
+    redirect_to :controller => 'provider', :action => 'accounts', :id => 
params[:provider][:id]
+  end
+
   def update
     @cloud_account = CloudAccount.find(params[:cloud_account][:id])
     require_privilege(Privilege::ACCOUNT_MODIFY,@cloud_account.provider)
@@ -88,4 +123,14 @@ class CloudAccountsController < ApplicationController
     end
     redirect_to :controller => 'provider', :action => 'accounts', :id => 
provider.id
   end
+
+  private
+
+  def quota_from_string(quota_raw)
+    if quota_raw.nil? or quota_raw.empty? or quota_raw.downcase == 'unlimited'
+      return nil
+    else
+      return Integer(quota_raw)
+    end
+  end
 end
diff --git a/src/app/models/quota.rb b/src/app/models/quota.rb
index 3bb05b8..87e3a7b 100644
--- a/src/app/models/quota.rb
+++ b/src/app/models/quota.rb
@@ -25,6 +25,9 @@ class Quota < ActiveRecord::Base
   has_one :cloud_account
   has_one :user
 
+  validates_numericality_of :maximum_total_instances, 
:greater_than_or_equal_to => 0, :allow_nil => true
+  validates_numericality_of :maximum_running_instances, 
:greater_than_or_equal_to => 0, :allow_nil => true
+
   QuotaResource = Struct.new(:name, :used, :max, :available, :unit)
 
   NO_LIMIT = nil
diff --git a/src/app/stylesheets/aggregator.scss 
b/src/app/stylesheets/aggregator.scss
index deefb11..059d83d 100644
--- a/src/app/stylesheets/aggregator.scss
+++ b/src/app/stylesheets/aggregator.scss
@@ -398,3 +398,9 @@ footer {
     bottom: 0; left: 0; right: 0;
   }
 }
+
+/* FIXME: this is a temporary fix so that the /provider/accounts/1 page
+fits the screen and is at least semi-usable */
+h3.first, h3.second, h3.third, h3.fourth, h3.fifth, h3.sixth, h3.seventh {
+  display: inline;
+}
diff --git a/src/app/views/provider/_providers.haml 
b/src/app/views/provider/_providers.haml
index 0fc755c..9efd8c4 100644
--- a/src/app/views/provider/_providers.haml
+++ b/src/app/views/provider/_providers.haml
@@ -11,6 +11,6 @@
         %a{ :href => url_for(:controller => 'provider', :action => 'show', :id 
=> provider), :class => selected }
           = provider.name
     - form_tag :controller => 'provider', :action => 'edit', :id => @provider 
do
-      = submit_tag t(:edit), :disabled => ('disabled' unless @provider and 
controller.action_name == 'show')
+      = submit_tag t(:edit), :disabled => ('disabled' unless @provider and 
['show', 'accounts'].include? controller.action_name)
     - form_tag({:controller => 'provider', :action => 'new'}, {:method => :get 
}) do
       %input{ :type => 'submit', :value => t(:add), :disabled => ('disabled' 
unless @providers.length == 0) }
diff --git a/src/app/views/provider/accounts.haml 
b/src/app/views/provider/accounts.haml
index 67d811a..3149962 100644
--- a/src/app/views/provider/accounts.haml
+++ b/src/app/views/provider/accounts.haml
@@ -1,22 +1,92 @@
-- if @provider.cloud_accounts.size == 0
-  %h1 There are no accounts to display
-- else
-  %table
-    %thead
-      %tr
-        %th{:scope => "col"} Label
-        %th{:scope => "col"} Username
-        %th{:scope => "col"} Key
-        %th{:scope => "col"}
-        %th{:scope => "col"}
-    %tbody
-      - @provider.cloud_accounts.each {|acct|
-      %tr
-        %td= acct.label
-        %td= acct.username
-        %td= (acct.instance_key.nil?) ? 'N/A' : 
link_to(acct.instance_key.name, :controller => :cloud_accounts, :action => 
:key, :id => acct.id)
-        %td= link_to "Edit",   {:controller => 'cloud_accounts', :action => 
'edit', :id => acct.id}    if has_account_modify?(@provider)
-        %td= link_to "Delete", {:controller => 'cloud_accounts', :action => 
'destroy', :id => acct.id} if has_account_modify?(@provider) && 
acct.destroyable?
-        %td= link_to "Quota", {:controller => 'quota', :action => 'show', :id 
=> acct.id, :parent_type => "cloud_account"}
-      - }
-= link_to "Add an account", {:controller => "cloud_accounts", :action => 
"new", :provider_id => @provider}, :class => "actionlink"
+:javascript
+  function set_unlimited_quota(elem_id) {
+    $("#" + elem_id)[0].value = "unlimited";
+  }
+= render :partial => 'providers'
+#details.grid_13
+  = render_navigation(:level => 4)
+  - form_tag({:controller => 'cloud_accounts', :action => 'update_accounts'}, 
:multipart => true) do
+    %h2.wider
+      = t('.provider_accounts')
+    %h3.first
+      = t('.account_name')
+      %span.required *
+    %h3.second
+      = t('.user_name')
+      %span.required *
+    %h3.third
+      = t('.password')
+      %span.required *
+    %h3.fourth
+      = t('.quota_instances')
+      %span.required *
+    %h3.fifth
+      = t('.account_number')
+      %span.required *
+    %h3.sixth
+      = t('.account_private_cert')
+      %span.required *
+    %h3.seventh
+      = t('.account_public_cert')
+      %span.required *
+
+    = hidden_field :provider, :id, :value => @provider.id
+    - @provider.cloud_accounts.each do |acct|
+      .fieldGroup.clearfix
+        - disabled = 'disabled' unless has_account_modify?(@provider)
+        - cloud_account_id = "cloud_accounts[#{acct.id}]"
+        = text_field cloud_account_id, :label, :title => t('.account_name'), 
:value => acct.label, :disabled => disabled
+        = text_field cloud_account_id, :username, :title => t('.access_key'), 
:value => acct.username, :disabled => disabled
+        = password_field cloud_account_id, :password, :title => 
t('.secret_access_key'), :disabled => disabled
+        = text_field cloud_account_id, :account_number, :title => 
t('.account_number'), :value => acct.account_number, :disabled => disabled
+        = file_field cloud_account_id, :x509_cert_priv_file, :title => 
t('.account_private_cert'), :disabled => disabled
+        = file_field cloud_account_id, :x509_cert_pub_file, :title => 
t('.account_public_cert'), :disabled => disabled
+        = text_field "quota[#{acct.id}]", :maximum_total_instances, :title => 
t('.quota_instances'), :value => (acct.quota.maximum_total_instances.nil? ? 
"unlimited" : acct.quota.maximum_total_instances), :disabled => disabled, :id 
=> "quota_instances#{acct.id}"
+        - remove_path = url_for :controller => 'cloud_accounts', :action => 
'destroy', :id => acct.id if has_account_modify?(@provider) && acct.destroyable?
+        %a.button{ :href => remove_path, :name => "remove_acc_#{acct.id}", 
:class => ('disabled' unless remove_path) }
+          = t(:remove)
+      .subtext
+        %span
+          (
+          %a{ :href => '' }<>
+            = t('.test_account')
+          )
+        %span
+        %span
+        %span
+          (
+          %a{ :href => '#', :onclick => 
"set_unlimited_quota(\"quota_instances#{acct.id}\");" }<>
+            = t('.unlimited_quota')
+          )
+
+    #prefooter
+      %p.requirement
+        %span.required *
+        \-
+        = t('.required_field')
+      = submit_tag t(:reset), :name => 'reset_form'
+      = submit_tag t(:save), :name => 'update_cloud_accounts'
+  - form_tag({:controller => 'cloud_accounts', :action => 'create'}, 
:multipart => true) do
+    .fieldGroup.clearfix
+      = text_field :cloud_account, :label, :title => t('.account_name')
+      = text_field :cloud_account, :username, :title => t('.access_key')
+      = password_field :cloud_account, :password, :title => 
t('.secret_access_key')
+      = text_field :cloud_account, :account_number, :title => 
t('.account_number')
+      = file_field :cloud_account, :x509_cert_priv_file, :title => 
t('.account_private_cert')
+      = file_field :cloud_account, :x509_cert_pub_file, :title => 
t('.account_public_cert')
+      = text_field :quota, :maximum_total_instances, :title => 
t('.quota_instances'), :id => "new_quota_instances", :value => "unlimited"
+      = hidden_field :cloud_account, :provider_id, :value => @provider.id
+      = submit_tag t(:add)
+    .subtext
+      %span
+        (
+        %a{ :href => '' }<>
+          = t('.test_account')
+        )
+      %span
+      %span
+      %span
+        (
+        %a{ :href => '#', :onclick => 
'set_unlimited_quota("new_quota_instances");' }<>
+          = t('.unlimited_quota')
+        )
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 3e6918c..c24b01a 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -42,6 +42,8 @@ en:
   edit: Edit
   add: Add
   save: Save
+  remove: Remove
+  reset: Reset
   settings:
     index:
       general_settings: General Settings
@@ -68,3 +70,15 @@ en:
       test_connection: Test Connection
       required_field: Required field.
       caution_image: Caution
+    accounts:
+      provider_accounts: Provider Accounts
+      account_name: Account Name
+      user_name: User Name
+      password: Password
+      quota_instances: Quota Instances
+      test_account: Test Account
+      unlimited_quota: Unlimited Quota
+      required_field: Required field.
+      account_number: Account Number
+      account_private_cert: EC2 x509 private key
+      account_public_cert: EC2 x509 public key
-- 
1.7.2.3

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

Reply via email to