Class: Dcmgr::Models::Volume
Defined Under Namespace
Classes: DiskError, RequestError
Constant Summary
collapse
- STATUS_TYPE_REGISTERING =
"registering"
- STATUS_TYPE_ONLINE =
"online"
- STATUS_TYPE_OFFLINE =
"offline"
- STATUS_TYPE_FAILED =
"failed"
- STATE_TYPE_REGISTERING =
"registering"
- STATE_TYPE_CREATING =
"creating"
- STATE_TYPE_AVAILABLE =
"available"
- STATE_TYPE_ATTATING =
"attating"
- STATE_TYPE_ATTACHED =
"attached"
- STATE_TYPE_DETACHING =
"detaching"
- STATE_TYPE_FAILED =
"failed"
- STATE_TYPE_DEREGISTERING =
"deregistering"
- STATE_TYPE_DELETING =
"deleting"
- STATE_TYPE_DELETED =
"deleted"
Constants inherited
from BaseNew
BaseNew::LOCK_TABLES_KEY
Class Method Summary
collapse
Instance Method Summary
collapse
#account
Methods inherited from BaseNew
Proxy, dataset, install_data, install_data_hooks, lock!, unlock!
Class Method Details
.delete_volume(account_id, uuid) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/dcmgr/models/volume.rb', line 100
def self.delete_volume(account_id, uuid)
v = self.dataset.where(:account_id=>account_id).where(:uuid=>uuid.split('-').last).first
if v.state.to_sym != :available
raise RequestError, "invalid delete request"
end
v.state = :deregistering
v.save_changes
v
end
|
.get_list(account_id, *args) ⇒ Object
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
|
# File 'lib/dcmgr/models/volume.rb', line 74
def self.get_list(account_id, *args)
data = args.first
vl = self.dataset.where(:account_id=>account_id)
vl = vl.limit(data[:limit], data[:start]) if data[:start] && data[:limit]
if data[:target] && data[:sort]
vl = case data[:sort]
when 'desc'
vl.order(data[:target].to_sym.desc)
when 'asc'
vl.order(data[:target].to_sym.asc)
end
end
if data[:target] && data[:filter]
filter = case data[:target]
when 'uuid'
data[:filter].split('vol-').last
else
data[:filter]
end
vl = vl.grep(data[:target].to_sym, "%#{filter}%")
end
vl.all.map{|row|
row.to_hash_document
}
end
|
Instance Method Details
#before_create ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/dcmgr/models/volume.rb', line 57
def before_create
sp = self.storage_pool
volume_size = Volume.dataset.where(:storage_pool_id=> self.storage_pool_id).get{sum(:size)}
total_size = sp.offerring_disk_space - volume_size.to_i
if self.size > total_size
raise DiskError, "out of disk space"
end
super
end
|
#before_save ⇒ Object
69
70
71
72
|
# File 'lib/dcmgr/models/volume.rb', line 69
def before_save
self.updated_at = Time.now
super
end
|
#create_snapshot(account_id) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/dcmgr/models/volume.rb', line 123
def create_snapshot(account_id)
vs = VolumeSnapshot.create(:account_id=>account_id,
:storage_pool_id=>self.storage_pool_id,
:origin_volume_id=>self.canonical_uuid,
:size=>self.size)
end
|
#merge_pool_data ⇒ Object
110
111
112
113
|
# File 'lib/dcmgr/models/volume.rb', line 110
def merge_pool_data
v = self.to_hash_document
v.merge(:storage_pool=>storage_pool.to_hash_document)
end
|
#to_hash_document ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/dcmgr/models/volume.rb', line 115
def to_hash_document
h = self.values.dup
h[:id] = h[:uuid] = h[:export_path] = self.canonical_uuid
h[:transport_information]=self.transport_information
h
end
|