Revision d90f0cb4 lib/cmdlib/instance_storage.py

b/lib/cmdlib/instance_storage.py
872 872
                         cleanup=new_disks)
873 873

  
874 874

  
875
def _PerformNodeInfoCall(lu, node_uuids, vg):
876
  """Prepares the input and performs a node info call.
877

  
878
  @type lu: C{LogicalUnit}
879
  @param lu: a logical unit from which we get configuration data
880
  @type node_uuids: list of string
881
  @param node_uuids: list of node UUIDs to perform the call for
882
  @type vg: string
883
  @param vg: the volume group's name
884

  
885
  """
886
  lvm_storage_units = [(constants.ST_LVM_VG, vg)]
887
  storage_units = rpc.PrepareStorageUnitsForNodes(lu.cfg, lvm_storage_units,
888
                                                  node_uuids)
889
  hvname = lu.cfg.GetHypervisorType()
890
  hvparams = lu.cfg.GetClusterInfo().hvparams
891
  nodeinfo = lu.rpc.call_node_info(node_uuids, storage_units,
892
                                   [(hvname, hvparams[hvname])])
893
  return nodeinfo
894

  
895

  
896
def _CheckVgCapacityForNode(node_name, node_info, vg, requested):
897
  """Checks the vg capacity for a given node.
898

  
899
  @type node_info: tuple (_, list of dicts, _)
900
  @param node_info: the result of the node info call for one node
901
  @type node_name: string
902
  @param node_name: the name of the node
903
  @type vg: string
904
  @param vg: volume group name
905
  @type requested: int
906
  @param requested: the amount of disk in MiB to check for
907
  @raise errors.OpPrereqError: if the node doesn't have enough disk,
908
      or we cannot check the node
909

  
910
  """
911
  (_, space_info, _) = node_info
912
  lvm_vg_info = utils.storage.LookupSpaceInfoByStorageType(
913
      space_info, constants.ST_LVM_VG)
914
  if not lvm_vg_info:
915
    raise errors.OpPrereqError("Can't retrieve storage information for LVM")
916
  vg_free = lvm_vg_info.get("storage_free", None)
917
  if not isinstance(vg_free, int):
918
    raise errors.OpPrereqError("Can't compute free disk space on node"
919
                               " %s for vg %s, result was '%s'" %
920
                               (node_name, vg, vg_free), errors.ECODE_ENVIRON)
921
  if requested > vg_free:
922
    raise errors.OpPrereqError("Not enough disk space on target node %s"
923
                               " vg %s: required %d MiB, available %d MiB" %
924
                               (node_name, vg, requested, vg_free),
925
                               errors.ECODE_NORES)
926

  
927

  
875 928
def _CheckNodesFreeDiskOnVG(lu, node_uuids, vg, requested):
876 929
  """Checks if nodes have enough free disk space in the specified VG.
877 930

  
......
892 945
      or we cannot check the node
893 946

  
894 947
  """
895
  lvm_storage_units = [(constants.ST_LVM_VG, vg)]
896
  storage_units = rpc.PrepareStorageUnitsForNodes(lu.cfg, lvm_storage_units,
897
                                                  node_uuids)
898
  hvname = lu.cfg.GetHypervisorType()
899
  hvparams = lu.cfg.GetClusterInfo().hvparams
900
  nodeinfo = lu.rpc.call_node_info(node_uuids, storage_units,
901
                                   [(hvname, hvparams[hvname])])
948
  nodeinfo = _PerformNodeInfoCall(lu, node_uuids, vg)
902 949
  for node in node_uuids:
903 950
    node_name = lu.cfg.GetNodeName(node)
904

  
905 951
    info = nodeinfo[node]
906 952
    info.Raise("Cannot get current information from node %s" % node_name,
907 953
               prereq=True, ecode=errors.ECODE_ENVIRON)
908
    (_, space_info, _) = info.payload
909
    lvm_vg_info = utils.storage.LookupSpaceInfoByStorageType(
910
        space_info, constants.ST_LVM_VG)
911
    if not lvm_vg_info:
912
      raise errors.OpPrereqError("Can't retrieve storage information for LVM")
913
    vg_free = lvm_vg_info.get("storage_free", None)
914
    if not isinstance(vg_free, int):
915
      raise errors.OpPrereqError("Can't compute free disk space on node"
916
                                 " %s for vg %s, result was '%s'" %
917
                                 (node_name, vg, vg_free), errors.ECODE_ENVIRON)
918
    if requested > vg_free:
919
      raise errors.OpPrereqError("Not enough disk space on target node %s"
920
                                 " vg %s: required %d MiB, available %d MiB" %
921
                                 (node_name, vg, requested, vg_free),
922
                                 errors.ECODE_NORES)
954
    _CheckVgCapacityForNode(node_name, info.payload, vg, requested)
923 955

  
924 956

  
925 957
def CheckNodesFreeDiskPerVG(lu, node_uuids, req_sizes):

Also available in: Unified diff