Scott Seago
2008-Nov-20 21:42 UTC
[Ovirt-devel] [PATCH] refactored storage UI to allow for creating/deleting NFS volumes.
Storage UI tab now allows for creation of NFS volumes. The UI is similar to the LVM volume creation functionality, except it's done from the NFS pool details pane rather than from tne ISCSI volume pane. Signed-off-by: Scott Seago <sseago at redhat.com> --- src/app/controllers/storage_controller.rb | 51 +++++++++++--------- src/app/models/nfs_storage_pool.rb | 4 ++ src/app/views/storage/_lvm_volume_form.rhtml | 19 ------- src/app/views/storage/_new_volume_form.rhtml | 24 +++++++++ .../{new_lvm_volume.rhtml => new_volume.rhtml} | 23 +++++---- src/app/views/storage/show.rhtml | 5 ++ src/app/views/storage/show_volume.rhtml | 2 +- .../migrate/031_add_storage_pool_capacity.rb} | 14 +++--- 8 files changed, 83 insertions(+), 59 deletions(-) delete mode 100644 src/app/views/storage/_lvm_volume_form.rhtml create mode 100644 src/app/views/storage/_new_volume_form.rhtml rename src/app/views/storage/{new_lvm_volume.rhtml => new_volume.rhtml} (60%) copy src/{app/models/nfs_storage_pool.rb => db/migrate/031_add_storage_pool_capacity.rb} (81%) diff --git a/src/app/controllers/storage_controller.rb b/src/app/controllers/storage_controller.rb index 6e6e3c2..6d171c9 100644 --- a/src/app/controllers/storage_controller.rb +++ b/src/app/controllers/storage_controller.rb @@ -122,32 +122,37 @@ class StorageController < ApplicationController end def new_volume - new_volume_internal(StoragePool.find(params[:storage_pool_id]), - { :storage_pool_id => params[:storage_pool_id]}) - render :layout => 'popup' - end - - def new_lvm_volume - @source_volume = StorageVolume.find(params[:source_volume_id]) @return_facebox = params[:return_facebox] - unless @source_volume.supports_lvm_subdivision - #fixme: proper error page for popups - redirect_to :controller => 'dashboard' - return - end - lvm_pool = @source_volume.lvm_storage_pool - unless lvm_pool - # FIXME: what should we do about VG/LV names? - # for now auto-create VG name as ovirt_vg_#{@source_volume.id} - lvm_pool = LvmStoragePool.new(:vg_name => "ovirt_vg_#{@source_volume.id}", + if params[:storage_pool_id] + @storage_pool = StoragePool.find(params[:storage_pool_id]) + unless @storage_pool.user_subdividable + #fixme: proper error page for popups + redirect_to :controller => 'dashboard' + return + end + new_volume_internal(@storage_pool, + { :storage_pool_id => params[:storage_pool_id]}) + else + @source_volume = StorageVolume.find(params[:source_volume_id]) + unless @source_volume.supports_lvm_subdivision + #fixme: proper error page for popups + redirect_to :controller => 'dashboard' + return + end + lvm_pool = @source_volume.lvm_storage_pool + unless lvm_pool + # FIXME: what should we do about VG/LV names? + # for now auto-create VG name as ovirt_vg_#{@source_volume.id} + lvm_pool = LvmStoragePool.new(:vg_name => "ovirt_vg_#{@source_volume.id}", :hardware_pool_id => @source_volume.storage_pool.hardware_pool_id) - lvm_pool.source_volumes << @source_volume - lvm_pool.save! + lvm_pool.source_volumes << @source_volume + lvm_pool.save! + end + new_volume_internal(lvm_pool, { :storage_pool_id => lvm_pool.id}) + @storage_volume.lv_owner_perms='0744' + @storage_volume.lv_group_perms='0744' + @storage_volume.lv_mode_perms='0744' end - new_volume_internal(lvm_pool, { :storage_pool_id => lvm_pool.id}) - @storage_volume.lv_owner_perms='0744' - @storage_volume.lv_group_perms='0744' - @storage_volume.lv_mode_perms='0744' render :layout => 'popup' end diff --git a/src/app/models/nfs_storage_pool.rb b/src/app/models/nfs_storage_pool.rb index a27944b..398e3f9 100644 --- a/src/app/models/nfs_storage_pool.rb +++ b/src/app/models/nfs_storage_pool.rb @@ -25,4 +25,8 @@ class NfsStoragePool < StoragePool def label_components "#{export_path}" end + + def user_subdividable + true + end end diff --git a/src/app/views/storage/_lvm_volume_form.rhtml b/src/app/views/storage/_lvm_volume_form.rhtml deleted file mode 100644 index 823158e..0000000 --- a/src/app/views/storage/_lvm_volume_form.rhtml +++ /dev/null @@ -1,19 +0,0 @@ -<%= error_messages_for 'storage_volume' %> - -<!--[form:storage_pool]--> -<%= hidden_field 'storage_volume', 'storage_pool_id' %> -<%= hidden_field_tag 'storage_type', @storage_volume.get_type_label %> - -<%= text_field_with_label "Size (GB):", 'storage_volume', 'size_in_gb' %> - -<%= text_field_with_label "LV Name:", 'storage_volume', 'lv_name' %> - -<%= text_field_with_label "Owner permissions:", 'storage_volume', 'lv_owner_perms' %> - -<%= text_field_with_label "Group permissions:", 'storage_volume', 'lv_group_perms' %> - -<%= text_field_with_label "Mode permissions:", 'storage_volume', 'lv_mode_perms' %> - - -<!--[eoform:storage_volume]--> - diff --git a/src/app/views/storage/_new_volume_form.rhtml b/src/app/views/storage/_new_volume_form.rhtml new file mode 100644 index 0000000..ae65e18 --- /dev/null +++ b/src/app/views/storage/_new_volume_form.rhtml @@ -0,0 +1,24 @@ +<%= error_messages_for 'storage_volume' %> + +<!--[form:storage_pool]--> +<%= hidden_field 'storage_volume', 'storage_pool_id' %> +<%= hidden_field_tag 'storage_type', @storage_volume.get_type_label %> + +<%= text_field_with_label "Size (GB):", 'storage_volume', 'size_in_gb' %> + +<%if @storage_volume.get_type_label==StoragePool::LVM -%> + <%= text_field_with_label "LV Name:", 'storage_volume', 'lv_name' %> + + <%= text_field_with_label "Owner permissions:", 'storage_volume', 'lv_owner_perms' %> + + <%= text_field_with_label "Group permissions:", 'storage_volume', 'lv_group_perms' %> + + <%= text_field_with_label "Mode permissions:", 'storage_volume', 'lv_mode_perms' %> +<%- end -%> +<%= text_field_with_label "LUN:", 'storage_volume', 'lun' if @storage_volume.get_type_label==StoragePool::ISCSI %> + +<%= text_field_with_label "Filename:", 'storage_volume', 'filename' if @storage_volume.get_type_label==StoragePool::NFS %> + + +<!--[eoform:storage_volume]--> + diff --git a/src/app/views/storage/new_lvm_volume.rhtml b/src/app/views/storage/new_volume.rhtml similarity index 60% rename from src/app/views/storage/new_lvm_volume.rhtml rename to src/app/views/storage/new_volume.rhtml index ea51cc5..958c463 100644 --- a/src/app/views/storage/new_lvm_volume.rhtml +++ b/src/app/views/storage/new_volume.rhtml @@ -1,23 +1,28 @@ <%- content_for :title do -%> - <%= _("Add New LVM Volume") %> + <%= _("Add New Volume") %> <%- end -%> <%- content_for :description do -%> - Add a new LVM Storage Volume to <%= @source_volume.display_name %>. + Add a new Storage Volume to + <%= if @storage_volume.get_type_label==StoragePool::LVM + @source_volume.display_name + else + @storage_pool.display_name + end %>. <%- end -%> <div class="panel_header"></div> <div class="dialog_form"> -<form method="POST" action="<%= url_for :action => 'create_volume' %>" id="lvm_volume_form" > +<form method="POST" action="<%= url_for :action => 'create_volume' %>" id="storage_volume_form" > <div class="dialog_form"> <div id="new_storage_pool"> - <%= render :partial => 'lvm_volume_form' %> + <%= render :partial => 'new_volume_form' %> </div> </div> <!-- FIXME: need to pop up the details dialog again --> - <%= popup_footer("$('#lvm_volume_form').submit()", "New LVM Volume") %> + <%= popup_footer("$('#storage_volume_form').submit()", "New Storage Volume") %> </form> </div> <script type="text/javascript"> -function afterLvmVolume(response, status){ +function afterStorageVolume(response, status){ ajax_validation(response, status); if (response.success) { <% if @return_facebox %> @@ -30,13 +35,13 @@ function afterLvmVolume(response, status){ } } $(function() { - var lvmvolumeoptions = { + var storagevolumeoptions = { target: '<%= url_for :action => 'create_volume' %>', // target element to update dataType: 'json', - success: afterLvmVolume // post-submit callback + success: afterStorageVolume // post-submit callback }; // bind form using 'ajaxForm' - $('#lvm_volume_form').ajaxForm(lvmvolumeoptions); + $('#storage_volume_form').ajaxForm(storagevolumeoptions); }); </script> diff --git a/src/app/views/storage/show.rhtml b/src/app/views/storage/show.rhtml index a4cc1c2..7e02f32 100644 --- a/src/app/views/storage/show.rhtml +++ b/src/app/views/storage/show.rhtml @@ -10,6 +10,11 @@ <a href="#" onClick="refresh_storage_pool()"> <%= image_tag "icon_refresh.png" %> Refresh </a> + <%if @storage_pool.user_subdividable -%> + <%= link_to image_tag("icon_addstorage.png") + " Add new Volume", + {:controller => 'storage', :action => 'new_volume', :storage_pool_id => @storage_pool.id}, + :rel=>"facebox[.bolder]", :class=>"selection_facebox" %> + <% end %> <a href="#confirm_delete_storage" rel="facebox[.bolder]"> <%= image_tag "icon_x.png" %> Delete </a> diff --git a/src/app/views/storage/show_volume.rhtml b/src/app/views/storage/show_volume.rhtml index bd1642f..f85feaa 100644 --- a/src/app/views/storage/show_volume.rhtml +++ b/src/app/views/storage/show_volume.rhtml @@ -6,7 +6,7 @@ <%if @can_modify -%> <%if @storage_volume.supports_lvm_subdivision and @storage_volume.vms.empty? -%> <%= link_to image_tag("icon_addstorage.png") + " Add new Volume", - {:controller => 'storage', :action => 'new_lvm_volume', :source_volume_id => @storage_volume.id}, + {:controller => 'storage', :action => 'new_volume', :source_volume_id => @storage_volume.id}, :rel=>"facebox[.bolder]", :class=>"selection_facebox" %> <% end %> <%if @storage_volume.deletable -%> diff --git a/src/app/models/nfs_storage_pool.rb b/src/db/migrate/031_add_storage_pool_capacity.rb similarity index 81% copy from src/app/models/nfs_storage_pool.rb copy to src/db/migrate/031_add_storage_pool_capacity.rb index a27944b..dc8e5d4 100644 --- a/src/app/models/nfs_storage_pool.rb +++ b/src/db/migrate/031_add_storage_pool_capacity.rb @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2008 Red Hat, Inc. # Written by Scott Seago <sseago at redhat.com> # @@ -17,12 +17,12 @@ # 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 - - validates_presence_of :ip_addr, :export_path - validates_uniqueness_of :ip_addr, :scope => :export_path +class AddStoragePoolCapacity < ActiveRecord::Migration + def self.up + add_column :storage_pools, :capacity, :integer, :limit => 8 + end - def label_components - "#{export_path}" + def self.down + drop_column :storage_pools, :capacity end end -- 1.5.6.5
Jason Guiditta
2008-Nov-24 19:07 UTC
[Ovirt-devel] [PATCH] refactored storage UI to allow for creating/deleting NFS volumes.
On Thu, 2008-11-20 at 21:42 +0000, Scott Seago wrote:> Storage UI tab now allows for creation of NFS volumes. The UI is similar to the LVM volume creation functionality, except it's done from the NFS pool details pane rather than from tne ISCSI volume pane.ACK, this works for me. -j