Revision fc5bb0fe lib/cmdlib.py

b/lib/cmdlib.py
8574 8574
        return self._ExecMigration()
8575 8575

  
8576 8576

  
8577
def _CreateBlockDev(lu, node, instance, device, force_create,
8578
                    info, force_open):
8577
def _CreateBlockDev(lu, node, instance, device, force_create, info,
8578
                    force_open):
8579
  """Wrapper around L{_CreateBlockDevInner}.
8580

  
8581
  This method annotates the root device first.
8582

  
8583
  """
8584
  (disk,) = _AnnotateDiskParams(instance, [device], lu.cfg)
8585
  return _CreateBlockDevInner(lu, node, instance, disk, force_create, info,
8586
                              force_open)
8587

  
8588

  
8589
def _CreateBlockDevInner(lu, node, instance, device, force_create,
8590
                         info, force_open):
8579 8591
  """Create a tree of block devices on a given node.
8580 8592

  
8581 8593
  If this device type has to be created on secondaries, create it and
......
8583 8595

  
8584 8596
  If not, just recurse to children keeping the same 'force' value.
8585 8597

  
8598
  @attention: The device has to be annotated already.
8599

  
8586 8600
  @param lu: the lu on whose behalf we execute
8587 8601
  @param node: the node on which to create the device
8588 8602
  @type instance: L{objects.Instance}
......
8607 8621

  
8608 8622
  if device.children:
8609 8623
    for child in device.children:
8610
      _CreateBlockDev(lu, node, instance, child, force_create,
8611
                      info, force_open)
8624
      _CreateBlockDevInner(lu, node, instance, child, force_create,
8625
                           info, force_open)
8612 8626

  
8613 8627
  if not force_create:
8614 8628
    return
......
10797 10811
    """
10798 10812
    iv_names = {}
10799 10813

  
10800
    for idx, dev in enumerate(self.instance.disks):
10814
    disks = _AnnotateDiskParams(self.instance, self.instance.disks, self.cfg)
10815
    for idx, dev in enumerate(disks):
10801 10816
      if idx not in self.disks:
10802 10817
        continue
10803 10818

  
......
10808 10823
      lv_names = [".disk%d_%s" % (idx, suffix) for suffix in ["data", "meta"]]
10809 10824
      names = _GenerateUniqueNames(self.lu, lv_names)
10810 10825

  
10811
      vg_data = dev.children[0].logical_id[0]
10826
      (data_disk, meta_disk) = dev.children
10827
      vg_data = data_disk.logical_id[0]
10812 10828
      lv_data = objects.Disk(dev_type=constants.LD_LV, size=dev.size,
10813
                             logical_id=(vg_data, names[0]), params={})
10814
      vg_meta = dev.children[1].logical_id[0]
10829
                             logical_id=(vg_data, names[0]),
10830
                             params=data_disk.params)
10831
      vg_meta = meta_disk.logical_id[0]
10815 10832
      lv_meta = objects.Disk(dev_type=constants.LD_LV, size=DRBD_META_SIZE,
10816
                             logical_id=(vg_meta, names[1]), params={})
10833
                             logical_id=(vg_meta, names[1]),
10834
                             params=meta_disk.params)
10817 10835

  
10818 10836
      new_lvs = [lv_data, lv_meta]
10819 10837
      old_lvs = [child.Copy() for child in dev.children]
......
10821 10839

  
10822 10840
      # we pass force_create=True to force the LVM creation
10823 10841
      for new_lv in new_lvs:
10824
        _CreateBlockDev(self.lu, node_name, self.instance, new_lv, True,
10825
                        _GetInstanceInfoText(self.instance), False)
10842
        _CreateBlockDevInner(self.lu, node_name, self.instance, new_lv, True,
10843
                             _GetInstanceInfoText(self.instance), False)
10826 10844

  
10827 10845
    return iv_names
10828 10846

  
......
11031 11049

  
11032 11050
    # Step: create new storage
11033 11051
    self.lu.LogStep(3, steps_total, "Allocate new storage")
11034
    for idx, dev in enumerate(self.instance.disks):
11052
    disks = _AnnotateDiskParams(self.instance, self.instance.disks, self.cfg)
11053
    for idx, dev in enumerate(disks):
11035 11054
      self.lu.LogInfo("Adding new local storage on %s for disk/%d" %
11036 11055
                      (self.new_node, idx))
11037 11056
      # we pass force_create=True to force LVM creation
11038 11057
      for new_lv in dev.children:
11039
        _CreateBlockDev(self.lu, self.new_node, self.instance, new_lv, True,
11040
                        _GetInstanceInfoText(self.instance), False)
11058
        _CreateBlockDevInner(self.lu, self.new_node, self.instance, new_lv,
11059
                             True, _GetInstanceInfoText(self.instance), False)
11041 11060

  
11042 11061
    # Step 4: dbrd minors and drbd setups changes
11043 11062
    # after this, we must manually remove the drbd minors on both the
......
11076 11095
                              children=dev.children,
11077 11096
                              size=dev.size,
11078 11097
                              params={})
11098
      (anno_new_drbd,) = _AnnotateDiskParams(self.instance, [new_drbd],
11099
                                             self.cfg)
11079 11100
      try:
11080
        _CreateSingleBlockDev(self.lu, self.new_node, self.instance, new_drbd,
11101
        _CreateSingleBlockDev(self.lu, self.new_node, self.instance,
11102
                              anno_new_drbd,
11081 11103
                              _GetInstanceInfoText(self.instance), False)
11082 11104
      except errors.GenericError:
11083 11105
        self.cfg.ReleaseDRBDMinors(self.instance.name)
......
12553 12575
                                      instance.name, pnode, [snode],
12554 12576
                                      disk_info, None, None, 0, feedback_fn,
12555 12577
                                      self.diskparams)
12578
    anno_disks = rpc.AnnotateDiskParams(constants.DT_DRBD8, new_disks,
12579
                                        self.diskparams)
12556 12580
    info = _GetInstanceInfoText(instance)
12557 12581
    feedback_fn("Creating additional volumes...")
12558 12582
    # first, create the missing data and meta devices
12559
    for disk in new_disks:
12583
    for disk in anno_disks:
12560 12584
      # unfortunately this is... not too nice
12561 12585
      _CreateSingleBlockDev(self, pnode, instance, disk.children[1],
12562 12586
                            info, True)
......
12572 12596

  
12573 12597
    feedback_fn("Initializing DRBD devices...")
12574 12598
    # all child devices are in place, we can now create the DRBD devices
12575
    for disk in new_disks:
12599
    for disk in anno_disks:
12576 12600
      for node in [pnode, snode]:
12577 12601
        f_create = node == pnode
12578 12602
        _CreateSingleBlockDev(self, node, instance, disk, info, f_create)

Also available in: Unified diff