Revision 428958aa lib/cmdlib.py

b/lib/cmdlib.py
3691 3691
      return self._ExecMigration()
3692 3692

  
3693 3693

  
3694
def _CreateBlockDevOnPrimary(lu, node, instance, device, info):
3695
  """Create a tree of block devices on the primary node.
3696

  
3697
  This always creates all devices.
3698

  
3699
  """
3700
  if device.children:
3701
    for child in device.children:
3702
      _CreateBlockDevOnPrimary(lu, node, instance, child, info)
3703

  
3704
  lu.cfg.SetDiskID(device, node)
3705
  result = lu.rpc.call_blockdev_create(node, device, device.size,
3706
                                       instance.name, True, info)
3707
  msg = result.RemoteFailMsg()
3708
  if msg:
3709
    raise errors.OpExecError("Can't create block device %s on primary"
3710
                             " node %s: %s" % (device, node, msg))
3711
  if device.physical_id is None:
3712
    device.physical_id = result.data[1]
3713

  
3714

  
3715
def _CreateBlockDevOnSecondary(lu, node, instance, device, force, info):
3716
  """Create a tree of block devices on a secondary node.
3694
def _CreateBlockDev(lu, node, instance, device, force_create,
3695
                    info, force_open):
3696
  """Create a tree of block devices on a given node.
3717 3697

  
3718 3698
  If this device type has to be created on secondaries, create it and
3719 3699
  all its children.
3720 3700

  
3721 3701
  If not, just recurse to children keeping the same 'force' value.
3722 3702

  
3703
  @param lu: the lu on whose behalf we execute
3704
  @param node: the node on which to create the device
3705
  @type instance: L{objects.Instance}
3706
  @param instance: the instance which owns the device
3707
  @type device: L{objects.Disk}
3708
  @param device: the device to create
3709
  @type force_create: boolean
3710
  @param force_create: whether to force creation of this device; this
3711
      will be change to True whenever we find a device which has
3712
      CreateOnSecondary() attribute
3713
  @param info: the extra 'metadata' we should attach to the device
3714
      (this will be represented as a LVM tag)
3715
  @type force_open: boolean
3716
  @param force_open: this parameter will be passes to the
3717
      L{backend.CreateBlockDevice} function where it specifies
3718
      whether we run on primary or not, and it affects both
3719
      the child assembly and the device own Open() execution
3720

  
3723 3721
  """
3724 3722
  if device.CreateOnSecondary():
3725
    force = True
3723
    force_create = True
3726 3724

  
3727 3725
  if device.children:
3728 3726
    for child in device.children:
3729
      _CreateBlockDevOnSecondary(lu, node, instance, child, force, info)
3727
      _CreateBlockDev(lu, node, instance, child, force_create,
3728
                      info, force_open)
3730 3729

  
3731
  if not force:
3730
  if not force_create:
3732 3731
    return
3733 3732

  
3734 3733
  lu.cfg.SetDiskID(device, node)
3735 3734
  new_id = lu.rpc.call_blockdev_create(node, device, device.size,
3736
                                       instance.name, False, info)
3735
                                       instance.name, force_open, info)
3737 3736
  if new_id.failed or not new_id.data:
3738
    raise errors.OpExecError("Can't create block device %s on secondary"
3737
    raise errors.OpExecError("Can't create block device %s on"
3739 3738
                             " node %s" % (device, node))
3740 3739
  if device.physical_id is None:
3741 3740
    device.physical_id = new_id
......
3859 3858

  
3860 3859
  """
3861 3860
  info = _GetInstanceInfoText(instance)
3861
  pnode = instance.primary_node
3862 3862

  
3863 3863
  if instance.disk_template == constants.DT_FILE:
3864 3864
    file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
3865
    result = lu.rpc.call_file_storage_dir_create(instance.primary_node,
3866
                                                 file_storage_dir)
3865
    result = lu.rpc.call_file_storage_dir_create(pnode, file_storage_dir)
3867 3866

  
3868 3867
    if result.failed or not result.data:
3869
      raise errors.OpExecError("Could not connect to node '%s'" %
3870
                               instance.primary_node)
3868
      raise errors.OpExecError("Could not connect to node '%s'" % pnode)
3871 3869

  
3872 3870
    if not result.data[0]:
3873 3871
      raise errors.OpExecError("Failed to create directory '%s'" %
......
3879 3877
    logging.info("Creating volume %s for instance %s",
3880 3878
                 device.iv_name, instance.name)
3881 3879
    #HARDCODE
3882
    for secondary_node in instance.secondary_nodes:
3883
      _CreateBlockDevOnSecondary(lu, secondary_node, instance,
3884
                                 device, False, info)
3885
    #HARDCODE
3886
    _CreateBlockDevOnPrimary(lu, instance.primary_node,
3887
                             instance, device, info)
3880
    for node in instance.all_nodes:
3881
      f_create = node == pnode
3882
      _CreateBlockDev(lu, node, instance, device, f_create, info, f_create)
3888 3883

  
3889 3884

  
3890 3885
def _RemoveDisks(lu, instance):
......
4821 4816
      iv_names[dev.iv_name] = (dev, old_lvs, new_lvs)
4822 4817
      info("creating new local storage on %s for %s" %
4823 4818
           (tgt_node, dev.iv_name))
4824
      # since we *always* want to create this LV, we use the
4825
      # _Create...OnPrimary (which forces the creation), even if we
4826
      # are talking about the secondary node
4819
      # we pass force_create=True to force the LVM creation
4827 4820
      for new_lv in new_lvs:
4828
        _CreateBlockDevOnPrimary(self, tgt_node, instance, new_lv,
4829
                                 _GetInstanceInfoText(instance))
4821
        _CreateBlockDev(self, tgt_node, instance, new_lv, True,
4822
                        _GetInstanceInfoText(instance), False)
4830 4823

  
4831 4824
    # Step: for each lv, detach+rename*2+attach
4832 4825
    self.proc.LogStep(4, steps_total, "change drbd configuration")
......
4989 4982
    for idx, dev in enumerate(instance.disks):
4990 4983
      info("adding new local storage on %s for disk/%d" %
4991 4984
           (new_node, idx))
4992
      # since we *always* want to create this LV, we use the
4993
      # _Create...OnPrimary (which forces the creation), even if we
4994
      # are talking about the secondary node
4985
      # we pass force_create=True to force LVM creation
4995 4986
      for new_lv in dev.children:
4996
        _CreateBlockDevOnPrimary(self, new_node, instance, new_lv,
4997
                                 _GetInstanceInfoText(instance))
4987
        _CreateBlockDev(self, new_node, instance, new_lv, True,
4988
                        _GetInstanceInfoText(instance), False)
4998 4989

  
4999 4990
    # Step 4: dbrd minors and drbd setups changes
5000 4991
    # after this, we must manually remove the drbd minors on both the
......
5026 5017
                              logical_id=new_alone_id,
5027 5018
                              children=dev.children)
5028 5019
      try:
5029
        _CreateBlockDevOnSecondary(self, new_node, instance, new_drbd, False,
5030
                                   _GetInstanceInfoText(instance))
5020
        _CreateBlockDev(self, new_node, instance, new_drbd, False,
5021
                        _GetInstanceInfoText(instance), False)
5031 5022
      except error.BlockDeviceError:
5032 5023
        self.cfg.ReleaseDRBDMinors(instance.name)
5033 5024
        raise
......
5690 5681
                     new_disk.iv_name, instance.name)
5691 5682
        # Note: this needs to be kept in sync with _CreateDisks
5692 5683
        #HARDCODE
5693
        for secondary_node in instance.secondary_nodes:
5684
        for node in instance.all_nodes:
5685
          f_create = node == instance.primary_node
5694 5686
          try:
5695
            _CreateBlockDevOnSecondary(self, secondary_node, instance,
5696
                                       new_disk, False, info)
5687
            _CreateBlockDev(self, node, instance, new_disk,
5688
                            f_create, info, f_create)
5697 5689
          except error.OpExecError, err:
5698 5690
            self.LogWarning("Failed to create volume %s (%s) on"
5699
                            " secondary node %s: %s",
5700
                            new_disk.iv_name, new_disk, secondary_node, err)
5701
        #HARDCODE
5702
        try:
5703
          _CreateBlockDevOnPrimary(self, instance.primary_node,
5704
                                   instance, new_disk, info)
5705
        except errors.OpExecError, err:
5706
          self.LogWarning("Failed to create volume %s on primary: %s",
5707
                          new_disk.iv_name, err)
5691
                            " node %s: %s",
5692
                            new_disk.iv_name, new_disk, node, err)
5708 5693
        result.append(("disk/%d" % disk_idx_base, "add:size=%s,mode=%s" %
5709 5694
                       (new_disk.size, new_disk.mode)))
5710 5695
      else:

Also available in: Unified diff