Revision 703fa9ab lib/objects.py

b/lib/objects.py
55 55
_TIMESTAMPS = ["ctime", "mtime"]
56 56
_UUID = ["uuid"]
57 57

  
58
# constants used to create InstancePolicy dictionary
59
TISPECS_GROUP_TYPES = {
60
  constants.ISPECS_MIN: constants.VTYPE_INT,
61
  constants.ISPECS_MAX: constants.VTYPE_INT,
62
  }
63

  
64
TISPECS_CLUSTER_TYPES = {
65
  constants.ISPECS_MIN: constants.VTYPE_INT,
66
  constants.ISPECS_MAX: constants.VTYPE_INT,
67
  constants.ISPECS_STD: constants.VTYPE_INT,
68
  }
69

  
70 58

  
71 59
def FillDict(defaults_dict, custom_dict, skip_keys=None):
72 60
  """Basic function to apply settings on top a default dict.
......
199 187
    ])
200 188

  
201 189

  
202
def CreateIPolicyFromOpts(ispecs_mem_size=None,
203
                          ispecs_cpu_count=None,
204
                          ispecs_disk_count=None,
205
                          ispecs_disk_size=None,
206
                          ispecs_nic_count=None,
207
                          ipolicy_disk_templates=None,
208
                          ipolicy_vcpu_ratio=None,
209
                          group_ipolicy=False,
210
                          allowed_values=None,
211
                          fill_all=False):
212
  """Creation of instance policy based on command line options.
213

  
214
  @param fill_all: whether for cluster policies we should ensure that
215
    all values are filled
216

  
217

  
218
  """
219
  # prepare ipolicy dict
220
  ipolicy_transposed = {
221
    constants.ISPEC_MEM_SIZE: ispecs_mem_size,
222
    constants.ISPEC_CPU_COUNT: ispecs_cpu_count,
223
    constants.ISPEC_DISK_COUNT: ispecs_disk_count,
224
    constants.ISPEC_DISK_SIZE: ispecs_disk_size,
225
    constants.ISPEC_NIC_COUNT: ispecs_nic_count,
226
    }
227

  
228
  # first, check that the values given are correct
229
  if group_ipolicy:
230
    forced_type = TISPECS_GROUP_TYPES
231
  else:
232
    forced_type = TISPECS_CLUSTER_TYPES
233

  
234
  for specs in ipolicy_transposed.values():
235
    utils.ForceDictType(specs, forced_type, allowed_values=allowed_values)
236

  
237
  # then transpose
238
  ipolicy_out = MakeEmptyIPolicy()
239
  for name, specs in ipolicy_transposed.iteritems():
240
    assert name in constants.ISPECS_PARAMETERS
241
    for key, val in specs.items(): # {min: .. ,max: .., std: ..}
242
      ipolicy_out[key][name] = val
243

  
244
  # no filldict for non-dicts
245
  if not group_ipolicy and fill_all:
246
    if ipolicy_disk_templates is None:
247
      ipolicy_disk_templates = constants.DISK_TEMPLATES
248
    if ipolicy_vcpu_ratio is None:
249
      ipolicy_vcpu_ratio = \
250
        constants.IPOLICY_DEFAULTS[constants.IPOLICY_VCPU_RATIO]
251
  if ipolicy_disk_templates is not None:
252
    ipolicy_out[constants.IPOLICY_DTS] = list(ipolicy_disk_templates)
253
  if ipolicy_vcpu_ratio is not None:
254
    ipolicy_out[constants.IPOLICY_VCPU_RATIO] = ipolicy_vcpu_ratio
255

  
256
  assert not (frozenset(ipolicy_out.keys()) - constants.IPOLICY_ALL_KEYS)
257

  
258
  return ipolicy_out
259

  
260

  
261 190
class ConfigObject(object):
262 191
  """A generic config object.
263 192

  

Also available in: Unified diff