Revision 922a9e65 lib/cmdlib/instance.py
b/lib/cmdlib/instance.py | ||
---|---|---|
2136 | 2136 |
|
2137 | 2137 |
|
2138 | 2138 |
def _ApplyContainerMods(kind, container, chgdesc, mods, |
2139 |
create_fn, modify_fn, remove_fn): |
|
2139 |
create_fn, modify_fn, remove_fn, |
|
2140 |
post_add_fn=None): |
|
2140 | 2141 |
"""Applies descriptions in C{mods} to C{container}. |
2141 | 2142 |
|
2142 | 2143 |
@type kind: string |
... | ... | |
2160 | 2161 |
@type remove_fn: callable |
2161 | 2162 |
@param remove_fn: Callback on removing item; receives absolute item index, |
2162 | 2163 |
item and private data object as added by L{_PrepareContainerMods} |
2164 |
@type post_add_fn: callable |
|
2165 |
@param post_add_fn: Callable for post-processing a newly created item after |
|
2166 |
it has been put into the container. It receives the index of the new item |
|
2167 |
and the new item as parameters. |
|
2163 | 2168 |
|
2164 | 2169 |
""" |
2165 | 2170 |
for (op, identifier, params, private) in mods: |
... | ... | |
2196 | 2201 |
assert idx <= len(container) |
2197 | 2202 |
# list.insert does so before the specified index |
2198 | 2203 |
container.insert(idx, item) |
2204 |
|
|
2205 |
if post_add_fn is not None: |
|
2206 |
post_add_fn(addidx, item) |
|
2207 |
|
|
2199 | 2208 |
else: |
2200 | 2209 |
# Retrieve existing item |
2201 | 2210 |
(absidx, item) = GetItemFromContainer(identifier, kind, container) |
... | ... | |
3229 | 3238 |
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)), |
3230 | 3239 |
]) |
3231 | 3240 |
|
3241 |
def _PostAddDisk(self, _, disk): |
|
3242 |
if not WaitForSync(self, self.instance, disks=[disk], |
|
3243 |
oneshot=not self.op.wait_for_sync): |
|
3244 |
raise errors.OpExecError("Failed to sync disks of %s" % |
|
3245 |
self.instance.name) |
|
3246 |
|
|
3232 | 3247 |
@staticmethod |
3233 | 3248 |
def _ModifyDisk(idx, disk, params, _): |
3234 | 3249 |
"""Modifies a disk. |
... | ... | |
3345 | 3360 |
# Apply disk changes |
3346 | 3361 |
_ApplyContainerMods("disk", self.instance.disks, result, self.diskmod, |
3347 | 3362 |
self._CreateNewDisk, self._ModifyDisk, |
3348 |
self._RemoveDisk) |
|
3363 |
self._RemoveDisk, post_add_fn=self._PostAddDisk)
|
|
3349 | 3364 |
_UpdateIvNames(0, self.instance.disks) |
3350 | 3365 |
|
3351 | 3366 |
if self.op.disk_template: |
Also available in: Unified diff