Revision e15a00dc lib/cmdlib/instance.py

b/lib/cmdlib/instance.py
2228 2228
      if op == constants.DDM_REMOVE:
2229 2229
        assert not params
2230 2230

  
2231
        if remove_fn is not None:
2232
          remove_fn(absidx, item, private)
2233

  
2234 2231
        changes = [("%s/%s" % (kind, absidx), "remove")]
2235 2232

  
2233
        if remove_fn is not None:
2234
          msg = remove_fn(absidx, item, private)
2235
          if msg:
2236
            changes.append(("%s/%s" % (kind, absidx), msg))
2237

  
2236 2238
        assert container[absidx] == item
2237 2239
        del container[absidx]
2238 2240
      elif op == constants.DDM_MODIFY:
......
3236 3238

  
3237 3239
  def _HotplugDevice(self, action, dev_type, device, extra, seq):
3238 3240
    self.LogInfo("Trying to hotplug device...")
3241
    msg = "hotplug:"
3239 3242
    result = self.rpc.call_hotplug_device(self.instance.primary_node,
3240 3243
                                          self.instance, action, dev_type,
3241 3244
                                          (device, self.instance),
......
3243 3246
    if result.fail_msg:
3244 3247
      self.LogWarning("Could not hotplug device: %s" % result.fail_msg)
3245 3248
      self.LogInfo("Continuing execution..")
3249
      msg += "failed"
3246 3250
    else:
3247 3251
      self.LogInfo("Hotplug done.")
3252
      msg += "done"
3253
    return msg
3248 3254

  
3249 3255
  def _CreateNewDisk(self, idx, params, _):
3250 3256
    """Creates a new disk.
......
3271 3277
                         disks=[(idx, disk, 0)],
3272 3278
                         cleanup=new_disks)
3273 3279

  
3280
    changes = [
3281
      ("disk/%d" % idx,
3282
      "add:size=%s,mode=%s" % (disk.size, disk.mode)),
3283
      ]
3274 3284
    if self.op.hotplug:
3275 3285
      result = self.rpc.call_blockdev_assemble(self.instance.primary_node,
3276 3286
                                               (disk, self.instance),
3277 3287
                                               self.instance.name, True, idx)
3278 3288
      if result.fail_msg:
3289
        changes.append(("disk/%d" % idx, "assemble:failed"))
3279 3290
        self.LogWarning("Can't assemble newly created disk %d: %s",
3280 3291
                        idx, result.fail_msg)
3281 3292
      else:
3282 3293
        _, link_name = result.payload
3283
        self._HotplugDevice(constants.HOTPLUG_ACTION_ADD,
3284
                            constants.HOTPLUG_TARGET_DISK,
3285
                            disk, link_name, idx)
3294
        msg = self._HotplugDevice(constants.HOTPLUG_ACTION_ADD,
3295
                                  constants.HOTPLUG_TARGET_DISK,
3296
                                  disk, link_name, idx)
3297
        changes.append(("disk/%d" % idx, msg))
3286 3298

  
3287
    return (disk, [
3288
      ("disk/%d" % idx, "add:size=%s,mode=%s" % (disk.size, disk.mode)),
3289
      ])
3299
    return (disk, changes)
3290 3300

  
3291 3301
  def _PostAddDisk(self, _, disk):
3292 3302
    if not WaitForSync(self, self.instance, disks=[disk],
......
3320 3330
    """Removes a disk.
3321 3331

  
3322 3332
    """
3333
    hotmsg = ""
3323 3334
    if self.op.hotplug:
3324
      self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
3325
                          constants.HOTPLUG_TARGET_DISK,
3326
                          root, None, idx)
3335
      hotmsg = self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
3336
                                   constants.HOTPLUG_TARGET_DISK,
3337
                                   root, None, idx)
3327 3338
      ShutdownInstanceDisks(self, self.instance, [root])
3328 3339

  
3329 3340
    (anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg)
......
3340 3351
    if root.dev_type in constants.DTS_DRBD:
3341 3352
      self.cfg.AddTcpUdpPort(root.logical_id[2])
3342 3353

  
3354
    return hotmsg
3355

  
3343 3356
  def _CreateNewNic(self, idx, params, private):
3344 3357
    """Creates data structure for a new network interface.
3345 3358

  
......
3355 3368
                       nicparams=nicparams)
3356 3369
    nobj.uuid = self.cfg.GenerateUniqueID(self.proc.GetECId())
3357 3370

  
3358
    if self.op.hotplug:
3359
      self._HotplugDevice(constants.HOTPLUG_ACTION_ADD,
3360
                          constants.HOTPLUG_TARGET_NIC,
3361
                          nobj, None, idx)
3362

  
3363
    desc = [
3371
    changes = [
3364 3372
      ("nic.%d" % idx,
3365 3373
       "add:mac=%s,ip=%s,mode=%s,link=%s,network=%s" %
3366 3374
       (mac, ip, private.filled[constants.NIC_MODE],
3367 3375
       private.filled[constants.NIC_LINK], net)),
3368 3376
      ]
3369 3377

  
3370
    return (nobj, desc)
3378
    if self.op.hotplug:
3379
      msg = self._HotplugDevice(constants.HOTPLUG_ACTION_ADD,
3380
                                constants.HOTPLUG_TARGET_NIC,
3381
                                nobj, None, idx)
3382
      changes.append(("nic.%d" % idx, msg))
3383

  
3384
    return (nobj, changes)
3371 3385

  
3372 3386
  def _ApplyNicMods(self, idx, nic, params, private):
3373 3387
    """Modifies a network interface.
......
3393 3407
        changes.append(("nic.%s/%d" % (key, idx), val))
3394 3408

  
3395 3409
    if self.op.hotplug:
3396
      self._HotplugDevice(constants.HOTPLUG_ACTION_MODIFY,
3397
                          constants.HOTPLUG_TARGET_NIC,
3398
                          nic, None, idx)
3410
      msg = self._HotplugDevice(constants.HOTPLUG_ACTION_MODIFY,
3411
                                constants.HOTPLUG_TARGET_NIC,
3412
                                nic, None, idx)
3413
      changes.append(("nic/%d" % idx, msg))
3399 3414

  
3400 3415
    return changes
3401 3416

  
3402 3417
  def _RemoveNic(self, idx, nic, _):
3403 3418
    if self.op.hotplug:
3404
      self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
3405
                          constants.HOTPLUG_TARGET_NIC,
3406
                          nic, None, idx)
3419
      return self._HotplugDevice(constants.HOTPLUG_ACTION_REMOVE,
3420
                                 constants.HOTPLUG_TARGET_NIC,
3421
                                 nic, None, idx)
3407 3422

  
3408 3423
  def Exec(self, feedback_fn):
3409 3424
    """Modifies an instance.

Also available in: Unified diff