Harshavardhana
2009-Jul-31 20:27 UTC
[Ovirt-devel] [TAKE-2][PATCH 2/5] Added new glusterfs models for storage_pool,volume respectively
--- src/app/models/glusterfs_storage_pool.rb | 33 ++++++++++++++++++++++++++++ src/app/models/glusterfs_storage_volume.rb | 32 +++++++++++++++++++++++++++ src/app/models/storage_pool.rb | 6 ++++- src/app/models/storage_volume.rb | 4 ++- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/app/models/glusterfs_storage_pool.rb create mode 100644 src/app/models/glusterfs_storage_volume.rb diff --git a/src/app/models/glusterfs_storage_pool.rb b/src/app/models/glusterfs_storage_pool.rb new file mode 100644 index 0000000..0fbc9c2 --- /dev/null +++ b/src/app/models/glusterfs_storage_pool.rb @@ -0,0 +1,33 @@ +# +# Copyright (C) 2008 Z Research Inc. +# Written by Harshavardhana <harsha at gluster.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 GlusterfsStoragePool < StoragePool + + validates_presence_of :ip_addr, :export_path + validates_uniqueness_of :ip_addr, :scope => :export_path + + def label_components + "#{export_path}" + end + + def user_subdividable + true + end + +end diff --git a/src/app/models/glusterfs_storage_volume.rb b/src/app/models/glusterfs_storage_volume.rb new file mode 100644 index 0000000..63749f0 --- /dev/null +++ b/src/app/models/glusterfs_storage_volume.rb @@ -0,0 +1,32 @@ +# +# Copyright (C) 2008 Z Research Inc. +# Written by Harshavardhana <harsha at gluster.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 GlusterfsStorageVolume < StorageVolume + def label_components + "#{storage_pool.export_path}/#{filename}" + end + + def volume_name + "filename" + end + + def volume_create_params + return filename, size, nil, nil, nil + end +end diff --git a/src/app/models/storage_pool.rb b/src/app/models/storage_pool.rb index 40333d0..9416bb3 100644 --- a/src/app/models/storage_pool.rb +++ b/src/app/models/storage_pool.rb @@ -40,7 +40,7 @@ class StoragePool < ActiveRecord::Base validates_presence_of :hardware_pool_id validates_inclusion_of :type, - :in => %w( IscsiStoragePool LvmStoragePool NfsStoragePool ) + :in => %w( IscsiStoragePool LvmStoragePool NfsStoragePool GlusterfsStoragePool ) validates_numericality_of :capacity, @@ -52,9 +52,11 @@ class StoragePool < ActiveRecord::Base :eager_load => :smart_pools ISCSI = "iSCSI" NFS = "NFS" + GLUSTERFS = "GLUSTERFS" LVM = "LVM" STORAGE_TYPES = { ISCSI => "Iscsi", NFS => "Nfs", + GLUSTERFS => "Glusterfs", LVM => "Lvm" } STORAGE_TYPE_PICKLIST = STORAGE_TYPES.keys - [LVM] @@ -72,6 +74,8 @@ class StoragePool < ActiveRecord::Base return IscsiStoragePool.new(params) when NFS return NfsStoragePool.new(params) + when GLUSTERFS + return GlusterfsStoragePool.new(params) when LVM return LvmStoragePool.new(params) else diff --git a/src/app/models/storage_volume.rb b/src/app/models/storage_volume.rb index 45cd5c6..0570f14 100644 --- a/src/app/models/storage_volume.rb +++ b/src/app/models/storage_volume.rb @@ -40,7 +40,7 @@ class StorageVolume < ActiveRecord::Base :unless => Proc.new { |storage_volume| storage_volume.nil? } validates_inclusion_of :type, - :in => %w( IscsiStorageVolume LvmStorageVolume NfsStorageVolume ) + :in => %w( IscsiStorageVolume LvmStorageVolume NfsStorageVolume GlusterfsStorageVolume ) STATE_PENDING_SETUP = "pending_setup" STATE_PENDING_DELETION = "pending_deletion" @@ -56,6 +56,8 @@ class StorageVolume < ActiveRecord::Base return IscsiStorageVolume.new(params) when StoragePool::NFS return NfsStorageVolume.new(params) + when StoragePool::GLUSTERFS + return GlusterfsStorageVolume.new(params) when StoragePool::LVM return LvmStorageVolume.new(params) else -- 1.6.0.6