Class: Dcmgr::Models::StoragePool
- Inherits:
-
AccountResource
- Object
- Sequel::Model
- BaseNew
- AccountResource
- Dcmgr::Models::StoragePool
- Defined in:
- lib/dcmgr/models/storage_pool.rb
Constant Summary collapse
- STATAS_TYPE_REGISTERING =
"registering"
- STATAS_TYPE_ONLINE =
"online"
- STATAS_TYPE_DEGRADE =
"degrade"
- STATAS_TYPE_FAILED =
"failed"
- STATAS_TYPE_DEREGISTERED =
"deregistered"
- STATUS_MSGS =
{ STATAS_TYPE_REGISTERING => :registering, STATAS_TYPE_ONLINE => :online, STATAS_TYPE_DEGRADE => :degrade, STATAS_TYPE_FAILED => :failed, STATAS_TYPE_DEREGISTERED => :deregistered }
Constants inherited from BaseNew
Class Method Summary collapse
Instance Method Summary collapse
- #before_validation ⇒ Object
-
#create_volume(account_id, size, snapshot_id = nil) ⇒ Object
def find_private_pool(account_id, uuid) sp = self.dataset.where(:account_id=>account_id).where(:uuid=>uuid) end.
- #state_machine ⇒ Object
Methods inherited from AccountResource
Methods inherited from BaseNew
Proxy, dataset, install_data, install_data_hooks, lock!, unlock!
Class Method Details
.create_pool(params) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dcmgr/models/storage_pool.rb', line 102 def self.create_pool(params) self.create(:account_id => params[:account_id], :node_id => params[:node_id], :offerring_disk_space => params[:offerring_disk_space], :transport_type => params[:transport_type], :storage_type => params[:storage_type], :export_path => params[:export_path], :ipaddr => params[:ipaddr], :snapshot_base_path => params[:snapshot_base_path]) end |
.get_lists(uuid) ⇒ Object
113 114 115 116 117 |
# File 'lib/dcmgr/models/storage_pool.rb', line 113 def self.get_lists(uuid) self.dataset.where(:account_id => uuid).all.map{|row| row.values } end |
Instance Method Details
#before_validation ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dcmgr/models/storage_pool.rb', line 41 def before_validation export_path = self.export_path if export_path =~ /^(\/[a-z0-9]+)+$/ export_path = export_path.split('/') export_path.shift self.export_path = export_path.join('/') end end |
#create_volume(account_id, size, snapshot_id = nil) ⇒ Object
def find_private_pool(account_id, uuid)
sp = self.dataset.where(:account_id=>account_id).where(:uuid=>uuid)
end
123 124 125 126 127 128 |
# File 'lib/dcmgr/models/storage_pool.rb', line 123 def create_volume(account_id, size, snapshot_id=nil) v = Volume.create(:account_id => account_id, :storage_pool_id => self.id, :snapshot_id => snapshot_id, :size =>size) end |
#state_machine ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/dcmgr/models/storage_pool.rb', line 50 def state_machine model = self st = Statemachine.build do superstate :storage_condition do trans :registering, :on_success, :online trans :registering, :on_error, :degrade trans :online, :on_success, :online trans :online, :on_error, :degrade trans :degrade, :on_success, :online trans :degrade, :on_error, :degrade event :on_fail, :failed event :on_deregistered, :deregistered end trans :failed, :on_success, :online trans :failed, :on_error, :degrade trans :failed, :on_deregistered, :deregistered on_entry_of :registering, proc { model.status = STATAS_TYPE_REGISTERING } on_entry_of :online, proc { model.status = STATAS_TYPE_ONLINE } on_entry_of :degrade, proc { model.status = STATAS_TYPE_DEGRADE } on_entry_of :failed, proc { model.status = STATAS_TYPE_FAILED } on_entry_of :deregistered, proc { model.status = STATAS_TYPE_DEREGISTERED } end if self[:status] if st.has_state(STATUS_MSGS[self[:status]].to_sym) st.state = STATUS_MSGS[self[:status]].to_sym else raise "Unknown state: #{self[:status]}" end else st.reset end st end |