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"
- RECENT_TERMED_PERIOD =
(60 * 15)
Constants inherited
from BaseNew
BaseNew::LOCK_TABLES_KEY
Class Method Summary
collapse
Instance Method Summary
collapse
#account
Methods inherited from BaseNew
Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?
Class Method Details
.delete_volume(account_id, uuid) ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'lib/dcmgr/models/volume.rb', line 116
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/dcmgr/models/volume.rb', line 90
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_api_document
}
end
|
Instance Method Details
#before_create ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/dcmgr/models/volume.rb', line 72
def before_create
sp = self.storage_pool
volume_size = sp.volumes_dataset.lives.sum(:size).to_i
total_size = sp.offering_disk_space - volume_size.to_i
if self.size > total_size
raise DiskError, "out of disk space"
end
per_account_totoal = self.class.filter(:account_id=>self.account_id).lives.sum(:size).to_i
if self.account.quota.volume_total_size < per_account_totoal + self.size.to_i
raise DiskError, "Out of account quota: #{self.account.quota.volume_total_size}, #{self.size.to_i}, #{per_account_totoal}"
end
super
end
|
#create_snapshot(account_id) ⇒ Object
158
159
160
161
162
163
|
# File 'lib/dcmgr/models/volume.rb', line 158
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
126
127
128
129
|
# File 'lib/dcmgr/models/volume.rb', line 126
def merge_pool_data
v = self.to_hash
v.merge(:storage_pool=>storage_pool.to_hash)
end
|
#ready_to_take_snapshot? ⇒ Boolean
154
155
156
|
# File 'lib/dcmgr/models/volume.rb', line 154
def ready_to_take_snapshot?
%w(available attached).member?(self.state)
end
|
#to_api_document ⇒ Object
Hash data for API response.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/dcmgr/models/volume.rb', line 139
def to_api_document
h = {
:id => self.canonical_uuid,
:uuid => self.canonical_uuid,
:size => self.size,
:snapshot_id => self.snapshot_id,
:created_at => self.created_at,
:attached_at => self.attached_at,
:state => self.state,
:instance_id => (self.instance && self.instance.canonical_uuid),
:deleted_at => self.deleted_at,
:detached_at => self.detached_at,
}
end
|
#to_hash ⇒ Object
131
132
133
134
135
136
|
# File 'lib/dcmgr/models/volume.rb', line 131
def to_hash
h = super
h[:transport_information]=self.transport_information
h
end
|