Class: Dcmgr::Models::InstanceSpec
Constant Summary
Constants inherited
from BaseNew
BaseNew::LOCK_TABLES_KEY
Instance Method Summary
collapse
-
#add_local_drive(name, index, size) ⇒ Object
-
#add_vif(name, index, bandwidth) ⇒ Object
Modify methods for vifs,drives hash parameters.
-
#add_volume_drive(name, index, size) ⇒ Object
-
#add_volume_drive_from_snapshot(name, index, snapshot_id) ⇒ Object
-
#before_destroy ⇒ Object
-
#before_validation ⇒ Object
-
#remove_drive(name) ⇒ Object
-
#remove_vif(name) ⇒ Object
-
#to_api_document ⇒ Object
-
#to_hash ⇒ Object
-
#update_drive_index(name, new_index) ⇒ Object
-
#update_drive_size(name, size) ⇒ Object
-
#update_drive_snapshot_id(name, snapshot_id) ⇒ Object
-
#update_vif_bandwidth(name, bandwidth) ⇒ Object
-
#update_vif_index(name, new_index) ⇒ Object
-
#validate ⇒ Object
#account
Methods inherited from BaseNew
Proxy, dataset, default_row_lock_mode=, install_data, install_data_hooks, lock!, unlock!, #with_timestamps?
Instance Method Details
#add_local_drive(name, index, size) ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/dcmgr/models/instance_spec.rb', line 121
def add_local_drive(name, index, size)
raise "Duplicate drive name: #{name}" if self.drives.has_key?(name)
self.drives[name] = {
:index => index,
:type => :local,
:size => size,
}
self.changed_columns << :drives
self
end
|
#add_vif(name, index, bandwidth) ⇒ Object
Modify methods for vifs,drives hash parameters.
91
92
93
94
95
96
97
98
99
|
# File 'lib/dcmgr/models/instance_spec.rb', line 91
def add_vif(name, index, bandwidth)
raise "Duplicate interface name: #{name}" if self.vifs.has_key?(name)
self.vifs[name]={
:index => index,
:bandwidth => bandwidth,
}
self.changed_columns << :vifs
self
end
|
#add_volume_drive(name, index, size) ⇒ Object
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/dcmgr/models/instance_spec.rb', line 132
def add_volume_drive(name, index, size)
raise "Duplicate drive name: #{name}" if self.drives.has_key?(name)
self.drives[name] = {
:index => index,
:type => :volume,
:size => size,
}
self.changed_columns << :drives
self
end
|
#add_volume_drive_from_snapshot(name, index, snapshot_id) ⇒ Object
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/dcmgr/models/instance_spec.rb', line 143
def add_volume_drive_from_snapshot(name, index, snapshot_id)
raise "Duplicate drive name: #{name}" if self.drives.has_key?(name)
self.drives[name] = {
:index => index,
:type => :volume,
:snapshot_id => snapshot_id,
}
self.changed_columns << :drives
self
end
|
#before_destroy ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/dcmgr/models/instance_spec.rb', line 69
def before_destroy
if !Instance.alives.filter(:instance_spec_id=>self.id).empty?
raise "There are one or more running instances refers this record."
end
super
end
|
#before_validation ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/dcmgr/models/instance_spec.rb', line 46
def before_validation
default_config = {}
self.config = default_config.merge(self.config || {})
self.vifs ||= {}
self.drives ||= {}
super
end
|
#remove_drive(name) ⇒ Object
182
183
184
185
186
|
# File 'lib/dcmgr/models/instance_spec.rb', line 182
def remove_drive(name)
self.drives.delete(name)
self.changed_columns << :drives
self
end
|
#remove_vif(name) ⇒ Object
115
116
117
118
119
|
# File 'lib/dcmgr/models/instance_spec.rb', line 115
def remove_vif(name)
self.vifs.delete(name)
self.changed_columns << :vifs
self
end
|
#to_api_document ⇒ Object
84
85
86
87
88
|
# File 'lib/dcmgr/models/instance_spec.rb', line 84
def to_api_document
doc = super()
doc.delete(:config)
doc
end
|
#to_hash ⇒ Object
77
78
79
80
81
82
|
# File 'lib/dcmgr/models/instance_spec.rb', line 77
def to_hash
super.merge({:config=>self.config, :vifs => self.vifs, :drives => self.drives, })
end
|
#update_drive_index(name, new_index) ⇒ Object
154
155
156
157
158
159
160
|
# File 'lib/dcmgr/models/instance_spec.rb', line 154
def update_drive_index(name, new_index)
raise "Unknown drive name: #{name}" if !self.drives.has_key?(name)
drive = self.drives[name]
drive[:index] = new_index
self.changed_columns << :drives
self
end
|
#update_drive_size(name, size) ⇒ Object
173
174
175
176
177
178
179
180
|
# File 'lib/dcmgr/models/instance_spec.rb', line 173
def update_drive_size(name, size)
raise "Unknown drive name: #{name}" if !self.drives.has_key?(name)
drive = self.drives[name]
drive.delete(:snapshot_id) if drive[:type] == :volume
drive[:size] = size
self.changed_columns << :drives
self
end
|
#update_drive_snapshot_id(name, snapshot_id) ⇒ Object
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/dcmgr/models/instance_spec.rb', line 162
def update_drive_snapshot_id(name, snapshot_id)
raise "Unknown drive name: #{name}" if !self.drives.has_key?(name)
drive = self.drives[name]
raise "Snapshot ID can only be set to volume drive" if !(drive[:type] == :volume)
drive.delete(:size)
drive[:snapshot_id] = snapshot_id
self.changed_columns << :drives
self
end
|
#update_vif_bandwidth(name, bandwidth) ⇒ Object
108
109
110
111
112
113
|
# File 'lib/dcmgr/models/instance_spec.rb', line 108
def update_vif_bandwidth(name, bandwidth)
raise "Unknown interface name: #{name}" if !self.vifs.has_key?(name)
self.vifs[name][:bandwidth]=bandwidth
self.changed_columns << :vifs
self
end
|
#update_vif_index(name, new_index) ⇒ Object
101
102
103
104
105
106
|
# File 'lib/dcmgr/models/instance_spec.rb', line 101
def update_vif_index(name, new_index)
raise "Unknown interface name: #{name}" if !self.vifs.has_key?(name)
self.vifs[name][:index]=new_index
self.changed_columns << :vifs
self
end
|
#validate ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/dcmgr/models/instance_spec.rb', line 57
def validate
super
unless self.vifs.values.map {|i| i[:index] }.uniq.size == self.vifs.size
errors.add(:vifs, "duplicate index value.")
end
unless self.drives.values.map {|i| i[:index] }.uniq.size == self.drives.size
errors.add(:drives, "duplicate index value.")
end
end
|