Class: Dcmgr::Models::StoragePool

Inherits:
AccountResource show all
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

BaseNew::LOCK_TABLES_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AccountResource

#account

Methods inherited from BaseNew

Proxy, dataset, install_data, install_data_hooks, lock!, unlock!

Class Method Details

.create_pool(params) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/dcmgr/models/storage_pool.rb', line 106

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



117
118
119
120
121
# File 'lib/dcmgr/models/storage_pool.rb', line 117

def self.get_lists(uuid)
  self.dataset.where(:account_id => uuid).all.map{|row|
    row.values
  }
end

Instance Method Details

#before_validationObject



39
40
41
42
43
44
45
46
# File 'lib/dcmgr/models/storage_pool.rb', line 39

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=>).where(:uuid=>uuid)

end



127
128
129
130
131
132
# File 'lib/dcmgr/models/storage_pool.rb', line 127

def create_volume(, size, snapshot_id=nil)
  v = Volume.create(:account_id => ,
                    :storage_pool_id => self.id,
                    :snapshot_id => snapshot_id,
                    :size =>size)
end

#state_machineObject



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
101
102
103
104
# File 'lib/dcmgr/models/storage_pool.rb', line 54

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

#to_hash_documentObject



48
49
50
51
52
# File 'lib/dcmgr/models/storage_pool.rb', line 48

def to_hash_document
  h = self.values.dup
  h[:id] = h[:uuid] = self.canonical_uuid
  h
end