Revision b768099e

b/lib/cmdlib.py
5524 5524
    """Recreate the disks.
5525 5525

  
5526 5526
    """
5527
    # change primary node, if needed
5528
    if self.op.nodes:
5529
      self.instance.primary_node = self.op.nodes[0]
5530
      self.LogWarning("Changing the instance's nodes, you will have to"
5531
                      " remove any disks left on the older nodes manually")
5527
    instance = self.instance
5532 5528

  
5533 5529
    to_skip = []
5534
    for idx, disk in enumerate(self.instance.disks):
5530
    mods = [] # keeps track of needed logical_id changes
5531

  
5532
    for idx, disk in enumerate(instance.disks):
5535 5533
      if idx not in self.op.disks: # disk idx has not been passed in
5536 5534
        to_skip.append(idx)
5537 5535
        continue
5538 5536
      # update secondaries for disks, if needed
5539 5537
      if self.op.nodes:
5540 5538
        if disk.dev_type == constants.LD_DRBD8:
5541
          # need to update the nodes
5539
          # need to update the nodes and minors
5542 5540
          assert len(self.op.nodes) == 2
5543
          logical_id = list(disk.logical_id)
5544
          logical_id[0] = self.op.nodes[0]
5545
          logical_id[1] = self.op.nodes[1]
5546
          disk.logical_id = tuple(logical_id)
5541
          assert len(disk.logical_id) == 6 # otherwise disk internals
5542
                                           # have changed
5543
          (_, _, old_port, _, _, old_secret) = disk.logical_id
5544
          new_minors = self.cfg.AllocateDRBDMinor(self.op.nodes, instance.name)
5545
          new_id = (self.op.nodes[0], self.op.nodes[1], old_port,
5546
                    new_minors[0], new_minors[1], old_secret)
5547
          assert len(disk.logical_id) == len(new_id)
5548
          mods.append((idx, new_id))
5549

  
5550
    # now that we have passed all asserts above, we can apply the mods
5551
    # in a single run (to avoid partial changes)
5552
    for idx, new_id in mods:
5553
      instance.disks[idx].logical_id = new_id
5554

  
5555
    # change primary node, if needed
5556
    if self.op.nodes:
5557
      instance.primary_node = self.op.nodes[0]
5558
      self.LogWarning("Changing the instance's nodes, you will have to"
5559
                      " remove any disks left on the older nodes manually")
5547 5560

  
5548 5561
    if self.op.nodes:
5549
      self.cfg.Update(self.instance, feedback_fn)
5562
      self.cfg.Update(instance, feedback_fn)
5550 5563

  
5551
    _CreateDisks(self, self.instance, to_skip=to_skip)
5564
    _CreateDisks(self, instance, to_skip=to_skip)
5552 5565

  
5553 5566

  
5554 5567
class LUInstanceRename(LogicalUnit):

Also available in: Unified diff