incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jprov...@redhat.com
Subject [PATCH aggregator 2/5] image/template controllers and views rework
Date Tue, 14 Sep 2010 15:53:45 GMT
From: Jan Provaznik <jprovazn@redhat.com>

---
 src/app/controllers/image_controller.rb            |    8 ++++-
 .../image_descriptor_target_controller.rb          |    8 ------
 src/app/controllers/instance_controller.rb         |   11 ++++----
 src/app/controllers/templates_controller.rb        |   25 ++++++++++++-------
 src/app/views/cloud_accounts/_form.haml            |   10 ++++++++
 src/app/views/image/_images.haml                   |    7 +----
 src/app/views/instance/_instances.haml             |    2 +-
 src/app/views/instance/new.haml                    |   14 +++++-----
 src/app/views/instance/select_image.haml           |    5 ----
 src/app/views/instance/select_template.haml        |    5 ++++
 src/app/views/templates/_targets.haml              |   14 +++++-----
 src/app/views/templates/_templates.haml            |   18 ++++++++++++++
 src/app/views/templates/software.haml              |    2 +-
 13 files changed, 79 insertions(+), 50 deletions(-)
 delete mode 100644 src/app/controllers/image_descriptor_target_controller.rb
 delete mode 100644 src/app/views/instance/select_image.haml
 create mode 100644 src/app/views/instance/select_template.haml
 create mode 100644 src/app/views/templates/_templates.haml

diff --git a/src/app/controllers/image_controller.rb b/src/app/controllers/image_controller.rb
index b75f692..e399225 100644
--- a/src/app/controllers/image_controller.rb
+++ b/src/app/controllers/image_controller.rb
@@ -25,6 +25,11 @@ class ImageController < ApplicationController
   def index
   end
 
+  def cancel
+    Image.update(params[:id], :status => Image::STATE_CANCELED)
+    redirect_to :controller => 'templates', :action => 'new', :params => {'image_descriptor[id]'
=> params[:template_id], :tab => 'software'}
+  end
+
   def show
     if params[:create_instance]
       redirect_to :controller => 'instance', :action => 'new', 'instance[image_id]'
=> (params[:ids] || []).first
@@ -37,8 +42,7 @@ class ImageController < ApplicationController
     @images = Image.search_filter(params[:search], Image::SEARCHABLE_COLUMNS).paginate(
       :page => params[:page] || 1,
       :order => @order + ' ' + @order_dir,
-      :include => :instances,
-      :conditions => {:provider_id => nil}
+      :include => :instances
     )
 
     if request.xhr? and params[:partial]
diff --git a/src/app/controllers/image_descriptor_target_controller.rb b/src/app/controllers/image_descriptor_target_controller.rb
deleted file mode 100644
index 6f01018..0000000
--- a/src/app/controllers/image_descriptor_target_controller.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-class ImageDescriptorTargetController < ApplicationController
-  before_filter :require_user
-
-  def cancel
-    ImageDescriptorTarget.update(params[:id], :status => ImageDescriptorTarget::STATE_CANCELED)
-    redirect_to :controller => 'templates', :action => 'new', :params => {'image_descriptor[id]'
=> params[:descriptor_id], :tab => 'software'}
-  end
-end
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb
index e2a1eaf..93b413e 100644
--- a/src/app/controllers/instance_controller.rb
+++ b/src/app/controllers/instance_controller.rb
@@ -48,23 +48,24 @@ class InstanceController < ApplicationController
     end
   end
 
-  def select_image
+  def select_template
     if params[:select]
-      redirect_to :action => 'new', 'instance[image_id]' => (params[:ids] || []).first
+      redirect_to :action => 'new', 'instance[template_id]' => (params[:ids] || []).first
     end
 
+    # FIXME: replace by template_view priv
     require_privilege(Privilege::IMAGE_VIEW)
     @order_dir = params[:order_dir] == 'desc' ? 'desc' : 'asc'
     @order = params[:order] || 'name'
-    @images = Image.search_filter(params[:search], Image::SEARCHABLE_COLUMNS).paginate(
+    @templates = Template.paginate(
       :page => params[:page] || 1,
       :order => @order + ' ' + @order_dir,
-      :conditions => {:provider_id => nil}
+      :conditions => {:complete => true}
     )
     @single_select = true
 
     if request.xhr? and params[:partial]
-      render :partial => 'image/images'
+      render :partial => 'templates/templates'
       return
     end
   end
diff --git a/src/app/controllers/templates_controller.rb b/src/app/controllers/templates_controller.rb
index c701486..7ba1658 100644
--- a/src/app/controllers/templates_controller.rb
+++ b/src/app/controllers/templates_controller.rb
@@ -38,7 +38,7 @@ class TemplatesController < ApplicationController
 
   def software
     @repository_manager = RepositoryManager.new
-    @image_descriptor = params[:id] ? ImageDescriptor.find(params[:id]) : ImageDescriptor.new
+    @image_descriptor = params[:id] ? Template.find(params[:id]) : Template.new
     @groups = @repository_manager.all_groups(params[:repository])
     if params[:tab].to_s == 'packages'
       @selected_tab = 'packages'
@@ -57,33 +57,40 @@ class TemplatesController < ApplicationController
     if params[:back]
       redirect_to :action => 'services', :id => @image_descriptor
     elsif params[:next]
+      # template is complete, upload it
+      @image_descriptor.upload_template
+      @image_descriptor.update_attribute(:complete, true)
       redirect_to :action => 'summary', :id => @image_descriptor
     end
   end
 
   def summary
     update_xml
-    @all_targets = ImageDescriptorTarget.available_targets
+    @all_targets = Image.available_targets
     if params[:build]
       if params[:targets]
         params[:targets].each do |target|
-          ImageDescriptorTarget.new_if_not_exists(:name => target, :image_descriptor_id
=> params[:id], :status => ImageDescriptorTarget::STATE_QUEUED)
+          # TODO: support versioning
+          Image.new_if_not_exists(
+            :name => "#{@image_descriptor.xml.name}/#{target}",
+            :target => target,
+            :template_id => params[:id],
+            :status => Image::STATE_QUEUED
+          )
         end
       end
     else
       if params[:back]
         redirect_to :action => 'software', :id => @image_descriptor
       elsif params[:done]
-        @image_descriptor.complete = true
-        @image_descriptor.save!
         redirect_to :controller => 'dashboard', :action => 'index'
       end
     end
   end
 
   def targets
-    @image_descriptor = ImageDescriptor.find(params[:id])
-    @all_targets = ImageDescriptorTarget.available_targets
+    @image_descriptor = Template.find(params[:id])
+    @all_targets = Image.available_targets
   end
 
   def select_group
@@ -113,7 +120,7 @@ class TemplatesController < ApplicationController
   end
 
   def update_group_or_package(method, *args)
-    @image_descriptor = params[:id] ? ImageDescriptor.find(params[:id]) : ImageDescriptor.new
+    @image_descriptor = params[:id] ? Template.find(params[:id]) : Template.new
     @image_descriptor.xml.send(method, *args)
     @image_descriptor.save_xml!
     if request.xhr?
@@ -124,7 +131,7 @@ class TemplatesController < ApplicationController
   end
 
   def update_xml
-    @image_descriptor = params[:id] ? ImageDescriptor.find(params[:id]) : ImageDescriptor.new
+    @image_descriptor = params[:id] ? Template.find(params[:id]) : Template.new
     @image_descriptor.update_xml_attributes!(params[:xml] || {})
   end
 
diff --git a/src/app/views/cloud_accounts/_form.haml b/src/app/views/cloud_accounts/_form.haml
index 42960b3..1864591 100644
--- a/src/app/views/cloud_accounts/_form.haml
+++ b/src/app/views/cloud_accounts/_form.haml
@@ -19,4 +19,14 @@
         Password
         %span Password for the provider account you wish to add.
       = password_field :cloud_account, :password
+    %li
+      %label
+        Account number
+        %span EC2 account number.
+      = text_field :cloud_account, :account_number
+    %li
+      %label
+        Account certificate
+        %span EC2 x509 certificate.
+      = text_area :cloud_account, :x509_cert
 = submit_tag "Save", :class => "submit"
diff --git a/src/app/views/image/_images.haml b/src/app/views/image/_images.haml
index 4dfeaa0..d37f1d3 100644
--- a/src/app/views/image/_images.haml
+++ b/src/app/views/image/_images.haml
@@ -1,8 +1,6 @@
 - columns = [                                                               |
   {:id => 'id', :header => ''},                                             |
   {:id => 'name', :header => 'Name', :sortable => true},                    |
-  {:id => 'architecture', :header => 'Architecture', :sortable => true},    |
-  {:id => 'instances', :header => 'Instances'},                             |
 ]                                                                           |
 
 - opts = { :order => @order,
@@ -16,6 +14,5 @@
 = paginated_table('images_table', columns, @images, opts) do |rec|
   %tr{:class => "#{cycle('even', 'odd')}"}
     %td= check_box_tag 'ids[]', rec.id
-    %td{:class => 'image_name'}= rec.name
-    %td= rec.architecture
-    %td= rec.instances.count
+    %td{:class => 'image_name'}= rec.image.name
+    /%td= rec.instances.count
diff --git a/src/app/views/instance/_instances.haml b/src/app/views/instance/_instances.haml
index 391bdba..b0f4692 100644
--- a/src/app/views/instance/_instances.haml
+++ b/src/app/views/instance/_instances.haml
@@ -19,6 +19,6 @@
     %td= rec.get_action_list.map {|action| link_to action, :controller => "instance",
:action => "instance_action", :id => rec, :instance_action => action}.join(" | ")
     %td= rec.name
     %td Details
-    %td= rec.image.name
+    %td= rec.template.name
     %td= rec.state
     %td= rec.time_last_running
diff --git a/src/app/views/instance/new.haml b/src/app/views/instance/new.haml
index d797d57..7942036 100644
--- a/src/app/views/instance/new.haml
+++ b/src/app/views/instance/new.haml
@@ -1,6 +1,6 @@
 :javascript
   $(document).ready(function() {
-    $(".select_image").click(function() {
+    $(".select_template").click(function() {
       var wrapper = $("#select_template_dialog");
       if (wrapper.length == 0) wrapper = $('<div id="select_template_dialog"></div>');
       wrapper.dialog({
@@ -10,14 +10,14 @@
         modal: true,
         overlay: {opacity: 0.2, background: "black"}
       });
-      wrapper.load('#{url_for :action => 'select_image'}', null, function() {
+      wrapper.load('#{url_for :action => 'select_template'}', null, function() {
         $(":submit[name=select]").click(function() {
           var checkbox = $("input[name='ids[]']:checked").first();
           var id = checkbox.val();
           if (id !== undefined) {
-            var name = $(".image_name", checkbox.parent().parent()).text();
-            $(".select_image").text(name);
-            $("input[name='instance[image_id]']").val(id);
+            var name = $(".template_name", checkbox.parent().parent()).text();
+            $(".select_template").text(name);
+            $("input[name='instance[template_id]']").val(id);
           }
           $("#select_template_dialog").dialog('close');
           return false;
@@ -45,8 +45,8 @@
         %label
           Template
           %span Choose a template to use
-        = link_to(@instance.image ? @instance.image.name : "Select template...", {:action
=> 'select_image'}, {:class => 'actionlink select_image'})
-    %input{:name => "instance[image_id]", :type => "hidden", :value => @instance.image
? @instance.image.id : ''}/
+        = link_to(@instance.template ? @instance.template.name : "Select template...", {:action
=> 'select_template'}, {:class => 'actionlink select_template'})
+    %input{:name => "instance[template_id]", :type => "hidden", :value => @instance.template
? @instance.template.id : ''}/
     - if @instance.pool
       %input{:name => "instance[pool_id]", :type => "hidden", :value => @instance.pool_id}/
     - if (@pools.size > 1)
diff --git a/src/app/views/instance/select_image.haml b/src/app/views/instance/select_image.haml
deleted file mode 100644
index 48fef83..0000000
--- a/src/app/views/instance/select_image.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-- buttons = capture_haml do
-  .action_buttons
-    = submit_tag "Select", :name => "select"
-
-= render :partial => 'image/images', :locals => {:footer => buttons}
diff --git a/src/app/views/instance/select_template.haml b/src/app/views/instance/select_template.haml
new file mode 100644
index 0000000..b1739cf
--- /dev/null
+++ b/src/app/views/instance/select_template.haml
@@ -0,0 +1,5 @@
+- buttons = capture_haml do
+  .action_buttons
+    = submit_tag "Select", :name => "select"
+
+= render :partial => 'templates/templates', :locals => {:footer => buttons}
diff --git a/src/app/views/templates/_targets.haml b/src/app/views/templates/_targets.haml
index 1b242e1..ba8f7f1 100644
--- a/src/app/views/templates/_targets.haml
+++ b/src/app/views/templates/_targets.haml
@@ -1,18 +1,18 @@
 #image_target_list{:class => 'target_list'}
-  - if @image_descriptor.image_descriptor_targets.empty?
+  - if @image_descriptor.images.empty?
     .empty No images have been created yet.
   -else
     %ul
-      - @image_descriptor.image_descriptor_targets.each do |target|
+      - @image_descriptor.images.each do |image|
         %li
           %span{:class => 'actions'}
             &nbsp;
-            - if ImageDescriptorTarget::ACTIVE_STATES.include?(target.status)
-              = link_to 'Cancel', {:controller => 'image_descriptor_target', :action =>
'cancel', :id => target, :descriptor_id => @image_descriptor}
+            - if Image::ACTIVE_STATES.include?(image.status)
+              = link_to 'Cancel', {:controller => 'image', :action => 'cancel', :id
=> image, :template_id => @image_descriptor}
           %span{:class => 'status'}
-            = target.status
-          = @all_targets[target.name]['name']
+            = image.status
+          = @all_targets[image.target]['name']
           %p
-            = target.created_at
+            = image.created_at
           //%span{:style => 'float:right'}
           //  Cancel
diff --git a/src/app/views/templates/_templates.haml b/src/app/views/templates/_templates.haml
new file mode 100644
index 0000000..e075c2e
--- /dev/null
+++ b/src/app/views/templates/_templates.haml
@@ -0,0 +1,18 @@
+- columns = [                                                               |
+  {:id => 'id', :header => ''},                                             |
+  {:id => 'name', :header => 'Name', :sortable => true},                    |
+]                                                                           |
+
+- opts = { :order => @order,
+  :order_dir => @order_dir,
+  :title => 'list of templates',
+  :check_all => 'id',
+  :header => defined?(header) ? header : nil,
+  :footer => defined?(footer) ? footer : nil,
+  :single_select => @single_select || false }
+
+= paginated_table('templates_table', columns, @templates, opts) do |rec|
+  %tr{:class => "#{cycle('even', 'odd')}"}
+    %td= check_box_tag 'ids[]', rec.id
+    %td{:class => 'template_name'}= rec.name
+    /%td= rec.instances.count
diff --git a/src/app/views/templates/software.haml b/src/app/views/templates/software.haml
index 998ce9b..9d11b5e 100644
--- a/src/app/views/templates/software.haml
+++ b/src/app/views/templates/software.haml
@@ -82,7 +82,7 @@
               %li{ :class => "#{selection_style} ui-state-default ui-corner-top", :style
=> 'clear: none' }
                 = "<a href=\"#{url_for(:action => "software", :id => @image_descriptor,
:tab => item[:tab])}\"><span>#{item[:text]}</span></a>"
             %li{ :class => "select_repository"}
-              = select_tag("repository", ["<option value='all' selected='selected'>All</option>"]
+ @repository_manager.repositories.map{|repid, rep| "<option value=\"#{repid}\">#{rep['name']}</option>"},
{:onchange => "get_repository(event)"})
+              = select_tag("repository", ["<option value='all' selected='selected'>All</option>"]
+ @repository_manager.repositories.map{|rep| "<option value=\"#{rep.id}\">#{rep.name}</option>"},
{:onchange => "get_repository(event)"})
           - unless request.xhr?
             = render :partial => @selected_tab
       .pkglist{:style => "margin-left: 30px", :class => "left-pkglist"}
-- 
1.7.2.2


Mime
View raw message