You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/11/29 14:16:56 UTC

[PATCH core 4/6] Fixed storage_volumes and storage_snapshots collections for EC2

From: Michal Fojtik <mf...@redhat.com>

---
 .../lib/deltacloud/helpers/application_helper.rb   |    7 +++++--
 server/views/storage_snapshots/index.html.haml     |    3 +++
 server/views/storage_snapshots/new.html.haml       |    9 +++++++++
 server/views/storage_volumes/attach.html.haml      |   20 ++++++++++++++++++++
 server/views/storage_volumes/index.html.haml       |   17 ++++++++++++++++-
 server/views/storage_volumes/index.xml.haml        |   11 +----------
 server/views/storage_volumes/new.html.haml         |   17 +++++++++++++++++
 server/views/storage_volumes/show.xml.haml         |    9 ++++++++-
 8 files changed, 79 insertions(+), 14 deletions(-)
 create mode 100644 server/views/storage_snapshots/new.html.haml
 create mode 100644 server/views/storage_volumes/attach.html.haml
 create mode 100644 server/views/storage_volumes/new.html.haml

diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb
index f538714..b2f9901 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -38,7 +38,11 @@ module ApplicationHelper
   end
 
   def instance_action_method(action)
-    collections[:instances].operations[action.to_sym].method
+    action_method(action, :instances)
+  end
+
+  def action_method(action, collection)
+    collections[collection].operations[action.to_sym].method
   end
 
   def driver_has_feature?(feature_name, collection_name = :instances)
@@ -131,7 +135,6 @@ module ApplicationHelper
   end
 
   def link_to_action(action, url, method)
-    return link_to(action, url) if method.eql? :get
     capture_haml do
       haml_tag :form, :method => :post, :action => url, :class => :link do
         haml_tag :input, :type => :hidden, :name => '_method', :value => method
diff --git a/server/views/storage_snapshots/index.html.haml b/server/views/storage_snapshots/index.html.haml
index e3671ec..e27eb04 100644
--- a/server/views/storage_snapshots/index.html.haml
+++ b/server/views/storage_snapshots/index.html.haml
@@ -7,6 +7,7 @@
       %th Volume
       %th Created
       %th State
+      %th Actions
   %tbody
     - @storage_snapshots.each do |snapshot|
       %tr
@@ -18,3 +19,5 @@
           = snapshot.created
         %td
           = snapshot.state
+        %td
+          = link_to_action "Delete", destroy_storage_snapshot_url(snapshot.id), :delete
diff --git a/server/views/storage_snapshots/new.html.haml b/server/views/storage_snapshots/new.html.haml
new file mode 100644
index 0000000..8e7d6f8
--- /dev/null
+++ b/server/views/storage_snapshots/new.html.haml
@@ -0,0 +1,9 @@
+%h1 Create new storage volume snapshot
+
+%form{ :action => '/api/storage_snapshots', :method => :post }
+  %p
+    %label
+      Volume ID:
+    %input{ :name => 'volume_id', :size => 30, :value => params[:volume_id] }
+  %p
+    %input{ :type => :submit, :name => "commit", :value => "create" }/
diff --git a/server/views/storage_volumes/attach.html.haml b/server/views/storage_volumes/attach.html.haml
new file mode 100644
index 0000000..2408cd9
--- /dev/null
+++ b/server/views/storage_volumes/attach.html.haml
@@ -0,0 +1,20 @@
+%h1 Attach storage volume
+
+%form{ :action => attach_storage_volume_url(params[:id]), :method => :post }
+  %p
+    %label
+      Instance ID:
+    - if @instances.empty?
+      %select
+        %option There are no instances
+    - else
+      %select{ :name => 'instance_id' }
+        - @instances.each do |i|
+          %option{ :value => "#{i.id}"} #{i.name}
+  %p
+    %label
+      Device name:
+    %input{ :name => "device", :size => 10, :value => "/dev/sdc"}
+  %p
+    %input{ :type => :hidden, :name => :id, :value => params[:id]}
+    %input{ :type => :submit, :name => "commit", :value => "create" }/
diff --git a/server/views/storage_volumes/index.html.haml b/server/views/storage_volumes/index.html.haml
index bd55edd..6f116fd 100644
--- a/server/views/storage_volumes/index.html.haml
+++ b/server/views/storage_volumes/index.html.haml
@@ -5,8 +5,10 @@
     %tr
       %th ID
       %th Created
+      %th Realm
       %th Capacity
       %th Status
+      %th Actions
   %tbody
     - @storage_volumes.each do |volume|
       %tr
@@ -15,7 +17,20 @@
         %td
           = volume.created
         %td
+          = volume.realm_id
+        %td
           = "#{volume.capacity} GB"
         %td
           = "#{volume.state}"
-
+        %td
+          - if ["AVAILABLE", "IN-USE"].include?(volume.state)
+            =link_to_action "Snaphot", url_for("/api/storage_snapshots/new?volume_id=#{volume.id}"), :get
+            - unless volume.instance_id
+              =link_to_action "Delete", destroy_storage_volume_url(volume.id), :delete
+              =link_to_action "Attach", url_for("/api/storage_volumes/attach?id=#{volume.id}"), :get
+            - if volume.instance_id
+              =link_to_action "Detach", detach_storage_volume_url(volume.id), :post
+  %tfoot
+    %tr
+      %td{:colspan => 6}
+        %a{ :href => url_for("/api/storage_volumes/new")} Create volume
diff --git a/server/views/storage_volumes/index.xml.haml b/server/views/storage_volumes/index.xml.haml
index 471169c..e73c46a 100644
--- a/server/views/storage_volumes/index.xml.haml
+++ b/server/views/storage_volumes/index.xml.haml
@@ -1,13 +1,4 @@
 !!!XML
 %storage_volumes
   - @elements.each do |volume|
-    %storage_volume{ :href => storage_volume_url(volume.id), :id => volume.id }
-      %created<
-        =volume.created
-      %capacity{ :unit => "GB" }<
-        = volume.capacity
-      - unless volume.instance_id.nil?
-        %mount
-          %instance{:href => instance_url(volume.instance_id), :id => volume.instance_id}
-          - unless volume.device.nil?
-            %device{ :name => volume.device }
+    = haml :'storage_volumes/show', :locals =>  { :@storage_volume =>  volume, :partial =>  true } 
diff --git a/server/views/storage_volumes/new.html.haml b/server/views/storage_volumes/new.html.haml
new file mode 100644
index 0000000..f8ab6b8
--- /dev/null
+++ b/server/views/storage_volumes/new.html.haml
@@ -0,0 +1,17 @@
+%h1 Create new storage volume
+
+%form{ :action => '/api/storage_volumes', :method => :post }
+  %p
+    %label
+      Snapshot ID:
+    %input{ :name => 'snapshot_id', :size => 30 } (optional)
+  %p
+    %label
+      Capacity (in GB):
+    %input{ :name => "capacity", :size => 3, :value => "1"}
+  %p
+    %label
+      Realm ID:
+    %input{ :name => "realm_id", :size => 10, :value => driver.realms(credentials).first.id}
+  %p
+    %input{ :type => :submit, :name => "commit", :value => "create" }/
diff --git a/server/views/storage_volumes/show.xml.haml b/server/views/storage_volumes/show.xml.haml
index ebf1b24..0a89192 100644
--- a/server/views/storage_volumes/show.xml.haml
+++ b/server/views/storage_volumes/show.xml.haml
@@ -1,11 +1,18 @@
-!!!XML
+- unless defined?(partial)
+  !!!XML
 %storage_volume{ :href => storage_volume_url(@storage_volume.id), :id => @storage_volume.id}
   %created<
     =@storage_volume.created
   %capacity{ :unit => "GB" }<
     = @storage_volume.capacity
+  %state<
+    = @storage_volume.state
   - unless @storage_volume.instance_id.nil?
     %mount
       %instance{:href => @storage_volume.instance_id, :id => @storage_volume.instance_id}
       - unless @storage_volume.device.nil?
         %device{ :name => @storage_volume.device }
+  - if @storage_volume.actions
+    %actions
+      - @storage_volume.actions.each do |action|
+        %link{:rel => action, :method => action_method(action, :storage_volumes), :href => self.send("#{action}_storage_volume_url", @storage_volume.id)}
-- 
1.7.3.2