Revision 74676af4

b/lib/cmdlib/instance.py
76 76
    ])))
77 77

  
78 78

  
79
def _DeviceHotplugable(dev):
80

  
81
  return dev.uuid is not None
82

  
83

  
79 84
def _CheckHostnameSane(lu, name):
80 85
  """Ensures that a given hostname resolves to a 'sane' name.
81 86

  
......
3028 3033
      # Operate on copies as this is still in prereq
3029 3034
      nics = [nic.Copy() for nic in self.instance.nics]
3030 3035
      _ApplyContainerMods("NIC", nics, self._nic_chgdesc, self.nicmod,
3031
                          self._CreateNewNic, self._ApplyNicMods, None)
3036
                          self._CreateNewNic, self._ApplyNicMods,
3037
                          self._RemoveNic)
3032 3038
      # Verify that NIC names are unique and valid
3033 3039
      utils.ValidateDeviceNames("NIC", nics)
3034 3040
      self._new_nics = nics
......
3203 3209
                        " continuing anyway: %s", idx,
3204 3210
                        self.cfg.GetNodeName(pnode_uuid), msg)
3205 3211

  
3212
  def _HotplugDevice(self, action, dev_type, device, extra, seq):
3213
    self.LogInfo("Trying to hotplug device...")
3214
    result = self.rpc.call_hotplug_device(self.instance.primary_node,
3215
                                          self.instance, action, dev_type,
3216
                                          device, extra, seq)
3217
    result.Raise("Could not hotplug device.")
3218
    self.LogInfo("Hotplug done.")
3219

  
3206 3220
  def _CreateNewDisk(self, idx, params, _):
3207 3221
    """Creates a new disk.
3208 3222

  
......
3228 3242
                         disks=[(idx, disk, 0)],
3229 3243
                         cleanup=new_disks)
3230 3244

  
3245
    if self.op.hotplug:
3246
      _, device_info = AssembleInstanceDisks(self, self.instance,
3247
                                             [disk], check=False)
3248
      _, _, dev_path = device_info[0]
3249
      self._HotplugDevice(constants.HOTPLUG_ADD, constants.HOTPLUG_DISK,
3250
                          disk, dev_path, idx)
3251

  
3231 3252
    return (disk, [
3232 3253
      ("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)),
3233 3254
      ])
......
3253 3274
    """Removes a disk.
3254 3275

  
3255 3276
    """
3277
    if self.op.hotplug and _DeviceHotplugable(root):
3278
      self._HotplugDevice(constants.HOTPLUG_REMOVE, constants.HOTPLUG_DISK,
3279
                          root, None, idx)
3280
      ShutdownInstanceDisks(self, self.instance, [root])
3281

  
3256 3282
    (anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg)
3257 3283
    for node_uuid, disk in anno_disk.ComputeNodeTree(
3258 3284
                             self.instance.primary_node):
......
3282 3308
                       nicparams=nicparams)
3283 3309
    nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId())
3284 3310

  
3285
    return (nobj, [
3311
    if self.op.hotplug:
3312
      self._HotplugDevice(constants.HOTPLUG_ADD, constants.HOTPLUG_NIC,
3313
                          nobj, None, idx)
3314

  
3315
    desc =  [
3286 3316
      ("nic.%d" % idx,
3287 3317
       "add:mac=%s,ip=%s,mode=%s,link=%s,network=%s" %
3288 3318
       (mac, ip, private.filled[constants.NIC_MODE],
3289
       private.filled[constants.NIC_LINK],
3290
       net)),
3291
      ])
3319
       private.filled[constants.NIC_LINK], net)),
3320
      ]
3321

  
3322
    return (nobj, desc)
3292 3323

  
3293 3324
  def _ApplyNicMods(self, idx, nic, params, private):
3294 3325
    """Modifies a network interface.
......
3313 3344
      for (key, val) in nic.nicparams.items():
3314 3345
        changes.append(("nic.%s/%d" % (key, idx), val))
3315 3346

  
3347
    if self.op.hotplug and _DeviceHotplugable(nic):
3348
      self._HotplugDevice(constants.HOTPLUG_REMOVE, constants.HOTPLUG_NIC,
3349
                          nic, None, idx)
3350
      self._HotplugDevice(constants.HOTPLUG_ADD, constants.HOTPLUG_NIC,
3351
                          nic, None, idx)
3352

  
3316 3353
    return changes
3317 3354

  
3355
  def _RemoveNic(self, idx, nic, _):
3356
    if self.op.hotplug and _DeviceHotplugable(nic):
3357
      self._HotplugDevice(constants.HOTPLUG_REMOVE, constants.HOTPLUG_NIC,
3358
                          nic, None, idx)
3359

  
3318 3360
  def Exec(self, feedback_fn):
3319 3361
    """Modifies an instance.
3320 3362

  
b/lib/cmdlib/instance_storage.py
1259 1259

  
1260 1260

  
1261 1261
def AssembleInstanceDisks(lu, instance, disks=None, ignore_secondaries=False,
1262
                           ignore_size=False):
1262
                          ignore_size=False, check=True):
1263 1263
  """Prepare the block devices for an instance.
1264 1264

  
1265 1265
  This sets up the block devices on all nodes.
......
1284 1284
  """
1285 1285
  device_info = []
1286 1286
  disks_ok = True
1287
  disks = ExpandCheckDisks(instance, disks)
1287
  if check:
1288
    disks = ExpandCheckDisks(instance, disks)
1288 1289

  
1289 1290
  # With the two passes mechanism we try to reduce the window of
1290 1291
  # opportunity for the race condition of switching DRBD to primary

Also available in: Unified diff