Revision 6032697c lib/storage.py

b/lib/storage.py
31 31
from ganeti import utils
32 32

  
33 33

  
34
COL_NAME = "name"
35
COL_SIZE = "size"
36
COL_FREE = "free"
37
COL_USED = "used"
38
COL_ALLOCATABLE = "allocatable"
39

  
40

  
41 34
def _ParseSize(value):
42 35
  return int(round(float(value), 0))
43 36

  
......
102 95
    values = []
103 96

  
104 97
    # Pre-calculate information in case it's requested more than once
105
    if COL_USED in fields:
98
    if constants.SF_USED in fields:
106 99
      dirsize = utils.CalculateDirectorySize(path)
107 100
    else:
108 101
      dirsize = None
109 102

  
110
    if COL_FREE in fields:
103
    if constants.SF_FREE in fields:
111 104
      fsfree = utils.GetFreeFilesystemSpace(path)
112 105
    else:
113 106
      fsfree = None
114 107

  
108
    # Make sure to update constants.VALID_STORAGE_FIELDS when changing fields.
115 109
    for field_name in fields:
116
      if field_name == COL_NAME:
110
      if field_name == constants.SF_NAME:
117 111
        values.append(path)
118 112

  
119
      elif field_name == COL_USED:
113
      elif field_name == constants.SF_USED:
120 114
        values.append(dirsize)
121 115

  
122
      elif field_name == COL_FREE:
116
      elif field_name == constants.SF_FREE:
123 117
        values.append(fsfree)
124 118

  
125 119
      else:
......
293 287
      return False
294 288

  
295 289
  LIST_COMMAND = "pvs"
290

  
291
  # Make sure to update constants.VALID_STORAGE_FIELDS when changing field
292
  # definitions.
296 293
  LIST_FIELDS = [
297
    (COL_NAME, "pv_name", None),
298
    (COL_SIZE, "pv_size", _ParseSize),
299
    (COL_USED, "pv_used", _ParseSize),
300
    (COL_FREE, "pv_free", _ParseSize),
301
    (COL_ALLOCATABLE, "pv_attr", _GetAllocatable),
294
    (constants.SF_NAME, "pv_name", None),
295
    (constants.SF_SIZE, "pv_size", _ParseSize),
296
    (constants.SF_USED, "pv_used", _ParseSize),
297
    (constants.SF_FREE, "pv_free", _ParseSize),
298
    (constants.SF_ALLOCATABLE, "pv_attr", _GetAllocatable),
302 299
    ]
303 300

  
304 301

  
......
307 304

  
308 305
  """
309 306
  LIST_COMMAND = "vgs"
307

  
308
  # Make sure to update constants.VALID_STORAGE_FIELDS when changing field
309
  # definitions.
310 310
  LIST_FIELDS = [
311
    (COL_NAME, "vg_name", None),
312
    (COL_SIZE, "vg_size", _ParseSize),
311
    (constants.SF_NAME, "vg_name", None),
312
    (constants.SF_SIZE, "vg_size", _ParseSize),
313 313
    ]
314 314

  
315 315

  

Also available in: Unified diff