Revision 2cc673a3 lib/objects.py
b/lib/objects.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
59 | 59 |
TISPECS_GROUP_TYPES = { |
60 | 60 |
constants.ISPECS_MIN: constants.VTYPE_INT, |
61 | 61 |
constants.ISPECS_MAX: constants.VTYPE_INT, |
62 |
} |
|
62 |
}
|
|
63 | 63 |
|
64 | 64 |
TISPECS_CLUSTER_TYPES = { |
65 | 65 |
constants.ISPECS_MIN: constants.VTYPE_INT, |
... | ... | |
92 | 92 |
return ret_dict |
93 | 93 |
|
94 | 94 |
|
95 |
def FillDictOfDicts(defaults_dict, custom_dict, skip_keys=None):
|
|
96 |
"""Run FillDict for each key in dictionary.
|
|
95 |
def FillIPolicy(default_ipolicy, custom_ipolicy, skip_keys=None):
|
|
96 |
"""Fills an instance policy with defaults.
|
|
97 | 97 |
|
98 | 98 |
""" |
99 |
assert frozenset(default_ipolicy.keys()) == constants.IPOLICY_ALL_KEYS |
|
99 | 100 |
ret_dict = {} |
100 |
for key in defaults_dict:
|
|
101 |
ret_dict[key] = FillDict(defaults_dict[key],
|
|
102 |
custom_dict.get(key, {}),
|
|
101 |
for key in constants.IPOLICY_PARAMETERS:
|
|
102 |
ret_dict[key] = FillDict(default_ipolicy[key],
|
|
103 |
custom_ipolicy.get(key, {}),
|
|
103 | 104 |
skip_keys=skip_keys) |
105 |
# list items |
|
106 |
for key in [constants.ISPECS_DTS]: |
|
107 |
ret_dict[key] = list(custom_ipolicy.get(key, default_ipolicy[key])) |
|
108 |
|
|
104 | 109 |
return ret_dict |
105 | 110 |
|
106 | 111 |
|
... | ... | |
166 | 171 |
|
167 | 172 |
""" |
168 | 173 |
return dict([ |
169 |
(constants.ISPECS_MIN, dict()),
|
|
170 |
(constants.ISPECS_MAX, dict()),
|
|
171 |
(constants.ISPECS_STD, dict()),
|
|
174 |
(constants.ISPECS_MIN, {}),
|
|
175 |
(constants.ISPECS_MAX, {}),
|
|
176 |
(constants.ISPECS_STD, {}),
|
|
172 | 177 |
]) |
173 | 178 |
|
174 | 179 |
|
... | ... | |
177 | 182 |
ispecs_disk_count=None, |
178 | 183 |
ispecs_disk_size=None, |
179 | 184 |
ispecs_nic_count=None, |
185 |
ispecs_disk_templates=None, |
|
180 | 186 |
group_ipolicy=False, |
181 |
allowed_values=None): |
|
182 |
"""Creation of instane policy based on command line options. |
|
187 |
allowed_values=None, |
|
188 |
fill_all=False): |
|
189 |
"""Creation of instance policy based on command line options. |
|
190 |
|
|
191 |
@param fill_all: whether for cluster policies we should ensure that |
|
192 |
all values are filled |
|
183 | 193 |
|
184 | 194 |
|
185 | 195 |
""" |
... | ... | |
208 | 218 |
for key, val in specs.items(): # {min: .. ,max: .., std: ..} |
209 | 219 |
ipolicy_out[key][name] = val |
210 | 220 |
|
221 |
# no filldict for lists |
|
222 |
if not group_ipolicy and fill_all and ispecs_disk_templates is None: |
|
223 |
ispecs_disk_templates = constants.DISK_TEMPLATES |
|
224 |
if ispecs_disk_templates is not None: |
|
225 |
ipolicy_out[constants.ISPECS_DTS] = list(ispecs_disk_templates) |
|
226 |
|
|
211 | 227 |
return ipolicy_out |
212 | 228 |
|
213 | 229 |
|
... | ... | |
857 | 873 |
|
858 | 874 |
class InstancePolicy(ConfigObject): |
859 | 875 |
"""Config object representing instance policy limits dictionary.""" |
860 |
__slots__ = ["min", "max", "std"] |
|
876 |
__slots__ = ["min", "max", "std", "disk_templates"]
|
|
861 | 877 |
|
862 | 878 |
@classmethod |
863 | 879 |
def CheckParameterSyntax(cls, ipolicy): |
... | ... | |
866 | 882 |
""" |
867 | 883 |
for param in constants.ISPECS_PARAMETERS: |
868 | 884 |
InstancePolicy.CheckISpecSyntax(ipolicy, param) |
885 |
if constants.ISPECS_DTS in ipolicy: |
|
886 |
InstancePolicy.CheckDiskTemplates(ipolicy[constants.ISPECS_DTS]) |
|
869 | 887 |
|
870 | 888 |
@classmethod |
871 | 889 |
def CheckISpecSyntax(cls, ipolicy, name): |
... | ... | |
892 | 910 |
if min_v > std_v or std_v > max_v: |
893 | 911 |
raise errors.ConfigurationError(err) |
894 | 912 |
|
913 |
@classmethod |
|
914 |
def CheckDiskTemplates(cls, disk_templates): |
|
915 |
"""Checks the disk templates for validity. |
|
916 |
|
|
917 |
""" |
|
918 |
wrong = frozenset(disk_templates).difference(constants.DISK_TEMPLATES) |
|
919 |
if wrong: |
|
920 |
raise errors.ConfigurationError("Invalid disk template(s) %s" % |
|
921 |
utils.CommaJoin(wrong)) |
|
922 |
|
|
895 | 923 |
|
896 | 924 |
class Instance(TaggableObject): |
897 | 925 |
"""Config object representing an instance.""" |
... | ... | |
1473 | 1501 |
|
1474 | 1502 |
# instance policy added before 2.6 |
1475 | 1503 |
if self.ipolicy is None: |
1476 |
self.ipolicy = FillDictOfDicts(constants.IPOLICY_DEFAULTS, {})
|
|
1504 |
self.ipolicy = FillIPolicy(constants.IPOLICY_DEFAULTS, {})
|
|
1477 | 1505 |
|
1478 | 1506 |
@property |
1479 | 1507 |
def primary_hypervisor(self): |
... | ... | |
1668 | 1696 |
the cluster defaults |
1669 | 1697 |
|
1670 | 1698 |
""" |
1671 |
return FillDictOfDicts(self.ipolicy, ipolicy)
|
|
1699 |
return FillIPolicy(self.ipolicy, ipolicy)
|
|
1672 | 1700 |
|
1673 | 1701 |
|
1674 | 1702 |
class BlockDevStatus(ConfigObject): |
Also available in: Unified diff