Revision ba924970 lib/cmdlib/instance.py
b/lib/cmdlib/instance.py | ||
---|---|---|
1834 | 1834 |
idx, result.fail_msg) |
1835 | 1835 |
errs.append(result.fail_msg) |
1836 | 1836 |
break |
1837 |
dev_path = result.payload |
|
1837 |
dev_path, _ = result.payload
|
|
1838 | 1838 |
result = self.rpc.call_blockdev_export(source_node.uuid, (disk, |
1839 | 1839 |
self.instance), |
1840 | 1840 |
target_node.secondary_ip, |
... | ... | |
3063 | 3063 |
# Operate on copies as this is still in prereq |
3064 | 3064 |
nics = [nic.Copy() for nic in self.instance.nics] |
3065 | 3065 |
_ApplyContainerMods("NIC", nics, self._nic_chgdesc, self.nicmod, |
3066 |
self._CreateNewNic, self._ApplyNicMods, None) |
|
3066 |
self._CreateNewNic, self._ApplyNicMods, |
|
3067 |
self._RemoveNic) |
|
3067 | 3068 |
# Verify that NIC names are unique and valid |
3068 | 3069 |
utils.ValidateDeviceNames("NIC", nics) |
3069 | 3070 |
self._new_nics = nics |
... | ... | |
3233 | 3234 |
(idx, self.cfg.GetNodeName(pnode_uuid)), |
3234 | 3235 |
self.LogWarning) |
3235 | 3236 |
|
3237 |
def _HotplugDevice(self, action, dev_type, device, extra, seq): |
|
3238 |
self.LogInfo("Trying to hotplug device...") |
|
3239 |
result = self.rpc.call_hotplug_device(self.instance.primary_node, |
|
3240 |
self.instance, action, dev_type, |
|
3241 |
device, extra, seq) |
|
3242 |
if result.fail_msg: |
|
3243 |
self.LogWarning("Could not hotplug device: %s" % result.fail_msg) |
|
3244 |
self.LogInfo("Continuing execution..") |
|
3245 |
else: |
|
3246 |
self.LogInfo("Hotplug done.") |
|
3247 |
|
|
3236 | 3248 |
def _CreateNewDisk(self, idx, params, _): |
3237 | 3249 |
"""Creates a new disk. |
3238 | 3250 |
|
... | ... | |
3258 | 3270 |
disks=[(idx, disk, 0)], |
3259 | 3271 |
cleanup=new_disks) |
3260 | 3272 |
|
3273 |
if self.op.hotplug: |
|
3274 |
result = self.rpc.call_blockdev_assemble(self.instance.primary_node, |
|
3275 |
(disk, self.instance), |
|
3276 |
self.instance.name, True, idx) |
|
3277 |
if result.fail_msg: |
|
3278 |
self.LogWarning("Can't assemble newly created disk %d: %s", |
|
3279 |
idx, result.fail_msg) |
|
3280 |
else: |
|
3281 |
_, link_name = result.payload |
|
3282 |
self._HotplugDevice(constants.HOTPLUG_ACTION_ADD, |
|
3283 |
constants.HOTPLUG_TARGET_DISK, |
|
3284 |
disk, link_name, idx) |
|
3285 |
|
|
3261 | 3286 |
return (disk, [ |
3262 | 3287 |
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)), |
3263 | 3288 |
]) |
... | ... | |
3294 | 3319 |
"""Removes a disk. |
3295 | 3320 |
|
3296 | 3321 |
""" |
3322 |
if self.op.hotplug: |
|
3323 |
self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE, |
|
3324 |
constants.HOTPLUG_TARGET_DISK, |
|
3325 |
root, None, idx) |
|
3326 |
ShutdownInstanceDisks(self, self.instance, [root]) |
|
3327 |
|
|
3297 | 3328 |
(anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg) |
3298 | 3329 |
for node_uuid, disk in anno_disk.ComputeNodeTree( |
3299 | 3330 |
self.instance.primary_node): |
... | ... | |
3323 | 3354 |
nicparams=nicparams) |
3324 | 3355 |
nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId()) |
3325 | 3356 |
|
3326 |
return (nobj, [ |
|
3357 |
if self.op.hotplug: |
|
3358 |
self._HotplugDevice(constants.HOTPLUG_ACTION_ADD, |
|
3359 |
constants.HOTPLUG_TARGET_NIC, |
|
3360 |
nobj, None, idx) |
|
3361 |
|
|
3362 |
desc = [ |
|
3327 | 3363 |
("nic.%d" % idx, |
3328 | 3364 |
"add:mac=%s,ip=%s,mode=%s,link=%s,network=%s" % |
3329 | 3365 |
(mac, ip, private.filled[constants.NIC_MODE], |
3330 |
private.filled[constants.NIC_LINK], |
|
3331 |
net)), |
|
3332 |
]) |
|
3366 |
private.filled[constants.NIC_LINK], net)), |
|
3367 |
] |
|
3368 |
|
|
3369 |
return (nobj, desc) |
|
3333 | 3370 |
|
3334 | 3371 |
def _ApplyNicMods(self, idx, nic, params, private): |
3335 | 3372 |
"""Modifies a network interface. |
... | ... | |
3354 | 3391 |
for (key, val) in nic.nicparams.items(): |
3355 | 3392 |
changes.append(("nic.%s/%d" % (key, idx), val)) |
3356 | 3393 |
|
3394 |
if self.op.hotplug: |
|
3395 |
self._HotplugDevice(constants.HOTPLUG_ACTION_MODIFY, |
|
3396 |
constants.HOTPLUG_TARGET_NIC, |
|
3397 |
nic, None, idx) |
|
3398 |
|
|
3357 | 3399 |
return changes |
3358 | 3400 |
|
3401 |
def _RemoveNic(self, idx, nic, _): |
|
3402 |
if self.op.hotplug: |
|
3403 |
self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE, |
|
3404 |
constants.HOTPLUG_TARGET_NIC, |
|
3405 |
nic, None, idx) |
|
3406 |
|
|
3359 | 3407 |
def Exec(self, feedback_fn): |
3360 | 3408 |
"""Modifies an instance. |
3361 | 3409 |
|
Also available in: Unified diff