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/12 16:02:09 UTC

[PATCH core 4/5] Added support for managing storage_volumes and storage_snapshots in EC2

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

---
 server/lib/deltacloud/models/storage_volume.rb |    1 +
 server/server.rb                               |   88 ++++++++++++++++++++++++
 server/views/storage_snapshots/index.html.haml |    3 +
 server/views/storage_snapshots/new.html.haml   |    9 +++
 server/views/storage_volumes/attach.html.erb   |   17 +++++
 server/views/storage_volumes/attach.html.haml  |   14 ++++
 server/views/storage_volumes/attach.html.html  |   17 +++++
 server/views/storage_volumes/index.html.haml   |   12 +++
 server/views/storage_volumes/new.html.haml     |   17 +++++
 9 files changed, 178 insertions(+), 0 deletions(-)
 create mode 100644 server/views/storage_snapshots/new.html.haml
 create mode 100644 server/views/storage_volumes/attach.html.erb
 create mode 100644 server/views/storage_volumes/attach.html.haml
 create mode 100644 server/views/storage_volumes/attach.html.html
 create mode 100644 server/views/storage_volumes/new.html.haml

diff --git a/server/lib/deltacloud/models/storage_volume.rb b/server/lib/deltacloud/models/storage_volume.rb
index 5e9e948..2f379da 100644
--- a/server/lib/deltacloud/models/storage_volume.rb
+++ b/server/lib/deltacloud/models/storage_volume.rb
@@ -23,6 +23,7 @@ class StorageVolume < BaseModel
   attr_accessor :state
   attr_accessor :capacity
   attr_accessor :instance_id
+  attr_accessor :realm_id
   attr_accessor :device
 
 end
diff --git a/server/server.rb b/server/server.rb
index 5ccf9f6..424daab 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -373,6 +373,12 @@ END
 
 end
 
+get '/api/storage_snapshots/new' do
+  respond_to do |format|
+    format.html { haml :"storage_snapshots/new" }
+  end
+end
+
 collection :storage_snapshots do
   description "Storage snapshots description here"
 
@@ -389,6 +395,38 @@ collection :storage_snapshots do
     param :id,          :string,    :required
     control { show(:storage_snapshot) }
   end
+
+  operation :create do
+    description "Create a new snapshot from volume"
+    with_capability :create_storage_snapshot
+    param :volume_id, :string,  :required
+    control do
+      @storage_snapshot = driver.create_storage_snapshot(credentials, params)
+      show(:storage_snapshot)
+    end
+  end
+
+  operation :destroy do
+    description "Delete storage snapshot"
+    with_capability :destroy_storage_snapshot
+    param :id,  :string,  :required
+    control do
+      driver.create_storage_snapshot(credentials, params)
+      redirect(storage_snapshot_url(params[:id]))
+    end
+  end
+end
+
+get '/api/storage_volumes/new' do
+  respond_to do |format|
+    format.html { haml :"storage_volumes/new" }
+  end
+end
+
+get '/api/storage_volumes/attach' do
+  respond_to do |format|
+    format.html { haml :"storage_volumes/attach" }
+  end
 end
 
 collection :storage_volumes do
@@ -407,6 +445,56 @@ collection :storage_volumes do
     param :id,          :string,    :required
     control { show(:storage_volume) }
   end
+
+  operation :create do
+    description "Create a new storage volume"
+    with_capability :create_storage_volume
+    param :snapshot_id, :string,  :optional
+    param :size,        :string,  :optional
+    param :zone,        :string,  :optional
+    control do
+      @storage_volume = driver.create_storage_volume(credentials, params)
+      respond_to do |format|
+        format.html { haml :"storage_volumes/show" }
+        format.xml { haml :"storage_volumes/show" }
+      end
+    end
+  end
+
+  operation :attach, :method => :post, :member => true do
+    description "Attach storage volume to instance"
+    with_capability :attach_storage_volume
+    param :id,         :string,  :required
+    param :instance_id,:string,  :required
+    param :device,     :string,  :required
+    control do
+      driver.attach_storage_volume(credentials, params)
+      redirect(storage_volume_url(params[:id]))
+    end
+  end
+
+  operation :detach, :method => :post, :member => true do
+    description "Detach storage volume to instance"
+    with_capability :detach_storage_volume
+    param :id,         :string,  :required
+    control do
+      volume = driver.storage_volume(credentials, :id => params[:id])
+      driver.detach_storage_volume(credentials, :id => volume.id, :instance_id => volume.instance_id, 
+                                   :device => volume.device)
+      redirect(storage_volume_url(params[:id]))
+    end
+  end
+
+  operation :destroy do
+    description "Destroy storage volume"
+    with_capability :destroy_storage_volume
+    param :id,          :string,  :optional
+    control do
+      driver.destroy_storage_volume(credentials, params)
+      redirect(storage_volumes_url)
+    end
+  end
+
 end
 
 get '/api/keys/new' do
diff --git a/server/views/storage_snapshots/index.html.haml b/server/views/storage_snapshots/index.html.haml
index e3671ec..5eb786e 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 "Destroy", destroy_storage_snapshot_url(snapshot.id), :class => :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.erb b/server/views/storage_volumes/attach.html.erb
new file mode 100644
index 0000000..e2ad667
--- /dev/null
+++ b/server/views/storage_volumes/attach.html.erb
@@ -0,0 +1,17 @@
+%h1 Attach storage volume
+
+%form{ :action => attach_storage_volume(params[:id]), :method => :post }
+  %p
+    %label
+      Snapshot ID:
+    %input{ :name => 'snapshot_id', :size => 30 } (optional)
+  %p
+    %label
+      Size (in GB):
+    %input{ :name => "size", :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/attach.html.haml b/server/views/storage_volumes/attach.html.haml
new file mode 100644
index 0000000..ec8eb66
--- /dev/null
+++ b/server/views/storage_volumes/attach.html.haml
@@ -0,0 +1,14 @@
+%h1 Attach storage volume
+
+%form{ :action => attach_storage_volume_url(params[:id]), :method => :post }
+  %p
+    %label
+      Instance ID:
+    %input{ :name => 'instance_id', :size => 30 }
+  %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/attach.html.html b/server/views/storage_volumes/attach.html.html
new file mode 100644
index 0000000..e2ad667
--- /dev/null
+++ b/server/views/storage_volumes/attach.html.html
@@ -0,0 +1,17 @@
+%h1 Attach storage volume
+
+%form{ :action => attach_storage_volume(params[:id]), :method => :post }
+  %p
+    %label
+      Snapshot ID:
+    %input{ :name => 'snapshot_id', :size => 30 } (optional)
+  %p
+    %label
+      Size (in GB):
+    %input{ :name => "size", :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/index.html.haml b/server/views/storage_volumes/index.html.haml
index bd55edd..3199a19 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,17 @@
         %td
           = volume.created
         %td
+          = volume.realm_id
+        %td
           = "#{volume.capacity} GB"
         %td
           = "#{volume.state}"
+        %td
+          - if ["AVAILABLE", "IN-USE"].include?(volume.state)
+            =link_to "Snaphot", url_for("/api/storage_snapshots/new?volume_id=#{volume.id}")
+            - unless volume.instance_id
+              =link_to "Delete", destroy_storage_volume_url(volume.id), :class => :delete
+              =link_to "Attach", url_for("/api/storage_volumes/attach?id=#{volume.id}")
+            - if volume.instance_id
+              =link_to "Detach", detach_storage_volume_url(volume.id), :class => :post
 
diff --git a/server/views/storage_volumes/new.html.haml b/server/views/storage_volumes/new.html.haml
new file mode 100644
index 0000000..66bf015
--- /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
+      Size (in GB):
+    %input{ :name => "size", :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" }/
-- 
1.7.3.2