Revision 98d0b695 lib/cmdlib/instance.py
b/lib/cmdlib/instance.py | ||
---|---|---|
75 | 75 |
]))) |
76 | 76 |
|
77 | 77 |
|
78 |
def _DeviceHotplugable(dev): |
|
79 |
|
|
80 |
return dev.uuid is not None |
|
81 |
|
|
82 |
|
|
78 | 83 |
def _CheckHostnameSane(lu, name): |
79 | 84 |
"""Ensures that a given hostname resolves to a 'sane' name. |
80 | 85 |
|
... | ... | |
2979 | 2984 |
# Operate on copies as this is still in prereq |
2980 | 2985 |
nics = [nic.Copy() for nic in self.instance.nics] |
2981 | 2986 |
_ApplyContainerMods("NIC", nics, self._nic_chgdesc, self.nicmod, |
2982 |
self._CreateNewNic, self._ApplyNicMods, None) |
|
2987 |
self._CreateNewNic, self._ApplyNicMods, |
|
2988 |
self._RemoveNic) |
|
2983 | 2989 |
# Verify that NIC names are unique and valid |
2984 | 2990 |
utils.ValidateDeviceNames("NIC", nics) |
2985 | 2991 |
self._new_nics = nics |
... | ... | |
3154 | 3160 |
" continuing anyway: %s", idx, |
3155 | 3161 |
self.cfg.GetNodeName(pnode_uuid), msg) |
3156 | 3162 |
|
3163 |
def _HotplugDevice(self, action, dev_type, device, extra, seq): |
|
3164 |
self.LogInfo("Trying to hotplug device...") |
|
3165 |
result = self.rpc.call_hotplug_device(self.instance.primary_node, |
|
3166 |
self.instance, action, dev_type, |
|
3167 |
device, extra, seq) |
|
3168 |
result.Raise("Could not hotplug device.") |
|
3169 |
self.LogInfo("Hotplug done.") |
|
3170 |
|
|
3157 | 3171 |
def _CreateNewDisk(self, idx, params, _): |
3158 | 3172 |
"""Creates a new disk. |
3159 | 3173 |
|
... | ... | |
3179 | 3193 |
disks=[(idx, disk, 0)], |
3180 | 3194 |
cleanup=new_disks) |
3181 | 3195 |
|
3196 |
if self.op.hotplug: |
|
3197 |
_, device_info = AssembleInstanceDisks(self, self.instance, |
|
3198 |
[disk], check=False) |
|
3199 |
_, _, dev_path = device_info[0] |
|
3200 |
self._HotplugDevice("ADD", "DISK", disk, dev_path, idx) |
|
3201 |
|
|
3182 | 3202 |
return (disk, [ |
3183 | 3203 |
("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)), |
3184 | 3204 |
]) |
... | ... | |
3204 | 3224 |
"""Removes a disk. |
3205 | 3225 |
|
3206 | 3226 |
""" |
3227 |
if self.op.hotplug and _DeviceHotplugable(root): |
|
3228 |
self._HotplugDevice("REMOVE", "DISK", root, None, idx) |
|
3229 |
ShutdownInstanceDisks(self, self.instance, [root]) |
|
3230 |
|
|
3207 | 3231 |
(anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg) |
3208 | 3232 |
for node_uuid, disk in anno_disk.ComputeNodeTree( |
3209 | 3233 |
self.instance.primary_node): |
... | ... | |
3233 | 3257 |
nicparams=nicparams) |
3234 | 3258 |
nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId()) |
3235 | 3259 |
|
3236 |
return (nobj, [ |
|
3260 |
if self.op.hotplug: |
|
3261 |
self._HotplugDevice("ADD", "NIC", nobj, None, idx) |
|
3262 |
|
|
3263 |
desc = [ |
|
3237 | 3264 |
("nic.%d" % idx, |
3238 | 3265 |
"add:mac=%s,ip=%s,mode=%s,link=%s,network=%s" % |
3239 | 3266 |
(mac, ip, private.filled[constants.NIC_MODE], |
3240 |
private.filled[constants.NIC_LINK], |
|
3241 |
net)), |
|
3242 |
]) |
|
3267 |
private.filled[constants.NIC_LINK], net)), |
|
3268 |
] |
|
3269 |
|
|
3270 |
return (nobj, desc) |
|
3243 | 3271 |
|
3244 | 3272 |
def _ApplyNicMods(self, idx, nic, params, private): |
3245 | 3273 |
"""Modifies a network interface. |
... | ... | |
3264 | 3292 |
for (key, val) in nic.nicparams.items(): |
3265 | 3293 |
changes.append(("nic.%s/%d" % (key, idx), val)) |
3266 | 3294 |
|
3295 |
if self.op.hotplug and _DeviceHotplugable(nic): |
|
3296 |
self._HotplugDevice("REMOVE", "NIC", nic, None, idx) |
|
3297 |
self._HotplugDevice("ADD", "NIC", nic, None, idx) |
|
3298 |
|
|
3267 | 3299 |
return changes |
3268 | 3300 |
|
3301 |
def _RemoveNic(self, idx, nic, _): |
|
3302 |
if self.op.hotplug and _DeviceHotplugable(nic): |
|
3303 |
self._HotplugDevice("REMOVE", "NIC", nic, None, idx) |
|
3304 |
|
|
3269 | 3305 |
def Exec(self, feedback_fn): |
3270 | 3306 |
"""Modifies an instance. |
3271 | 3307 |
|
Also available in: Unified diff