Revision cd46491f lib/objects.py

b/lib/objects.py
922 922
                             self.params)
923 923
    # add here config upgrade for this disk
924 924

  
925
  @staticmethod
926
  def ComputeLDParams(disk_template, disk_params):
927
    """Computes Logical Disk parameters from Disk Template parameters.
928

  
929
    @type disk_template: string
930
    @param disk_template: disk template, one of L{constants.DISK_TEMPLATES}
931
    @type disk_params: dict
932
    @param disk_params: disk template parameters;
933
                        dict(template_name -> parameters
934
    @rtype: list(dict)
935
    @return: a list of dicts, one for each node of the disk hierarchy. Each dict
936
      contains the LD parameters of the node. The tree is flattened in-order.
937

  
938
    """
939
    if disk_template not in constants.DISK_TEMPLATES:
940
      raise errors.ProgrammerError("Unknown disk template %s" % disk_template)
941

  
942
    assert disk_template in disk_params
943

  
944
    result = list()
945
    dt_params = disk_params[disk_template]
946
    if disk_template == constants.DT_DRBD8:
947
      drbd_params = {
948
        constants.LDP_RESYNC_RATE: dt_params[constants.DRBD_RESYNC_RATE],
949
        constants.LDP_BARRIERS: dt_params[constants.DRBD_DISK_BARRIERS],
950
        constants.LDP_NO_META_FLUSH: dt_params[constants.DRBD_META_BARRIERS],
951
        constants.LDP_DEFAULT_METAVG: dt_params[constants.DRBD_DEFAULT_METAVG],
952
        constants.LDP_DISK_CUSTOM: dt_params[constants.DRBD_DISK_CUSTOM],
953
        constants.LDP_NET_CUSTOM: dt_params[constants.DRBD_NET_CUSTOM],
954
        constants.LDP_DYNAMIC_RESYNC: dt_params[constants.DRBD_DYNAMIC_RESYNC],
955
        constants.LDP_PLAN_AHEAD: dt_params[constants.DRBD_PLAN_AHEAD],
956
        constants.LDP_FILL_TARGET: dt_params[constants.DRBD_FILL_TARGET],
957
        constants.LDP_DELAY_TARGET: dt_params[constants.DRBD_DELAY_TARGET],
958
        constants.LDP_MAX_RATE: dt_params[constants.DRBD_MAX_RATE],
959
        constants.LDP_MIN_RATE: dt_params[constants.DRBD_MIN_RATE],
960
        }
961

  
962
      drbd_params = \
963
        FillDict(constants.DISK_LD_DEFAULTS[constants.LD_DRBD8],
964
                 drbd_params)
965

  
966
      result.append(drbd_params)
967

  
968
      # data LV
969
      data_params = {
970
        constants.LDP_STRIPES: dt_params[constants.DRBD_DATA_STRIPES],
971
        }
972
      data_params = \
973
        FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV],
974
                 data_params)
975
      result.append(data_params)
976

  
977
      # metadata LV
978
      meta_params = {
979
        constants.LDP_STRIPES: dt_params[constants.DRBD_META_STRIPES],
980
        }
981
      meta_params = \
982
        FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV],
983
                 meta_params)
984
      result.append(meta_params)
985

  
986
    elif (disk_template == constants.DT_FILE or
987
          disk_template == constants.DT_SHARED_FILE):
988
      result.append(constants.DISK_LD_DEFAULTS[constants.LD_FILE])
989

  
990
    elif disk_template == constants.DT_PLAIN:
991
      params = {
992
        constants.LDP_STRIPES: dt_params[constants.LV_STRIPES],
993
        }
994
      params = \
995
        FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV],
996
                 params)
997
      result.append(params)
998

  
999
    elif disk_template == constants.DT_BLOCK:
1000
      result.append(constants.DISK_LD_DEFAULTS[constants.LD_BLOCKDEV])
1001

  
1002
    elif disk_template == constants.DT_RBD:
1003
      params = {
1004
        constants.LDP_POOL: dt_params[constants.RBD_POOL]
1005
        }
1006
      params = \
1007
        FillDict(constants.DISK_LD_DEFAULTS[constants.LD_RBD],
1008
                 params)
1009
      result.append(params)
1010

  
1011
    return result
1012

  
925 1013

  
926 1014
class InstancePolicy(ConfigObject):
927 1015
  """Config object representing instance policy limits dictionary.

Also available in: Unified diff