Class: Dcmgr::Models::StorageNode

Inherits:
AccountResource show all
Defined in:
lib/dcmgr/models/storage_node.rb

Constant Summary collapse

BACKINGSTORE_ZFS =
'zfs'
BACKINGSTORE_RAW =
'raw'
SUPPORTED_BACKINGSTORE =
[BACKINGSTORE_ZFS, BACKINGSTORE_RAW]

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, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?

Class Method Details

.check_domain_capacity?(size, num = 1) ⇒ Boolean

Check the free resource capacity across entire local VDC domain.

Returns:

  • (Boolean)


79
80
81
82
83
84
# File 'lib/dcmgr/models/storage_node.rb', line 79

def self.check_domain_capacity?(size, num=1)
  alives_size = Volume.dataset.lives.filter.sum(:size).to_i
  avail_size = self.online_nodes.sum(:offering_disk_space).to_i - alives_size
  
  (avail_size >= size * num.to_i)
end

.create_pool(params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/dcmgr/models/storage_node.rb', line 35

def self.create_pool(params)
  self.create(:account_id => params[:account_id],
              :node_id => params[:node_id],
              :offering_disk_space => params[:offering_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



46
47
48
49
50
# File 'lib/dcmgr/models/storage_node.rb', line 46

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

Instance Method Details

#before_validationObject



25
26
27
28
29
30
31
32
33
# File 'lib/dcmgr/models/storage_node.rb', line 25

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
  super
end

#disk_usageObject

Returns total disk usage of associated volumes.



69
70
71
# File 'lib/dcmgr/models/storage_node.rb', line 69

def disk_usage
  volumes_dataset.lives.sum(:size).to_i
end

#free_disk_spaceObject

Returns available space of the storage node.



74
75
76
# File 'lib/dcmgr/models/storage_node.rb', line 74

def free_disk_space
  self.offering_disk_space - self.disk_usage
end

#statusObject

Show status of the agent.



53
54
55
# File 'lib/dcmgr/models/storage_node.rb', line 53

def status
  node.nil? ? :offline : node.state
end

#to_api_documentObject



61
62
63
64
65
66
# File 'lib/dcmgr/models/storage_node.rb', line 61

def to_api_document
  h = super()
  h.merge!(:status=>self.status)
  h.delete(:node_id)
  h
end

#to_hashObject



57
58
59
# File 'lib/dcmgr/models/storage_node.rb', line 57

def to_hash
  super.merge({:status=>self.status})
end