Revision 99452998 lib/cmdlib/instance.py
b/lib/cmdlib/instance.py | ||
---|---|---|
1807 | 1807 |
idx, result.fail_msg) |
1808 | 1808 |
errs.append(result.fail_msg) |
1809 | 1809 |
break |
1810 |
dev_path = result.payload |
|
1810 |
dev_path, _ = result.payload
|
|
1811 | 1811 |
result = self.rpc.call_blockdev_export(source_node, (disk, instance), |
1812 | 1812 |
target_node, dev_path, |
1813 | 1813 |
cluster_name) |
... | ... | |
2977 | 2977 |
# Operate on copies as this is still in prereq |
2978 | 2978 |
nics = [nic.Copy() for nic in instance.nics] |
2979 | 2979 |
_ApplyContainerMods("NIC", nics, self._nic_chgdesc, self.nicmod, |
2980 |
self._CreateNewNic, self._ApplyNicMods, None) |
|
2980 |
self._CreateNewNic, self._ApplyNicMods, |
|
2981 |
self._RemoveNic) |
|
2981 | 2982 |
# Verify that NIC names are unique and valid |
2982 | 2983 |
utils.ValidateDeviceNames("NIC", nics) |
2983 | 2984 |
self._new_nics = nics |
... | ... | |
3152 | 3153 |
self.LogWarning("Could not remove metadata for disk %d on node %s," |
3153 | 3154 |
" continuing anyway: %s", idx, pnode, msg) |
3154 | 3155 |
|
3156 |
def _HotplugDevice(self, action, dev_type, device, extra, seq): |
|
3157 |
self.LogInfo("Trying to hotplug device...") |
|
3158 |
result = self.rpc.call_hotplug_device(self.instance.primary_node, |
|
3159 |
self.instance, action, dev_type, |
|
3160 |
device, extra, seq) |
|
3161 |
if result.fail_msg: |
|
3162 |
self.LogWarning("Could not hotplug device: %s" % result.fail_msg) |
|
3163 |
self.LogInfo("Continuing execution..") |
|
3164 |
else: |
|
3165 |
self.LogInfo("Hotplug done.") |
|
3166 |
|
|
3155 | 3167 |
def _CreateNewDisk(self, idx, params, _): |
3156 | 3168 |
"""Creates a new disk. |
3157 | 3169 |
|
... | ... | |
3179 | 3191 |
disks=[(idx, disk, 0)], |
3180 | 3192 |
cleanup=new_disks) |
3181 | 3193 |
|
3194 |
if self.op.hotplug: |
|
3195 |
result = self.rpc.call_blockdev_assemble(self.instance.primary_node, |
|
3196 |
(disk, self.instance), |
|
3197 |
self.instance.name, True, idx) |
|
3198 |
if result.fail_msg: |
|
3199 |
self.LogWarning("Can't assemble newly created disk %d: %s", |
|
3200 |
idx, result.fail_msg) |
|
3201 |
else: |
|
3202 |
_, link_name = result.payload |
|
3203 |
self._HotplugDevice(constants.HOTPLUG_ACTION_ADD, |
|
3204 |
constants.HOTPLUG_TARGET_DISK, |
|
3205 |
disk, link_name, idx) |
|
3206 |
|
|
3182 | 3207 |
return (disk, [ |
3183 | 3208 |
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)), |
3184 | 3209 |
]) |
... | ... | |
3216 | 3241 |
"""Removes a disk. |
3217 | 3242 |
|
3218 | 3243 |
""" |
3244 |
if self.op.hotplug: |
|
3245 |
self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE, |
|
3246 |
constants.HOTPLUG_TARGET_DISK, |
|
3247 |
root, None, idx) |
|
3248 |
ShutdownInstanceDisks(self, self.instance, [root]) |
|
3249 |
|
|
3219 | 3250 |
(anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg) |
3220 | 3251 |
for node, disk in anno_disk.ComputeNodeTree(self.instance.primary_node): |
3221 | 3252 |
self.cfg.SetDiskID(disk, node) |
... | ... | |
3243 | 3274 |
nicparams=nicparams) |
3244 | 3275 |
nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId()) |
3245 | 3276 |
|
3246 |
return (nobj, [ |
|
3277 |
if self.op.hotplug: |
|
3278 |
self._HotplugDevice(constants.HOTPLUG_ACTION_ADD, |
|
3279 |
constants.HOTPLUG_TARGET_NIC, |
|
3280 |
nobj, None, idx) |
|
3281 |
|
|
3282 |
desc = [ |
|
3247 | 3283 |
("nic.%d" % idx, |
3248 | 3284 |
"add:mac=%s,ip=%s,mode=%s,link=%s,network=%s" % |
3249 | 3285 |
(mac, ip, private.filled[constants.NIC_MODE], |
3250 |
private.filled[constants.NIC_LINK], |
|
3251 |
net)), |
|
3252 |
]) |
|
3286 |
private.filled[constants.NIC_LINK], net)), |
|
3287 |
] |
|
3288 |
|
|
3289 |
return (nobj, desc) |
|
3253 | 3290 |
|
3254 | 3291 |
def _ApplyNicMods(self, idx, nic, params, private): |
3255 | 3292 |
"""Modifies a network interface. |
... | ... | |
3274 | 3311 |
for (key, val) in nic.nicparams.items(): |
3275 | 3312 |
changes.append(("nic.%s/%d" % (key, idx), val)) |
3276 | 3313 |
|
3314 |
if self.op.hotplug: |
|
3315 |
self._HotplugDevice(constants.HOTPLUG_ACTION_MODIFY, |
|
3316 |
constants.HOTPLUG_TARGET_NIC, |
|
3317 |
nic, None, idx) |
|
3318 |
|
|
3277 | 3319 |
return changes |
3278 | 3320 |
|
3321 |
def _RemoveNic(self, idx, nic, _): |
|
3322 |
if self.op.hotplug: |
|
3323 |
self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE, |
|
3324 |
constants.HOTPLUG_TARGET_NIC, |
|
3325 |
nic, None, idx) |
|
3326 |
|
|
3279 | 3327 |
def Exec(self, feedback_fn): |
3280 | 3328 |
"""Modifies an instance. |
3281 | 3329 |
|
Also available in: Unified diff