[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] [Patch] add support for NFS storage pools/volumes to WUI



This patch adds support for NFS storage pools and volumes to the Ovirt WUI. Taskomatic work is still needed to correspond to these changes -- mainly for handling NFS stuff, but also for previous iSCSI code to properly set the :type attribute for storage volumes now.


diff --git a/wui/src/app/controllers/storage_controller.rb b/wui/src/app/controllers/storage_controller.rb
index 8cc17d6..7a2f270 100644
--- a/wui/src/app/controllers/storage_controller.rb
+++ b/wui/src/app/controllers/storage_controller.rb
@@ -186,9 +186,11 @@ class StorageController < ApplicationController
   end
 
   def pre_new2
-    @storage_pool = StoragePool.factory(params[:storage_type], 
-                                        { :hardware_pool_id => params[:hardware_pool_id],
-                                          :port => 3260})
+    new_params = { :hardware_pool_id => params[:hardware_pool_id]}
+    if (params[:storage_type] == "iSCSI")
+      new_params[:port] = 3260
+    end
+    @storage_pool = StoragePool.factory(params[:storage_type], new_params)
     @perm_obj = @storage_pool.hardware_pool
     @redir_controller = @storage_pool.hardware_pool.get_controller
     authorize_admin
diff --git a/wui/src/app/models/iscsi_storage_pool.rb b/wui/src/app/models/iscsi_storage_pool.rb
index ec16ab6..8164e7c 100644
--- a/wui/src/app/models/iscsi_storage_pool.rb
+++ b/wui/src/app/models/iscsi_storage_pool.rb
@@ -18,5 +18,7 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
 class IscsiStoragePool < StoragePool
-
+  def label_components
+    "#{target}"
+  end
 end
diff --git a/wui/src/app/models/iscsi_storage_volume.rb b/wui/src/app/models/iscsi_storage_volume.rb
new file mode 100644
index 0000000..b254cd8
--- /dev/null
+++ b/wui/src/app/models/iscsi_storage_volume.rb
@@ -0,0 +1,24 @@
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Scott Seago <sseago redhat com>
+#
+# 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.
+
+class IscsiStorageVolume < StorageVolume
+  def label_components
+    "#{storage_pool[:target]}:#{lun}"
+  end
+end
diff --git a/wui/src/app/models/nfs_storage_pool.rb b/wui/src/app/models/nfs_storage_pool.rb
new file mode 100644
index 0000000..30608cd
--- /dev/null
+++ b/wui/src/app/models/nfs_storage_pool.rb
@@ -0,0 +1,24 @@
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Scott Seago <sseago redhat com>
+#
+# 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.
+
+class NfsStoragePool < StoragePool
+  def label_components
+    "#{export_path}"
+  end
+end
diff --git a/wui/src/app/models/nfs_storage_volume.rb b/wui/src/app/models/nfs_storage_volume.rb
new file mode 100644
index 0000000..f220930
--- /dev/null
+++ b/wui/src/app/models/nfs_storage_volume.rb
@@ -0,0 +1,24 @@
+# 
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Scott Seago <sseago redhat com>
+#
+# 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.
+
+class NfsStorageVolume < StorageVolume
+  def label_components
+    "#{storage_pool.export_path}/#{filename}"
+  end
+end
diff --git a/wui/src/app/models/storage_pool.rb b/wui/src/app/models/storage_pool.rb
index 8bedcc8..06c4b07 100644
--- a/wui/src/app/models/storage_pool.rb
+++ b/wui/src/app/models/storage_pool.rb
@@ -26,23 +26,28 @@ class StoragePool < ActiveRecord::Base
     end
   end
 
-  STORAGE_TYPES = { "iSCSI" => "IscsiStoragePool" }
+  ISCSI = "iSCSI"
+  NFS   = "NFS"
+  STORAGE_TYPES = { ISCSI => "Iscsi",
+                    NFS   => "Nfs" }
 
   def self.factory(type, params = nil)
     case type
-    when "iSCSI"
+    when ISCSI
       return IscsiStoragePool.new(params)
+    when NFS
+      return NfsStoragePool.new(params)
     else
       return nil
     end
   end
 
   def display_name
-    "#{get_type_label}#{ip_addr}:#{target}"
+    "#{get_type_label}: #{ip_addr}:#{label_components}"
   end
 
   def get_type_label
-    STORAGE_TYPES.invert[self.class.name]
+    STORAGE_TYPES.invert[self.class.name.gsub("StoragePool", "")]
   end
 
   def tasks
diff --git a/wui/src/app/models/storage_volume.rb b/wui/src/app/models/storage_volume.rb
index 9679a02..cdcc681 100644
--- a/wui/src/app/models/storage_volume.rb
+++ b/wui/src/app/models/storage_volume.rb
@@ -23,8 +23,23 @@ class StorageVolume < ActiveRecord::Base
   belongs_to              :storage_pool
   has_and_belongs_to_many :vms
 
+  def self.factory(type, params = nil)
+    case type
+    when "iSCSI"
+      return IscsiStoragePool.new(params)
+    when "NFS"
+      return NfsStoragePool.new(params)
+    else
+      return nil
+    end
+  end
+
+  def get_type_label
+    StoragePool::STORAGE_TYPES.invert[self.class.name.gsub("StorageVolume", "")]
+  end
+
   def display_name
-    "#{storage_pool.ip_addr}:#{storage_pool[:target]}:#{lun}"
+    "#{get_type_label}: #{storage_pool.ip_addr}:#{label_components}"
   end
 
   def size_in_gb
diff --git a/wui/src/app/views/storage/_form.rhtml b/wui/src/app/views/storage/_form.rhtml
index e5086f9..d11c787 100644
--- a/wui/src/app/views/storage/_form.rhtml
+++ b/wui/src/app/views/storage/_form.rhtml
@@ -6,9 +6,11 @@
 
 <%= text_field_with_label "IP Address", 'storage_pool', 'ip_addr'  %>
 
-<%= text_field_with_label "Port", 'storage_pool', 'port'  %>
+<%= text_field_with_label "Port", 'storage_pool', 'port' if @storage_pool[:type] == "IscsiStoragePool" %>
 
-<%= text_field_with_label "Target", 'storage_pool', 'target'  %>
+<%= text_field_with_label "Target", 'storage_pool', 'target'  if @storage_pool[:type] == "IscsiStoragePool"  %>
+
+<%= text_field_with_label "Export Path", 'storage_pool', 'export_path'  if @storage_pool[:type] == "NfsStoragePool"  %>
 
 
 <%= focus('storage_pool_ip_addr') %>
diff --git a/wui/src/app/views/storage/_list.rhtml b/wui/src/app/views/storage/_list.rhtml
index 4c93360..652d659 100644
--- a/wui/src/app/views/storage/_list.rhtml
+++ b/wui/src/app/views/storage/_list.rhtml
@@ -1,21 +1,34 @@
+<% for type in StoragePool::STORAGE_TYPES.keys %>
+<% type_pools = storage_pools.select {|pool| pool[:type] == StoragePool::STORAGE_TYPES[type]+"StoragePool"} %>
+<%unless type_pools.empty? %>
+<div class="data-section-header"><strong><%= type %></strong></div>
 <table class="listing">
 <thead>
 <tr>
-  <th class="empty">ip : port</th>
+  <th class="empty">ip<%if type == StoragePool::ISCSI -%>: port<%end -%></th>
   <th>type</th>
+<%if type == StoragePool::ISCSI -%>
   <th>target</th>
+<%elsif type == StoragePool::NFS -%>
+  <th>export path</th>
+<% end -%>
   <th class="empty"></th>
 </tr>
 </thead>
 <tbody>
-<% for storage_pool in storage_pools %>
-<tr class="<%= cycle('odd','even', :name => storage_pools) %>">
+<% for storage_pool in type_pools %>
+<tr class="<%= cycle('odd','even', :name => type_pools) %>">
   <% vol_hash = { :controller => 'storage', :action => 'show', :id => storage_pool }
      vol_hash[:hardware_pool_id] = hardware_pool_id if defined? hardware_pool_id
   %>
-  <td style="text-align:left;"><%= link_to storage_pool.ip_addr, vol_hash, { :class => "show" } %><span class="secondary">:<%= storage_pool.port %></span></td>
+  <td style="text-align:left;"><%= link_to storage_pool.ip_addr, vol_hash, { :class => "show" } %>
+    <%if type == StoragePool::ISCSI -%><span class="secondary">:<%= storage_pool.port %></span><% end -%></td>
   <td><%= storage_pool.get_type_label %></td>
+<%if type == StoragePool::ISCSI -%>
   <td><%= storage_pool[:target] %></td>
+<%elsif type == StoragePool::NFS -%>
+  <td><%= storage_pool[:export_path] %></td>
+<% end -%>
 <%if @attach_to_pool -%>
     <td><%= link_to 'Choose', { :action => 'attach_to_pool', :id => storage_pool, :hardware_pool_id => @attach_to_pool }, { :class => "choose" } %></td>
 <% else -%>
@@ -27,3 +40,5 @@
 </tr>
 <% end %>
 </table>
+<% end %>
+<% end %>
diff --git a/wui/src/app/views/storage/_list_volumes.rhtml b/wui/src/app/views/storage/_list_volumes.rhtml
index dd4c721..212720e 100644
--- a/wui/src/app/views/storage/_list_volumes.rhtml
+++ b/wui/src/app/views/storage/_list_volumes.rhtml
@@ -1,24 +1,39 @@
+<% for type in StoragePool::STORAGE_TYPES.keys %>
+<% type_volumes = storage_volumes.select {|volume| volume[:type] == StoragePool::STORAGE_TYPES[type]+"StorageVolume"} %>
+<%unless type_volumes.empty? %>
+<div class="data-section-header"><strong><%= type %></strong></div>
 <table class="listing">
 <thead>
 <tr>
-  <th class="empty">ip : port</th>
+  <th class="empty">ip <%if type == StoragePool::ISCSI -%>: port<%end -%></th>
   <th>type</th>
+<%if type == StoragePool::ISCSI -%>
   <th>target</th>
   <th>LUN</th>
+<%elsif type == StoragePool::NFS -%>
+  <th>export path</th>
+<% end -%>
   <th>size <span class="unit">(gigs)</span></th>
 </tr>
 </thead>
 <tbody>
-<% for storage_volume in storage_volumes %>
-<tr class="<%= cycle('odd','even', :name => storage_volumes) %>">
+<% for storage_volume in type_volumes %>
+<tr class="<%= cycle('odd','even', :name => type_volumes) %>">
   <% vol_hash = { :controller => 'storage', :action => 'show_volume', :id => storage_volume }
      vol_hash[:vm_id] = vm_id if defined? vm_id
   %>
-  <td style="text-align:left;"><%= link_to storage_volume.storage_pool.ip_addr, vol_hash, { :class => "show" } %><span class="secondary">:<%= storage_volume.storage_pool.port %></span></td>
+  <td style="text-align:left;"><%= link_to storage_volume.storage_pool.ip_addr, vol_hash, { :class => "show" } %>
+    <%if type == StoragePool::ISCSI -%><span class="secondary">:<%= storage_volume.storage_pool.port %></span><% end -%></td>
   <td><%= storage_volume.storage_pool.get_type_label %></td>
+<%if type == StoragePool::ISCSI -%>
   <td><%= storage_volume.storage_pool[:target] %></td>
   <td><%= storage_volume.lun %></td>
+<%elsif type == StoragePool::NFS -%>
+  <td><%= "#{storage_volume.storage_pool.export_path}/#{storage_volume.filename}" if storage_volume[:type] == "NfsStorageVolume" %></td>
+<% end -%>
   <td><%= storage_volume.size_in_gb %></td>
 </tr>
 <% end %>
 </table>
+<% end %>
+<% end %>
diff --git a/wui/src/app/views/storage/show.rhtml b/wui/src/app/views/storage/show.rhtml
index 599b2ca..8b20a81 100644
--- a/wui/src/app/views/storage/show.rhtml
+++ b/wui/src/app/views/storage/show.rhtml
@@ -9,8 +9,12 @@
                 <div class="data-table-column">
 
                 <p><b>IP address:</b> <%=h @storage_pool.ip_addr %></p>
+<% if @storage_pool[:type] == "IscsiStoragePool" %>
                 <p><b>Port:</b>       <%=h @storage_pool.port %></p>
                 <p><b>Target:</b>     <%=h @storage_pool.target %></p>
+<% elsif @storage_pool[:type] == "NfsStoragePool" %>
+                <p><b>Export path:</b>     <%=h @storage_pool.export_path %></p>
+<% end %>
                 <p><b>Type:</b>       <%=h @storage_pool.get_type_label %></p>
 
                 </div>
diff --git a/wui/src/app/views/storage/show_volume.rhtml b/wui/src/app/views/storage/show_volume.rhtml
index d518935..42e693d 100644
--- a/wui/src/app/views/storage/show_volume.rhtml
+++ b/wui/src/app/views/storage/show_volume.rhtml
@@ -9,12 +9,20 @@
                 <div class="data-table-column">
 
                 <p><b>IP address:</b> <%=h @storage_volume.storage_pool.ip_addr %></p>
+<% if @storage_volume.storage_pool[:type] == "IscsiStoragePool" %>
                 <p><b>Port:</b>       <%=h @storage_volume.storage_pool.port %></p>
                 <p><b>Target:</b>     <%=h @storage_volume.storage_pool[:target] %></p>
+<% elsif @storage_volume.storage_pool[:type] == "NfsStoragePool" %>
+                <p><b>Export path:</b> <%=h @storage_volume.storage_pool.export_path %></p>
+<% end %>
                 <p><b>Type:</b>       <%=h @storage_volume.storage_pool.get_type_label %></p>
 		<p></p>
                 <p><b>Path:</b>       <%=h @storage_volume.path %></p>
+<% if @storage_volume[:type] == "IscsiStorageVolume" %>
                 <p><b>LUN:</b>        <%=h @storage_volume.lun %></p>
+<% elsif @storage_volume[:type] == "NfsStorageVolume" %>
+                <p><b>Filename:</b>        <%=h @storage_volume.filename %></p>
+<% end %>
                 <p><b>Size:</b>       <%=h @storage_volume.size_in_gb %> GB</p>
 
                 </div>
diff --git a/wui/src/db/migrate/004_create_storage_volumes.rb b/wui/src/db/migrate/004_create_storage_volumes.rb
index 97ae957..51887f4 100644
--- a/wui/src/db/migrate/004_create_storage_volumes.rb
+++ b/wui/src/db/migrate/004_create_storage_volumes.rb
@@ -21,16 +21,28 @@ class CreateStorageVolumes < ActiveRecord::Migration
   def self.up
     create_table :storage_pools do |t|
       t.column :ip_addr,                    :string
-      t.column :port,                       :integer
-      t.column :target,                     :string
       t.column :type,                       :string
       t.column :hardware_pool_id,           :integer, :null => false
+
+      # for IscsiStoragePool
+      t.column :port,                       :integer
+      t.column :target,                     :string
+
+      # for NfsStoragePool
+      t.column :export_path,                :string
     end
+
     create_table :storage_volumes do |t|
       t.column :path,                       :string
-      t.column :lun,                        :string
       t.column :size,                       :integer
       t.column :storage_pool_id,            :integer, :null => false
+      t.column :type,                       :string
+
+      # for IscsiStorageVolume
+      t.column :lun,                        :string
+
+      # for IscsiStorageVolume
+      t.column :filename,                   :string
     end
 
     execute "alter table storage_pools add constraint fk_storage_pool_hw_pools

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]