Revision da803ff1 lib/rpc.py

b/lib/rpc.py
718 718
  return [annotation_fn(disk.Copy(), ld_params) for disk in disks]
719 719

  
720 720

  
721
def _GetESFlag(cfg, node_uuid):
721
def _GetExclusiveStorageFlag(cfg, node_uuid):
722 722
  ni = cfg.GetNodeInfo(node_uuid)
723 723
  if ni is None:
724 724
    raise errors.OpPrereqError("Invalid node name %s" % node_uuid,
......
726 726
  return cfg.GetNdParams(ni)[constants.ND_EXCLUSIVE_STORAGE]
727 727

  
728 728

  
729
def _AddExclusiveStorageFlagToLvmStorageUnits(storage_units, es_flag):
730
  """Adds the exclusive storage flag to lvm units.
731

  
732
  This function creates a copy of the storage_units lists, with the
733
  es_flag being added to all lvm storage units.
734

  
735
  @type storage_units: list of pairs (string, string)
736
  @param storage_units: list of 'raw' storage units, consisting only of
737
    (storage_type, storage_key)
738
  @type es_flag: boolean
739
  @param es_flag: exclusive storage flag
740
  @rtype: list of tuples (string, string, list)
741
  @return: list of storage units (storage_type, storage_key, params) with
742
    the params containing the es_flag for lvm-vg storage units
743

  
744
  """
745
  result = []
746
  for (storage_type, storage_key) in storage_units:
747
    if storage_type == constants.ST_LVM_VG:
748
      result.append((storage_type, storage_key, es_flag))
749
    else:
750
      result.append((storage_type, storage_key, []))
751
  return result
752

  
753

  
729 754
def GetExclusiveStorageForNodes(cfg, node_uuids):
730 755
  """Return the exclusive storage flag for all the given nodes.
731 756

  
......
734 759
  @type node_uuids: list or tuple
735 760
  @param node_uuids: node UUIDs for which to read the flag
736 761
  @rtype: dict
737
  @return: mapping from node names to exclusive storage flags
762
  @return: mapping from node uuids to exclusive storage flags
738 763
  @raise errors.OpPrereqError: if any given node name has no corresponding
739 764
  node
740 765

  
741 766
  """
742
  getflag = lambda n: _GetESFlag(cfg, n)
767
  getflag = lambda n: _GetExclusiveStorageFlag(cfg, n)
743 768
  flags = map(getflag, node_uuids)
744 769
  return dict(zip(node_uuids, flags))
745 770

  
746 771

  
772
def PrepareStorageUnitsForNodes(cfg, storage_units, node_uuids):
773
  """Return the lvm storage unit for all the given nodes.
774

  
775
  Main purpose of this function is to map the exclusive storage flag, which
776
  can be different for each node, to the default LVM storage unit.
777

  
778
  @type cfg: L{config.ConfigWriter}
779
  @param cfg: cluster configuration
780
  @type storage_units: list of pairs (string, string)
781
  @param storage_units: list of 'raw' storage units, e.g. pairs of
782
    (storage_type, storage_key)
783
  @type node_uuids: list or tuple
784
  @param node_uuids: node UUIDs for which to read the flag
785
  @rtype: dict
786
  @return: mapping from node uuids to a list of storage units which include
787
    the exclusive storage flag for lvm storage
788
  @raise errors.OpPrereqError: if any given node name has no corresponding
789
  node
790

  
791
  """
792
  getunit = lambda n: _AddExclusiveStorageFlagToLvmStorageUnits(
793
      storage_units, _GetExclusiveStorageFlag(cfg, n))
794
  flags = map(getunit, node_uuids)
795
  return dict(zip(node_uuids, flags))
796

  
797

  
747 798
#: Generic encoders
748 799
_ENCODERS = {
749 800
  rpc_defs.ED_OBJECT_DICT: _ObjectToDict,

Also available in: Unified diff