Revision 6c00b2c7 lib/utils/storage.py

b/lib/utils/storage.py
95 95
    return (storage_type, None)
96 96

  
97 97

  
98
def _GetDefaultStorageUnitForSpindles(cfg):
99
  """Creates a 'spindle' storage unit, by retrieving the volume group
100
  name and associating it to the lvm-pv storage type.
101

  
102
  @rtype: (string, string)
103
  @return: tuple (storage_type, storage_key), where storage type is
104
    'lvm-pv' and storage_key the name of the default volume group
105

  
106
  """
107
  return (constants.ST_LVM_PV, cfg.GetVGName())
108

  
109

  
110
def GetStorageUnitsOfCluster(cfg, include_spindles=False):
111
  """Examines the cluster's configuration and returns a list of storage
112
  units and their storage keys, ordered by the order in which they
113
  are enabled.
114

  
115
  @type cfg: L{config.ConfigWriter}
116
  @param cfg: Cluster configuration
117
  @type include_spindles: boolean
118
  @param include_spindles: flag to include an extra storage unit for physical
119
    volumes
120
  @rtype: list of tuples (string, string)
121
  @return: list of storage units, each storage unit being a tuple of
122
    (storage_type, storage_key); storage_type is in
123
    C{constants.STORAGE_TYPES} and the storage_key a string to
124
    identify an entity of that storage type, for example a volume group
125
    name for LVM storage or a file for file storage.
126

  
127
  """
128
  cluster_config = cfg.GetClusterInfo()
129
  storage_units = []
130
  for disk_template in cluster_config.enabled_disk_templates:
131
    if constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]\
132
        in constants.STS_REPORT:
133
      storage_units.append(
134
          _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template))
135
  if include_spindles:
136
    included_storage_types = set([st for (st, _) in storage_units])
137
    if not constants.ST_LVM_PV in included_storage_types:
138
      storage_units.append(
139
          _GetDefaultStorageUnitForSpindles(cfg))
140

  
141
  return storage_units
98
def DiskTemplateSupportsSpaceReporting(disk_template):
99
  """Check whether the disk template supports storage space reporting."""
100
  return (constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]
101
          in constants.STS_REPORT)
142 102

  
143 103

  
144 104
def GetStorageUnits(cfg, disk_templates):
......
162 122
  """
163 123
  storage_units = []
164 124
  for disk_template in disk_templates:
165
    if constants.MAP_DISK_TEMPLATE_STORAGE_TYPE[disk_template]\
166
        in constants.STS_REPORT:
125
    if DiskTemplateSupportsSpaceReporting(disk_template):
167 126
      storage_units.append(
168 127
          _GetDefaultStorageUnitForDiskTemplate(cfg, disk_template))
169
  if len(set(disk_templates) & constants.DTS_LVM) > 0:
170
    storage_units.append(
171
        _GetDefaultStorageUnitForSpindles(cfg))
172

  
173 128
  return storage_units
174 129

  
175 130

  

Also available in: Unified diff